From b47ed354cf13fa9b1607d6c638224782d111fc5c Mon Sep 17 00:00:00 2001 From: michelou Date: Fri, 17 Aug 2007 14:22:22 +0000 Subject: updated several tests for MSIL --- test/files/run/Course-2002-03.scala | 5 +- test/files/run/Course-2002-06.scala | 4 +- test/files/run/Course-2002-09.scala | 3 +- test/files/run/Course-2002-10.scala | 2 +- test/files/run/arrays.scala | 94 ++++++++++----------- test/files/run/tailcalls.scala | 159 ++++++++++++++++++------------------ 6 files changed, 133 insertions(+), 134 deletions(-) (limited to 'test/files/run') diff --git a/test/files/run/Course-2002-03.scala b/test/files/run/Course-2002-03.scala index efb3c81446..7fb0d2636c 100644 --- a/test/files/run/Course-2002-03.scala +++ b/test/files/run/Course-2002-03.scala @@ -3,7 +3,6 @@ //############################################################################ // $Id$ -import scala.compat.StringBuilder; object M0 { class Rational(x: Int, y: Int) { @@ -274,7 +273,7 @@ object M8 { new NonEmpty(f(elem), lset, rset) } - def foreach(f: Int => Unit): Unit = { + def foreach(f: Int => Unit) { left.foreach(f); f(elem); right.foreach(f); @@ -376,7 +375,7 @@ object M9 { //############################################################################ object Test { - def main(args: Array[String]): Unit = { + def main(args: Array[String]) { M0; M1; M2; diff --git a/test/files/run/Course-2002-06.scala b/test/files/run/Course-2002-06.scala index 47851988c0..e2cfb6daf4 100644 --- a/test/files/run/Course-2002-06.scala +++ b/test/files/run/Course-2002-06.scala @@ -11,7 +11,7 @@ class Vector (_x: Double, _y: Double) { def *(scalar: Double): Vector = new Vector(x * scalar, y * scalar); def -(that: Vector): Vector = new Vector(x - that.x, y - that.y); def /(scalar: Double): Vector = new Vector(x / scalar, y / scalar); - def norm: Double = compat.Math.sqrt(x * x + y * y); + def norm: Double = Math.sqrt(x * x + y * y); } //############################################################################ @@ -88,7 +88,7 @@ class PostScript (filename: String, _width: Double, _height: Double) def mm2ps(x: Double) : Double = round(x * 72.0 / 25.4); def round(x: Double): Double = - compat.Math.floor(x * 100.0 + 0.5) / 100.0; + Math.floor(x * 100.0 + 0.5) / 100.0; def scaleAndCenter(frm: Frame, ratio:Double): Frame = { val currentRatio = frm.edgeX.norm / frm.edgeY.norm; diff --git a/test/files/run/Course-2002-09.scala b/test/files/run/Course-2002-09.scala index 029796ab6d..193edb9b7e 100644 --- a/test/files/run/Course-2002-09.scala +++ b/test/files/run/Course-2002-09.scala @@ -49,8 +49,7 @@ class Multiplier(m1: Quantity, m2: Quantity, prod: Quantity) class Squarer(square: Quantity, root: Quantity) extends Constraint { def newValue: Unit = Pair(square.getValue, root.getValue) match { case Pair(Some(x), _ )if (x < 0) => error("Square of negative number") - case Pair(Some(x), _ ) => - root.setValue(compat.Math.sqrt(x), this) + case Pair(Some(x), _ ) => root.setValue(Math.sqrt(x), this) case Pair(_ , Some(x)) => square.setValue(x*x, this) case _ => } diff --git a/test/files/run/Course-2002-10.scala b/test/files/run/Course-2002-10.scala index 79c760afee..c354c82a31 100644 --- a/test/files/run/Course-2002-10.scala +++ b/test/files/run/Course-2002-10.scala @@ -3,7 +3,7 @@ //############################################################################ // $Id$ -import compat.Math.{PI, log} +import Math.{Pi, log} object M0 { diff --git a/test/files/run/arrays.scala b/test/files/run/arrays.scala index 888f5d6545..5fcc5e6614 100644 --- a/test/files/run/arrays.scala +++ b/test/files/run/arrays.scala @@ -101,7 +101,7 @@ object Test { var checks: Int = 0; - def check(test0: Boolean, actual: Any, expected: Any): Unit = { + def check(test0: Boolean, actual: Any, expected: Any) { val test1: Boolean = actual == expected; if (!test0 || !test1) { val s0 = if (test0) "ok" else "KO"; @@ -110,30 +110,30 @@ object Test { val s3 = expected.toString(); error(s0 + " - " + s1 + ": " + s2 + " != " + s3); } - checks = checks + 1; + checks += 1 } - def check_Ta[T <: Any ](xs: Array[T], l: Int, x0: T, c: Check[T]): Unit ={ + def check_Ta[T <: Any ](xs: Array[T], l: Int, x0: T, c: Check[T]) { check(xs.length == l, xs.length, l); check(xs(0) == x0, xs(0), x0); c(xs); } - def check_Tv[T <: AnyVal ](xs: Array[T], l: Int, x0: T, c: Check[T]): Unit ={ + def check_Tv[T <: AnyVal ](xs: Array[T], l: Int, x0: T, c: Check[T]) { check(xs.length == l, xs.length, l); check(xs(0) == x0, xs(0), x0); check_Ta(xs, l, x0, c); c(xs); } - def check_Tr[T <: AnyRef ](xs: Array[T], l: Int, x0: T, c: Check[T]): Unit ={ + def check_Tr[T <: AnyRef ](xs: Array[T], l: Int, x0: T, c: Check[T]) { check(xs.length == l, xs.length, l); check(xs(0) == x0, xs(0), x0); check_Ta(xs, l, x0, c); c(xs); } - def check_To[T <: Object ](xs: Array[T], l: Int, x0: T, c: Check[T]): Unit ={ + def check_To[T <: Object ](xs: Array[T], l: Int, x0: T, c: Check[T]) { check(xs.length == l, xs.length, l); check(xs(0) == x0, xs(0), x0); check_Ta(xs, l, x0, c); @@ -141,7 +141,7 @@ object Test { c(xs); } - def check_Tm[T <: Map ](xs: Array[T], l: Int, x0: T, c: Check[T]): Unit ={ + def check_Tm[T <: Map ](xs: Array[T], l: Int, x0: T, c: Check[T]) { check(xs.length == l, xs.length, l); check(xs(0) == x0, xs(0), x0); check_Ta(xs, l, x0, c); @@ -150,7 +150,7 @@ object Test { c(xs); } - def check_Tn[T <: Strings](xs: Array[T], l: Int, x0: T, c: Check[T]): Unit ={ + def check_Tn[T <: Strings](xs: Array[T], l: Int, x0: T, c: Check[T]) { check(xs.length == l, xs.length, l); check(xs(0) == x0, xs(0), x0); check_Ta(xs, l, x0, c); @@ -162,7 +162,7 @@ object Test { //########################################################################## // Values - import compat.Math._; + import Math._ val u0: Unit = (); val u1: Unit = (); @@ -863,47 +863,47 @@ object Test { //###################################################################### - check_Ta(uarray, 2, u0, ucheck); - check_Ta(zarray, 2, z0, zcheck); - check_Ta(barray, 3, b0, bcheck); - check_Ta(sarray, 3, s0, scheck); - check_Ta(carray, 3, c0, ccheck); - check_Ta(iarray, 3, i0, icheck); - check_Ta(larray, 3, l0, lcheck); - check_Ta(farray, 3, f0, fcheck); - check_Ta(darray, 3, d0, dcheck); - check_Ta(rarray, 6, r0, rcheck); - check_Ta(oarray, 6, o0, ocheck); - check_Ta(marray, 3, m0, mcheck); - check_Ta(narray, 3, n0, ncheck); - - check_Tv(uarray, 2, u0, ucheck); - check_Tv(zarray, 2, z0, zcheck); - check_Tv(barray, 3, b0, bcheck); - check_Tv(sarray, 3, s0, scheck); - check_Tv(carray, 3, c0, ccheck); - check_Tv(iarray, 3, i0, icheck); - check_Tv(larray, 3, l0, lcheck); - check_Tv(farray, 3, f0, fcheck); - check_Tv(darray, 3, d0, dcheck); - - check_Tr(rarray, 6, r0, rcheck); - check_Tr(oarray, 6, o0, ocheck); - check_Tr(marray, 3, m0, mcheck); - check_Tr(narray, 3, n0, ncheck); - - check_To(rarray, 6, r0, rcheck); - check_To(oarray, 6, o0, ocheck); - check_To(marray, 3, m0, mcheck); - check_To(narray, 3, n0, ncheck); - - check_Tm(marray, 3, m0, mcheck); - - check_Tn(narray, 3, n0, ncheck); + check_Ta(uarray, 2, u0, ucheck) + check_Ta(zarray, 2, z0, zcheck) + check_Ta(barray, 3, b0, bcheck) + check_Ta(sarray, 3, s0, scheck) + check_Ta(carray, 3, c0, ccheck) + check_Ta(iarray, 3, i0, icheck) + check_Ta(larray, 3, l0, lcheck) + check_Ta(farray, 3, f0, fcheck) + check_Ta(darray, 3, d0, dcheck) + check_Ta(rarray, 6, r0, rcheck) + check_Ta(oarray, 6, o0, ocheck) + check_Ta(marray, 3, m0, mcheck) + check_Ta(narray, 3, n0, ncheck) + + check_Tv(uarray, 2, u0, ucheck) + check_Tv(zarray, 2, z0, zcheck) + check_Tv(barray, 3, b0, bcheck) + check_Tv(sarray, 3, s0, scheck) + check_Tv(carray, 3, c0, ccheck) + check_Tv(iarray, 3, i0, icheck) + check_Tv(larray, 3, l0, lcheck) + check_Tv(farray, 3, f0, fcheck) + check_Tv(darray, 3, d0, dcheck) + + check_Tr(rarray, 6, r0, rcheck) + check_Tr(oarray, 6, o0, ocheck) + check_Tr(marray, 3, m0, mcheck) + check_Tr(narray, 3, n0, ncheck) + + check_To(rarray, 6, r0, rcheck) + check_To(oarray, 6, o0, ocheck) + check_To(marray, 3, m0, mcheck) + check_To(narray, 3, n0, ncheck) + + check_Tm(marray, 3, m0, mcheck) + + check_Tn(narray, 3, n0, ncheck) //###################################################################### - Console.println("checks: " + checks); + println("checks: " + checks) //###################################################################### } diff --git a/test/files/run/tailcalls.scala b/test/files/run/tailcalls.scala index 9e714b979b..1bd698a832 100644 --- a/test/files/run/tailcalls.scala +++ b/test/files/run/tailcalls.scala @@ -235,51 +235,52 @@ class NonTailCall { // Test code object Test { - def check_success(name: String, closure: => Int, expected: Int): Unit = { - Console.print("test " + name); + def check_success(name: String, closure: => Int, expected: Int) { + print("test " + name) try { - val actual: Int = closure; + val actual: Int = closure if (actual == expected) { - Console.print(" was successful"); + print(" was successful") } else { - Console.print(" failed: expected "+ expected +", found "+ actual); + print(" failed: expected "+ expected +", found "+ actual) } } catch { case exception: Throwable => { - Console.print(" raised exception " + exception); + print(" raised exception " + exception) } } - Console.println; + println } - def check_success_b(name: String, closure: => Boolean, expected: Boolean): Unit = { - Console.print("test " + name); + def check_success_b(name: String, closure: => Boolean, expected: Boolean) { + print("test " + name) try { - val actual: Boolean = closure; + val actual: Boolean = closure if (actual == expected) { - Console.print(" was successful"); + print(" was successful") } else { - Console.print(" failed: expected "+ expected +", found "+ actual); + print(" failed: expected "+ expected +", found "+ actual) } } catch { case exception: Throwable => { Console.print(" raised exception " + exception); } } - Console.println; + println } - def check_overflow(name: String, closure: => Int): Unit = { - Console.print("test " + name); + def check_overflow(name: String, closure: => Int) { + print("test " + name) try { val actual: Int = closure; } catch { - case exception: compat.Platform.StackOverflowError => Console.println(" was successful"); + case exception: compat.Platform.StackOverflowError => + println(" was successful") case exception: Throwable => { - Console.print(" raised exception " + exception); + print(" raised exception " + exception) } } - Console.println; + println } def calibrate: Int = { @@ -289,86 +290,86 @@ object Test { while (!stop) { try { calibrator.f(n, n); - if (n >= compat.Math.MAX_INT / 2) error("calibration failure"); + if (n >= Math.MAX_INT / 2) error("calibration failure"); n = 2 * n; } catch { case exception: compat.Platform.StackOverflowError => stop = true } } - 4 * n; + 4 * n } - def main(args: Array[String]): Unit = { + def main(args: Array[String]) { // compute min and max iteration number val min = 16; val max = calibrate; // test tail calls in different contexts - val Final = new Final(); - val Class = new Class(); - val SubClass = new SubClass(); - val Sealed = new Sealed(); - val SubSealed = new SubSealed(); - check_success("Object .f", Object .f(max, max), 0); - check_success("Final .f", Final .f(max, max), 0); - check_success("Class .f", Class .f(max, max), 0); - check_success("SubClass .f", SubClass .f(max, max), max); - check_success("Sealed .f", Sealed .f(max, max), 0); - check_success("SubSealed.f", SubSealed.f(max, max), max); - Console.println; + val Final = new Final() + val Class = new Class() + val SubClass = new SubClass() + val Sealed = new Sealed() + val SubSealed = new SubSealed() + check_success("Object .f", Object .f(max, max), 0) + check_success("Final .f", Final .f(max, max), 0) + check_success("Class .f", Class .f(max, max), 0) + check_success("SubClass .f", SubClass .f(max, max), max) + check_success("Sealed .f", Sealed .f(max, max), 0) + check_success("SubSealed.f", SubSealed.f(max, max), max) + println // test tail calls in nested classes/objects - val c: C = new C; - check_success("O .f", O .f(max, max), 0); - check_success("c .f", c .f(max, max), 0); - check_success("O.O .f", O.O .f(max, max), 0); - check_success("O.c .f", O.c .f(max, max), 0); - check_success("c.O .f", c.O .f(max, max), 0); - check_success("c.c .f", c.c .f(max, max), 0); - check_success("O.O.O .f", O.O.O .f(max, max), 0); - check_success("O.O.c .f", O.O.c .f(max, max), 0); - check_success("O.c.O .f", O.c.O .f(max, max), 0); - check_success("O.c.c .f", O.c.c .f(max, max), 0); - check_success("c.O.O .f", c.O.O .f(max, max), 0); - check_success("c.O.c .f", c.O.c .f(max, max), 0); - check_success("c.c.O .f", c.c.O .f(max, max), 0); - check_success("c.c.c .f", c.c.c .f(max, max), 0); - check_success("O.O.O.O.f", O.O.O.O.f(max, max), 0); - check_success("O.O.O.c.f", O.O.O.c.f(max, max), 0); - check_success("O.O.c.O.f", O.O.c.O.f(max, max), 0); - check_success("O.O.c.c.f", O.O.c.c.f(max, max), 0); - check_success("O.c.O.O.f", O.c.O.O.f(max, max), 0); - check_success("O.c.O.c.f", O.c.O.c.f(max, max), 0); - check_success("O.c.c.O.f", O.c.c.O.f(max, max), 0); - check_success("O.c.c.c.f", O.c.c.c.f(max, max), 0); - check_success("c.O.O.O.f", c.O.O.O.f(max, max), 0); - check_success("c.O.O.c.f", c.O.O.c.f(max, max), 0); - check_success("c.O.c.O.f", c.O.c.O.f(max, max), 0); - check_success("c.O.c.c.f", c.O.c.c.f(max, max), 0); - check_success("c.c.O.O.f", c.c.O.O.f(max, max), 0); - check_success("c.c.O.c.f", c.c.O.c.f(max, max), 0); - check_success("c.c.c.O.f", c.c.c.O.f(max, max), 0); - check_success("c.c.c.c.f", c.c.c.c.f(max, max), 0); - Console.println; + val c: C = new C + check_success("O .f", O .f(max, max), 0) + check_success("c .f", c .f(max, max), 0) + check_success("O.O .f", O.O .f(max, max), 0) + check_success("O.c .f", O.c .f(max, max), 0) + check_success("c.O .f", c.O .f(max, max), 0) + check_success("c.c .f", c.c .f(max, max), 0) + check_success("O.O.O .f", O.O.O .f(max, max), 0) + check_success("O.O.c .f", O.O.c .f(max, max), 0) + check_success("O.c.O .f", O.c.O .f(max, max), 0) + check_success("O.c.c .f", O.c.c .f(max, max), 0) + check_success("c.O.O .f", c.O.O .f(max, max), 0) + check_success("c.O.c .f", c.O.c .f(max, max), 0) + check_success("c.c.O .f", c.c.O .f(max, max), 0) + check_success("c.c.c .f", c.c.c .f(max, max), 0) + check_success("O.O.O.O.f", O.O.O.O.f(max, max), 0) + check_success("O.O.O.c.f", O.O.O.c.f(max, max), 0) + check_success("O.O.c.O.f", O.O.c.O.f(max, max), 0) + check_success("O.O.c.c.f", O.O.c.c.f(max, max), 0) + check_success("O.c.O.O.f", O.c.O.O.f(max, max), 0) + check_success("O.c.O.c.f", O.c.O.c.f(max, max), 0) + check_success("O.c.c.O.f", O.c.c.O.f(max, max), 0) + check_success("O.c.c.c.f", O.c.c.c.f(max, max), 0) + check_success("c.O.O.O.f", c.O.O.O.f(max, max), 0) + check_success("c.O.O.c.f", c.O.O.c.f(max, max), 0) + check_success("c.O.c.O.f", c.O.c.O.f(max, max), 0) + check_success("c.O.c.c.f", c.O.c.c.f(max, max), 0) + check_success("c.c.O.O.f", c.c.O.O.f(max, max), 0) + check_success("c.c.O.c.f", c.c.O.c.f(max, max), 0) + check_success("c.c.c.O.f", c.c.c.O.f(max, max), 0) + check_success("c.c.c.c.f", c.c.c.c.f(max, max), 0) + println // test tail calls with different signatures - val TailCall = new TailCall("S"); - check_success("TailCall.f1", TailCall.f1(max, max ), 0); - check_success("TailCall.f2", TailCall.f2(max, max ), 0); - check_success("TailCall.f3", TailCall.f3(max, max, Nil), 0); - check_success("TailCall.f4", TailCall.f4(max, max ), 0); - check_success("TailCall.g1", TailCall.g1(max, max ), 0); - check_success("TailCall.g2", TailCall.g2(max, max ), 0); - check_success("TailCall.g3", TailCall.g3(max, max, Nil), 0); - check_success("TailCall.h1", TailCall.h1(max, max ), 0); - Console.println; - - val NonTailCall = new NonTailCall; + val TailCall = new TailCall("S") + check_success("TailCall.f1", TailCall.f1(max, max ), 0) + check_success("TailCall.f2", TailCall.f2(max, max ), 0) + check_success("TailCall.f3", TailCall.f3(max, max, Nil), 0) + check_success("TailCall.f4", TailCall.f4(max, max ), 0) + check_success("TailCall.g1", TailCall.g1(max, max ), 0) + check_success("TailCall.g2", TailCall.g2(max, max ), 0) + check_success("TailCall.g3", TailCall.g3(max, max, Nil), 0) + check_success("TailCall.h1", TailCall.h1(max, max ), 0) + println + + val NonTailCall = new NonTailCall check_success("NonTailCall.f1", NonTailCall.f1(2), 0) check_overflow("NonTailCall.f2", NonTailCall.f2(max)) - check_success_b("TailCall.b1", TailCall.b1(max), true); - check_success_b("TailCall.b2", TailCall.b2(max), true); + check_success_b("TailCall.b1", TailCall.b1(max), true) + check_success_b("TailCall.b2", TailCall.b2(max), true) val FancyTailCalls = new FancyTailCalls; check_success("FancyTailCalls.tcTryLocal", FancyTailCalls.tcTryLocal(max, max), max) -- cgit v1.2.3