From a961d3dcd6f93ee006cff1d386052bf62326739a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 3 Jan 2007 15:56:13 +0000 Subject: 1. --- test/files/jvm/xml01.scala | 2 +- test/files/neg/bug846.check | 6 +++ test/files/neg/bug846.scala | 13 +++++ test/files/pos/bounds.scala | 11 ++++ test/files/pos/nested2.scala | 9 ++++ test/files/run/Course-2002-10.scala | 18 +++---- test/files/run/collections.check | 28 ++++++++++ test/files/run/collections.scala | 100 ++++++++++++++++++++++++++++++++++++ test/files/run/infix.check | 2 + test/files/run/infix.scala | 12 +++++ test/files/run/tuples.check | 2 + test/files/run/tuples.scala | 8 +++ 12 files changed, 201 insertions(+), 10 deletions(-) create mode 100644 test/files/neg/bug846.check create mode 100755 test/files/neg/bug846.scala create mode 100755 test/files/pos/bounds.scala create mode 100755 test/files/pos/nested2.scala create mode 100644 test/files/run/collections.check create mode 100755 test/files/run/collections.scala create mode 100644 test/files/run/infix.check create mode 100755 test/files/run/infix.scala create mode 100644 test/files/run/tuples.check create mode 100755 test/files/run/tuples.scala (limited to 'test') diff --git a/test/files/jvm/xml01.scala b/test/files/jvm/xml01.scala index 8c99cfd358..b0a3044fc1 100644 --- a/test/files/jvm/xml01.scala +++ b/test/files/jvm/xml01.scala @@ -177,7 +177,7 @@ object Test { //Text("John Mitchell"), Elem(null,"title",e,sc,Text("Foundations of Programming Languages")) //Text("Foundations of Programming Languages") - ) + ): Seq[Node] ); // test group node diff --git a/test/files/neg/bug846.check b/test/files/neg/bug846.check new file mode 100644 index 0000000000..b60b4c7125 --- /dev/null +++ b/test/files/neg/bug846.check @@ -0,0 +1,6 @@ +bug846.scala:9 error: type mismatch; + found : scala.Null(null) + required: B + if (a != null) f(a) else null + ^ +one error found diff --git a/test/files/neg/bug846.scala b/test/files/neg/bug846.scala new file mode 100755 index 0000000000..be105a71aa --- /dev/null +++ b/test/files/neg/bug846.scala @@ -0,0 +1,13 @@ +package test; +trait Test { + type Bar; + trait FooImpl; + trait Bob { + def bar : Bar with FooImpl; + } + def ifn[A,B](a : A)(f : A => B): B = + if (a != null) f(a) else null + val bob : Bob = null; + val bar = ifn(bob)(.bar); + assert(bar == null); +} diff --git a/test/files/pos/bounds.scala b/test/files/pos/bounds.scala new file mode 100755 index 0000000000..5bc5cf89dc --- /dev/null +++ b/test/files/pos/bounds.scala @@ -0,0 +1,11 @@ +trait Map[A, +C] { + def ++ [B1 >: C] (kvs: Iterable[Pair[A, B1]]): Map[A, B1] = this + def ++ [B1 >: C] (kvs: Iterator[Pair[A, B1]]): Map[A, B1] = this +} + +class ListMap[A, +B] extends Map[A, B] {} + +object ListMap { + def empty[X, Y] = new ListMap[X, Y] + def apply[A1, B2](elems: Pair[A1, B2]*): Map[A1, B2] = empty[A1,B2].++(elems.elements) +} diff --git a/test/files/pos/nested2.scala b/test/files/pos/nested2.scala new file mode 100755 index 0000000000..302688a0ef --- /dev/null +++ b/test/files/pos/nested2.scala @@ -0,0 +1,9 @@ +class C[A] { + class D[B] { + } +} + +object Test { + val x = new C[String] + val y: C[String]#D[int] = new x.D[int] +} diff --git a/test/files/run/Course-2002-10.scala b/test/files/run/Course-2002-10.scala index 258b6dc8fd..79c760afee 100644 --- a/test/files/run/Course-2002-10.scala +++ b/test/files/run/Course-2002-10.scala @@ -31,9 +31,9 @@ object M1 { Stream.cons(s.head, partialSums(s.tail) map (x => x + s.head)); def euler(s: Stream[double]): Stream[double] = { - val nm1 = s at 0; - val n = s at 1; - val np1 = s at 2; + val nm1 = s apply 0; + val n = s apply 1; + val np1 = s apply 2; Stream.cons(np1 - ((np1 - n)*(np1 - n) / (nm1 - 2*n + np1)),euler(s.tail)) }; @@ -68,9 +68,9 @@ object M1 { var i = 0; while (i < 10) { Console.print("pi("+i+") = "); - Console.print(str(pi0.at(i)) + ", "); - Console.print(str(pi1.at(i)) + ", "); - Console.print(str(pi2.at(i)) + "\n"); + Console.print(str(pi0.apply(i)) + ", "); + Console.print(str(pi1.apply(i)) + ", "); + Console.print(str(pi2.apply(i)) + "\n"); i = i + 1; } Console.print("pi = "); @@ -81,9 +81,9 @@ object M1 { i = 0; while (i < 10) { Console.print("ln("+i+") = "); - Console.print(str(ln0.at(i)) + ", "); - Console.print(str(ln1.at(i)) + ", "); - Console.print(str(ln2.at(i)) + "\n"); + Console.print(str(ln0.apply(i)) + ", "); + Console.print(str(ln1.apply(i)) + ", "); + Console.print(str(ln2.apply(i)) + "\n"); i = i + 1; } Console.print("ln = "); diff --git a/test/files/run/collections.check b/test/files/run/collections.check new file mode 100644 index 0000000000..ad92767fa6 --- /dev/null +++ b/test/files/run/collections.check @@ -0,0 +1,28 @@ +***** immutable.ListSet: +test1: 14005 +test2: 25005003 +test3: 25005003 +***** immutable.TreeSet: +test1: 14005 +test2: 25005003 +test3: 25005003 +***** mutable.HashSet: +test1: 14005 +test2: 25005003 +test3: 25005003 +***** immutable.ListMap: +test1: 14005 +test2: 1013003 +test3: 1013003 +***** immutable.TreeMap: +test1: 14005 +test2: 1013003 +test3: 1013003 +***** immutable.UnBalancedTreeMap: +test1: 14005 +test2: 1013003 +test3: 1013003 +***** mutable.HashMap: +test1: 14005 +test2: 25005003 +test3: 25005003 diff --git a/test/files/run/collections.scala b/test/files/run/collections.scala new file mode 100755 index 0000000000..5e97b2df38 --- /dev/null +++ b/test/files/run/collections.scala @@ -0,0 +1,100 @@ +import collection._ + +object Test extends Application { + + val printTime = false + + def sum[A](xs: Iterable[int]) = (0 /: xs)((x, y) => x + y) + + def time(op: => unit): unit = { + val start = System.currentTimeMillis; + op + if (printTime) Console.println(" time = "+(System.currentTimeMillis - start)+"ms") + } + + def test(msg: String, s0: collection.immutable.Set[int]) = { + Console.println("***** "+msg+":") + var s = s0 + s = s + 2 + s = s + (3, 4000, 10000) + Console.println("test1: "+sum(s)) + time { + s = s ++ (List.range(0, 5000) map (2*)) + Console.println("test2: "+sum(s)) + } + time { + var x = 0 + for (val i <- (0 to 10000)) + if (s contains i) x = x + i + Console.println("test3: "+x) + } + } + + def test(msg: String, s0: collection.mutable.Set[int]) = { + Console.println("***** "+msg+":") + var s = s0 + s = s + 2 + s = s + (3, 4000, 10000) + Console.println("test1: "+sum(s)) + time { + s = s ++ (List.range(0, 5000) map (2*)) + Console.println("test2: "+sum(s)) + } + time { + var x = 0 + for (val i <- (0 to 10000)) + if (s contains i) x = x + i + Console.println("test3: "+x) + } + } + + def test(msg: String, s0: collection.immutable.Map[int, int]) = { + Console.println("***** "+msg+":") + var s = s0 + s = s + (2 -> 2) + s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000) + Console.println("test1: "+sum(s map (._2))) + time { + s = s ++ (List.range(0, 1000) map (x => x * 2 -> x * 2)) + Console.println("test2: "+sum(s map (._2))) + } + time { + var x = 0 + for (val i <- (0 to 10000)) + s get i match { + case Some(i) => x = x + i + case None => + } + Console.println("test3: "+x) + } + } + + def test(msg: String, s0: collection.mutable.Map[int, int]) = { + Console.println("***** "+msg+":") + var s = s0 + s = s + (2 -> 2) + s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000) + Console.println("test1: "+sum(s map (._2))) + time { + s = s ++ (List.range(0, 5000) map (x => x * 2 -> x * 2)) + Console.println("test2: "+sum(s map (._2))) + } + time { + var x = 0 + for (val i <- (0 to 10000)) + s get i match { + case Some(i) => x = x + i + case None => + } + Console.println("test3: "+x) + } + } + + test("immutable.ListSet", new immutable.ListSet[int]) + test("immutable.TreeSet", new immutable.TreeSet[int]) + test("mutable.HashSet", new mutable.HashSet[int]) + test("immutable.ListMap", new immutable.ListMap[int, int]) + test("immutable.TreeMap", new immutable.TreeMap[int, int]) + test("immutable.UnBalancedTreeMap", new immutable.UnbalancedTreeMap[int, int]) + test("mutable.HashMap", new mutable.HashMap[int, int]) +} diff --git a/test/files/run/infix.check b/test/files/run/infix.check new file mode 100644 index 0000000000..dd0457b776 --- /dev/null +++ b/test/files/run/infix.check @@ -0,0 +1,2 @@ +op(op(op(null,0,0),1,1),2,2) +OK diff --git a/test/files/run/infix.scala b/test/files/run/infix.scala new file mode 100755 index 0000000000..9df07ac317 --- /dev/null +++ b/test/files/run/infix.scala @@ -0,0 +1,12 @@ +case class op(x: op, y: int, z: int) { + def op(y: int, z: int) = new op(this, y, z) +} + +object Test extends Application { + val xs = new op(null, 0, 0) op (1, 1) op (2, 2) + Console.println(xs) + xs match { + case null op (0, 0) op (1, 1) op (2, 2) => Console.println("OK") + } +} + diff --git a/test/files/run/tuples.check b/test/files/run/tuples.check new file mode 100644 index 0000000000..731f2746c9 --- /dev/null +++ b/test/files/run/tuples.check @@ -0,0 +1,2 @@ +{1,abc,true} +OK diff --git a/test/files/run/tuples.scala b/test/files/run/tuples.scala new file mode 100755 index 0000000000..c6dcda4af8 --- /dev/null +++ b/test/files/run/tuples.scala @@ -0,0 +1,8 @@ +object Test extends Application { + var xyz: {int, String, boolean} = _ + xyz = { 1, "abc", true } + Console.println(xyz) + xyz match { + case { 1, "abc", true } => Console.println("OK") + } +} -- cgit v1.2.3