From a4baf28d203959457d82762e27ffbb7104dc0a07 Mon Sep 17 00:00:00 2001 From: michelou Date: Tue, 10 Jun 2008 08:46:06 +0000 Subject: int -> Int, etc.. --- test/files/run/Course-2002-07.scala | 165 ++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 83 deletions(-) (limited to 'test/files/run/Course-2002-07.scala') diff --git a/test/files/run/Course-2002-07.scala b/test/files/run/Course-2002-07.scala index b084a35e73..d33e269805 100644 --- a/test/files/run/Course-2002-07.scala +++ b/test/files/run/Course-2002-07.scala @@ -6,45 +6,45 @@ object M0 { trait Expr { - def isNumber: boolean; - def isSum: boolean; - def numValue: int; + def isNumber: Boolean; + def isSum: Boolean; + def numValue: Int; def leftOp: Expr; def rightOp: Expr; } - class Number(n: int) extends Expr { - def isNumber: boolean = true; - def isSum: boolean = false; - def numValue: int = n; + class Number(n: Int) extends Expr { + def isNumber: Boolean = true; + def isSum: Boolean = false; + def numValue: Int = n; def leftOp: Expr = error("Number.leftOp"); def rightOp: Expr = error("Number.rightOp"); } class Sum(e1: Expr, e2: Expr) extends Expr { - def isNumber: boolean = false; - def isSum: boolean = true; - def numValue: int = error("Sum.numValue"); + def isNumber: Boolean = false; + def isSum: Boolean = true; + def numValue: Int = error("Sum.numValue"); def leftOp: Expr = e1; def rightOp: Expr = e2; } class Prod(e1: Expr, e2: Expr) extends Expr { - def isNumber: boolean = false; - def isSum: boolean = false; - def numValue: int = error("Prod.numValue"); + def isNumber: Boolean = false; + def isSum: Boolean = false; + def numValue: Int = error("Prod.numValue"); def leftOp: Expr = e1; def rightOp: Expr = e2; } class Var(x: String) extends Expr { - def isNumber: boolean = false; - def isSum: boolean = false; - def numValue: int = error("Var.numValue"); + def isNumber: Boolean = false; + def isSum: Boolean = false; + def numValue: Int = error("Var.numValue"); def leftOp: Expr = error("Var.leftOp"); def rightOp: Expr = error("Var.rightOp"); } - def eval(e: Expr): int = { + def eval(e: Expr): Int = { if (e.isNumber) e.numValue else if (e.isSum) eval(e.leftOp) + eval(e.rightOp) else error("unknown expression") @@ -69,13 +69,13 @@ object M0 { object M1 { trait Expr { - def eval: int; + def eval: Int; } - class Number(n: int) extends Expr { - def eval: int = n; + class Number(n: Int) extends Expr { + def eval: Int = n; } class Sum(e1: Expr, e2: Expr) extends Expr { - def eval: int = e1.eval + e2.eval; + def eval: Int = e1.eval + e2.eval; } def test = { @@ -96,10 +96,10 @@ object M1 { object M2 { trait Expr; - case class Number(n: int) extends Expr; + case class Number(n: Int) extends Expr; case class Sum(e1: Expr, e2: Expr) extends Expr; - def eval(e: Expr): int = e match { + def eval(e: Expr): Int = e match { case Number(n) => n case Sum(e1, e2) => eval(e1) + eval(e2) } @@ -120,12 +120,12 @@ object M2 { object M3 { trait Expr { - def eval: int = this match { + def eval: Int = this match { case Number(n) => n case Sum(e1, e2) => e1.eval + e2.eval } } - case class Number(n: int) extends Expr; + case class Number(n: Int) extends Expr; case class Sum(e1: Expr, e2: Expr) extends Expr; def test = { @@ -160,18 +160,18 @@ object M4 { test_concat(List(List(),List(),List())); test_concat(List(List(1,2,3,4,5,6))); - test_concat(List(List(1,2,3,4,5,6),List[int]())); // !!! [int] + test_concat(List(List(1,2,3,4,5,6),List[Int]())); // !!! [int] test_concat(List(List(1,2,3),List(4,5,6))); - test_concat(List(List[int](),List(1,2,3,4,5,6))); // !!! [int] - test_concat(List(List(1,2,3,4,5,6),List[int](),List[int]())); // !!! [int] - test_concat(List(List(1,2,3,4,5),List(6),List[int]())); // !!! [int] - test_concat(List(List(1,2,3),List(4,5,6),List[int]())); // !!! [int] - test_concat(List(List(1),List(2,3,4,5,6),List[int]())); // !!! [int] - test_concat(List(List[int](),List(1,2,3,4,5,6),List[int]())); // !!! [int] - test_concat(List(List[int](),List(1,2,3,4,5),List(6))); // !!! [int] - test_concat(List(List[int](),List(1,2,3),List(4,5,6))); // !!! [int] - test_concat(List(List[int](),List(1),List(2,3,4,5,6))); // !!! [int] - test_concat(List(List[int](),List[int](),List(1,2,3,4,5,6))); // !!! [int] + test_concat(List(List[Int](),List(1,2,3,4,5,6))); // !!! [int] + test_concat(List(List(1,2,3,4,5,6),List[Int](),List[Int]())); // !!! [int] + test_concat(List(List(1,2,3,4,5),List(6),List[Int]())); // !!! [int] + test_concat(List(List(1,2,3),List(4,5,6),List[Int]())); // !!! [int] + test_concat(List(List(1),List(2,3,4,5,6),List[Int]())); // !!! [int] + test_concat(List(List[Int](),List(1,2,3,4,5,6),List[Int]())); // !!! [int] + test_concat(List(List[Int](),List(1,2,3,4,5),List(6))); // !!! [int] + test_concat(List(List[Int](),List(1,2,3),List(4,5,6))); // !!! [int] + test_concat(List(List[Int](),List(1),List(2,3,4,5,6))); // !!! [int] + test_concat(List(List[Int](),List[Int](),List(1,2,3,4,5,6))); // !!! [int] test_concat(List(List(1,2),List(3,4),List(5,6))); Console.println; } @@ -259,7 +259,6 @@ object M7 { Console.println(heads(xss).toString + " = heads(" + xss + ")"); // !!! .toString } - def test = { test_heads(List()); test_heads(List(List())); @@ -267,21 +266,21 @@ object M7 { test_heads(List(List(),List(),List())); test_heads(List(List(1,2,3,4,5,6))); - test_heads(List(List(1,2,3,4,5,6),List[int]())); // !!! [int] - test_heads(List(List[int](),List(1,2,3,4,5,6))); // !!! [int] - test_heads(List(List(1,2,3,4,5,6),List[int](),List[int]())); // !!! [int] - test_heads(List(List[int](),List(1,2,3,4,5,6),List[int]())); // !!! [int] - test_heads(List(List[int](),List[int](),List(1,2,3,4,5,6))); // !!! [int] + test_heads(List(List(1,2,3,4,5,6),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List(1,2,3,4,5,6))); // !!! [int] + test_heads(List(List(1,2,3,4,5,6),List[Int](),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List(1,2,3,4,5,6),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List[Int](),List(1,2,3,4,5,6))); // !!! [int] - test_heads(List(List(1),List(2,3,4,5,6),List[int]())); // !!! [int] - test_heads(List(List[int](),List(1),List(2,3,4,5,6))); // !!! [int] + test_heads(List(List(1),List(2,3,4,5,6),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List(1),List(2,3,4,5,6))); // !!! [int] test_heads(List(List(1,2,3),List(4,5,6))); - test_heads(List(List(1,2,3),List(4,5,6),List[int]())); // !!! [int] - test_heads(List(List[int](),List(1,2,3),List(4,5,6))); // !!! [int] + test_heads(List(List(1,2,3),List(4,5,6),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List(1,2,3),List(4,5,6))); // !!! [int] - test_heads(List(List(1,2,3,4,5),List(6),List[int]())); // !!! [int] - test_heads(List(List[int](),List(1,2,3,4,5),List(6))); // !!! [int] + test_heads(List(List(1,2,3,4,5),List(6),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List(1,2,3,4,5),List(6))); // !!! [int] test_heads(List(List(1,2),List(3,4),List(5,6))); @@ -313,21 +312,21 @@ object M8 { test_heads(List(List(),List(),List())); test_heads(List(List(1,2,3,4,5,6))); - test_heads(List(List(1,2,3,4,5,6),List[int]())); // !!! [int] - test_heads(List(List[int](),List(1,2,3,4,5,6))); // !!! [int] - test_heads(List(List(1,2,3,4,5,6),List[int](),List[int]())); // !!! [int] - test_heads(List(List[int](),List(1,2,3,4,5,6),List[int]())); // !!! [int] - test_heads(List(List[int](),List[int](),List(1,2,3,4,5,6))); // !!! [int] + test_heads(List(List(1,2,3,4,5,6),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List(1,2,3,4,5,6))); // !!! [int] + test_heads(List(List(1,2,3,4,5,6),List[Int](),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List(1,2,3,4,5,6),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List[Int](),List(1,2,3,4,5,6))); // !!! [int] - test_heads(List(List(1),List(2,3,4,5,6),List[int]())); // !!! [int] - test_heads(List(List[int](),List(1),List(2,3,4,5,6))); // !!! [int] + test_heads(List(List(1),List(2,3,4,5,6),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List(1),List(2,3,4,5,6))); // !!! [int] test_heads(List(List(1,2,3),List(4,5,6))); - test_heads(List(List(1,2,3),List(4,5,6),List[int]())); // !!! [int] - test_heads(List(List[int](),List(1,2,3),List(4,5,6))); // !!! + test_heads(List(List(1,2,3),List(4,5,6),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List(1,2,3),List(4,5,6))); // !!! - test_heads(List(List(1,2,3,4,5),List(6),List[int]())); // !!! [int] - test_heads(List(List[int](),List(1,2,3,4,5),List(6))); // !!! [int] + test_heads(List(List(1,2,3,4,5),List(6),List[Int]())); // !!! [int] + test_heads(List(List[Int](),List(1,2,3,4,5),List(6))); // !!! [int] test_heads(List(List(1,2),List(3,4),List(5,6))); @@ -348,7 +347,7 @@ object M9 { case Prod(e1, e2) => Sum(Prod(e1, e2 derive v), Prod(e2, e1 derive v)) } } - case class Number(x: int) extends Expr { + case class Number(x: Int) extends Expr { override def toString = "Number(" + x + ")"; // !!! remove ! } case class Var(name: String) extends Expr { @@ -391,7 +390,7 @@ object MA { case Prod(e1, e2) => e1 * (e2 derive v) + e2 * (e1 derive v) } } - case class Number(x: int) extends Expr { + case class Number(x: Int) extends Expr { override def toString = x.toString } case class Var(name: String) extends Expr { @@ -410,15 +409,15 @@ object MA { } } - def eval(e: Expr): int = e match { + def eval(e: Expr): Int = e match { case Number(n) => n case Var(_) => error("cannot evaluate variable") case Sum(e1, e2) => eval(e1) + eval(e2) case Prod(e1, e2) => eval(e1) * eval(e2) } - def evalvars(xs: List[Pair[String,int]]): Expr => Int = { - def loop(e: Expr): int = e match { + def evalvars(xs: List[(String,Int)]): Expr => Int = { + def loop(e: Expr): Int = e match { case Number(n) => n case Var(name) => lookup(xs,name) case Sum(e1, e2) => loop(e1) + loop(e2) @@ -451,10 +450,10 @@ object MA { object Utils { - private def power0(x: int, y: int): int = + private def power0(x: Int, y: Int): Int = if (y == 1) x else if (y % 2 == 0) power0(x*x,y/2) else x*power0(x, y-1); - def power(x: int, y: int): int = Pair(x,y) match { + def power(x: Int, y: Int): Int = (x,y) match { case Pair(0,0) => error("power(0,0)") case Pair(0,_) => 0 case Pair(1,_) => 1 @@ -464,13 +463,13 @@ object Utils { case Pair(_,_) => if (y < 0) 1/power0(x,y) else power0(x,y) } - def lookup(entries: List[Pair[String,int]], key: String):int = entries match{ + def lookup(entries: List[(String,Int)], key: String): Int = entries match { case List() => error("no value for " + key) case Pair(k,v) :: _ if (k == key) => v case _ :: rest => lookup(rest, key) } - def compare(xs: List[String], ys: List[String]): int = Pair(xs,ys) match{ + def compare(xs: List[String], ys: List[String]): Int = (xs, ys) match { case Pair(List(), List()) => 0 case Pair(List(), _ ) => -1 case Pair(_ , List()) => +1 @@ -489,7 +488,7 @@ object MB { trait Expr { - private def count: int = this match { + private def count: Int = this match { case Lit(n) => n case Mul(Lit(n),_) => n case _ => 1 @@ -508,9 +507,9 @@ object MB { case _ => List() } - private def +< (that: Expr): boolean = (this + 0 case Pair(_ , Add(_,_)) => 0 case Pair(_ , _ ) => compare(this.vars,that.vars) @@ -528,9 +527,9 @@ object MB { } } else that + this; - private def *< (that: Expr): boolean = (this * 0 case Pair(_ , Mul(_,_)) => 0 case Pair(Add(_,_), Add(_,_)) => 0 @@ -558,7 +557,7 @@ object MB { case Pair(_ , _ ) => Mul(this,that) } else that * this; - def ^ (that: int): Expr = Pair(this,that) match { + def ^ (that: Int): Expr = (this,that) match { case Pair(_ ,1) => this case Pair(Lit(i) ,n) => Lit(power(i,n)) case Pair(Var(_) ,n) => Pow(this,n) @@ -575,7 +574,7 @@ object MB { case Pow(e1, i2) => Lit(i2) * (e1 derive v) * (e1 ^ (i2 - 1)) } - def evaluate(vars: List[Pair[String,int]]): int = this match { + def evaluate(vars: List[(String,Int)]): Int = this match { case Lit(cst) => cst case Var (name) => lookup(vars, name) case Add (l, r) => l.evaluate(vars) + r.evaluate(vars) @@ -583,7 +582,7 @@ object MB { case Pow(l, r) => power(l.evaluate(vars), r) } - def equ(that: Expr): boolean = Pair(this,that) match { + def equ(that: Expr): Boolean = Pair(this,that) match { case Pair(Lit(l) ,Lit(r)) => l == r case Pair(Var(l) ,Var(r)) => l == r case Pair(Add(ll,lr),Add(rl,rr)) => (ll equ rl) && (lr equ rr) @@ -594,7 +593,7 @@ object MB { } - case class Lit(x: int) extends Expr { + case class Lit(x: Int) extends Expr { override def toString = x.toString } @@ -616,7 +615,7 @@ object MB { } } - case class Pow(e1: Expr, i2: int) extends Expr { + case class Pow(e1: Expr, i2: Int) extends Expr { override def toString = { def factorToString(e: Expr) = e match { case Add(_, _) => "(" + e.toString + ")" @@ -668,8 +667,8 @@ object MB { Console.println("f0(x) = " + f0); Console.println; - def check(n: String, f: Expr, x: int, e: int) = { - val a: int = f.evaluate(List(Pair("x",x))); + def check(n: String, f: Expr, x: Int, e: Int) { + val a: Int = f.evaluate(List(Pair("x",x))); val s: String = if (a == e) "ok" else "KO(" + e + ")"; Console.println(n + "(" + x + ") = " + a + " " + s); } @@ -704,7 +703,7 @@ object MB { //############################################################################ object Test { - def main(args: Array[String]): unit = { + def main(args: Array[String]) { M0.test; M1.test; M2.test; -- cgit v1.2.3