summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-01-03 15:56:13 +0000
committerMartin Odersky <odersky@gmail.com>2007-01-03 15:56:13 +0000
commita961d3dcd6f93ee006cff1d386052bf62326739a (patch)
tree5af3312932236340708522dfd078f32beed20519 /test/files/run
parent02a45e20bb6f68808708dca377bc72ccaf5bba3d (diff)
downloadscala-a961d3dcd6f93ee006cff1d386052bf62326739a.tar.gz
scala-a961d3dcd6f93ee006cff1d386052bf62326739a.tar.bz2
scala-a961d3dcd6f93ee006cff1d386052bf62326739a.zip
1.
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/Course-2002-10.scala18
-rw-r--r--test/files/run/collections.check28
-rwxr-xr-xtest/files/run/collections.scala100
-rw-r--r--test/files/run/infix.check2
-rwxr-xr-xtest/files/run/infix.scala12
-rw-r--r--test/files/run/tuples.check2
-rwxr-xr-xtest/files/run/tuples.scala8
7 files changed, 161 insertions, 9 deletions
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")
+ }
+}