summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-06-18 09:19:21 +0000
committermichelou <michelou@epfl.ch>2007-06-18 09:19:21 +0000
commit52ccdc5627e3d3d34019b57560601a7e3ec89483 (patch)
tree9c63a503562b570d0bbffeaf7fb284ab7f639b26 /test/files
parent2cae4689ebef09384c1d26213a5a9904a2a4e02d (diff)
downloadscala-52ccdc5627e3d3d34019b57560601a7e3ec89483.tar.gz
scala-52ccdc5627e3d3d34019b57560601a7e3ec89483.tar.bz2
scala-52ccdc5627e3d3d34019b57560601a7e3ec89483.zip
added tests for scala.Iterable
Diffstat (limited to 'test/files')
-rw-r--r--test/files/run/collections.scala86
-rw-r--r--test/files/run/iterables.check2
-rw-r--r--test/files/run/iterables.scala14
3 files changed, 59 insertions, 43 deletions
diff --git a/test/files/run/collections.scala b/test/files/run/collections.scala
index 3f3bfb6b06..7c723c9fc7 100644
--- a/test/files/run/collections.scala
+++ b/test/files/run/collections.scala
@@ -5,113 +5,113 @@ object Test extends Application {
val printTime = false
- def sum[A](xs: Iterable[int]) = (0 /: xs)((x, y) => x + y)
+ def sum[A](xs: Iterable[Int]) = (0 /: xs)((x, y) => x + y)
- def time(op: => unit): unit = {
+ def time(op: => Unit) {
val start = currentTime
op
- if (printTime) Console.println(" time = "+(currentTime - start)+"ms")
+ if (printTime) println(" time = "+(currentTime - start)+"ms")
}
- def test(msg: String, s0: collection.immutable.Set[int], iters: int) = {
- Console.println("***** "+msg+":")
+ def test(msg: String, s0: collection.immutable.Set[Int], iters: Int) = {
+ println("***** "+msg+":")
var s = s0
s = s + 2
s = s + (3, 4000, 10000)
- Console.println("test1: "+sum(s))
+ println("test1: "+sum(s))
time {
s = s ++ (List.range(0, iters) map (2*))
- Console.println("test2: "+sum(s)+", iters = "+iters)
+ println("test2: "+sum(s)+", iters = "+iters)
}
time {
var x = 0
- for (val i <- (0 to 10000))
- if (s contains i) x = x + i
- Console.println("test3: "+x)
+ for (i <- 0 to 10000)
+ if (s contains i) x += i
+ println("test3: "+x)
}
}
- def test(msg: String, s0: collection.mutable.Set[int], iters: int) = {
- Console.println("***** "+msg+":")
+ def test(msg: String, s0: collection.mutable.Set[Int], iters: Int) = {
+ println("***** "+msg+":")
var s = s0
s = s + 2
s = s + (3, 4000, 10000)
- Console.println("test1: "+sum(s))
+ println("test1: "+sum(s))
time {
s = s ++ (List.range(0, iters) map (2*))
- Console.println("test2: "+sum(s)+", iters = "+iters)
+ println("test2: "+sum(s)+", iters = "+iters)
}
time {
var x = 0
- for (val i <- (0 to 10000))
- if (s contains i) x = x + i
- Console.println("test3: "+x)
+ for (i <- 0 to 10000)
+ if (s contains i) x += i
+ println("test3: "+x)
}
}
- def test(msg: String, s0: collection.immutable.Map[int, int], iters: int) = {
- Console.println("***** "+msg+":")
+ def test(msg: String, s0: collection.immutable.Map[Int, Int], iters: Int) = {
+ println("***** "+msg+":")
var s = s0
s = s + (2 -> 2)
s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000)
- Console.println("test1: "+sum(s map (_._2)))
+ println("test1: "+sum(s map (_._2)))
time {
s = s ++ (List.range(0, iters) map (x => x * 2 -> x * 2))
- Console.println("test2: "+sum(s map (_._2))+", iters = "+iters)
+ println("test2: "+sum(s map (_._2))+", iters = "+iters)
}
time {
var x = 0
- for (val i <- (0 to 10000))
+ for (i <- 0 to 10000)
s get i match {
- case Some(i) => x = x + i
+ case Some(i) => x += i
case None =>
}
- Console.println("test3: "+x)
+ println("test3: "+x)
}
if (iters == 5000) {
time {
var s1 = s
var x = 0
- for (val i <- (0 to 10000)) {
+ for (i <- 0 to 10000) {
s get i match {
- case Some(i) => x = x + i
+ case Some(i) => x += i
case None =>
}
s1 = s1 + ((i + 10000) -> i)
}
- Console.println("test4: "+x)
+ println("test4: "+x)
}
}
}
- def test(msg: String, s0: collection.mutable.Map[int, int], iters: int) = {
- Console.println("***** "+msg+":")
+ def test(msg: String, s0: collection.mutable.Map[Int, Int], iters: Int) = {
+ println("***** "+msg+":")
var s = s0
s = s + (2 -> 2)
s = s + (3 -> 3, 4000 -> 4000, 10000 -> 10000)
- Console.println("test1: "+sum(s map (_._2)))
+ println("test1: "+sum(s map (_._2)))
time {
s = s ++ (List.range(0, iters) map (x => x * 2 -> x * 2))
- Console.println("test2: "+sum(s map (_._2))+", iters = "+iters)
+ println("test2: "+sum(s map (_._2))+", iters = "+iters)
}
time {
var x = 0
- for (val i <- (0 to 10000))
+ for (i <- 0 to 10000)
s get i match {
- case Some(i) => x = x + i
+ case Some(i) => x += i
case None =>
}
- Console.println("test3: "+x)
+ println("test3: "+x)
}
}
- test("mutable.HashSet", new mutable.HashSet[int], 5000)
- test("immutable.Set", immutable.Set[int](), 5000)
- test("immutable.ListSet", new immutable.ListSet[int], 5000)
- test("immutable.TreeSet", new immutable.TreeSet[int], 5000)
- test("mutable.HashMap", new mutable.HashMap[int, int], 5000)
- test("immutable.Map", immutable.Map[int, int](), 5000)
- test("immutable.TreeMap", new immutable.TreeMap[int, int], 5000)
- test("immutable.ListMap", new immutable.ListMap[int, int], 3000)
- test("immutable.UnBalancedTreeMap", new immutable.UnbalancedTreeMap[int, int], 1000)
+ test("mutable.HashSet", new mutable.HashSet[Int], 5000)
+ test("immutable.Set", immutable.Set[Int](), 5000)
+ test("immutable.ListSet", new immutable.ListSet[Int], 5000)
+ test("immutable.TreeSet", new immutable.TreeSet[Int], 5000)
+ test("mutable.HashMap", new mutable.HashMap[Int, Int], 5000)
+ test("immutable.Map", immutable.Map[Int, Int](), 5000)
+ test("immutable.TreeMap", new immutable.TreeMap[Int, Int], 5000)
+ test("immutable.ListMap", new immutable.ListMap[Int, Int], 3000)
+ test("immutable.UnBalancedTreeMap", new immutable.UnbalancedTreeMap[Int, Int], 1000)
}
diff --git a/test/files/run/iterables.check b/test/files/run/iterables.check
new file mode 100644
index 0000000000..2660f51aa5
--- /dev/null
+++ b/test/files/run/iterables.check
@@ -0,0 +1,2 @@
+false
+0,1,2,3,4,5,6,7,8,9
diff --git a/test/files/run/iterables.scala b/test/files/run/iterables.scala
new file mode 100644
index 0000000000..7a29b80e8d
--- /dev/null
+++ b/test/files/run/iterables.scala
@@ -0,0 +1,14 @@
+object Test extends Application {
+ class Test(n: Int) extends Iterable[Int] {
+ private var i = 0
+ def elements = new Iterator[Int] {
+ def hasNext = i < n
+ def next =
+ if (hasNext) { val v = i; i += 1; v }
+ else throw new IndexOutOfBoundsException("empty iterator")
+ }
+ }
+ val x = new Test(10)
+ println(x.isEmpty)
+ println(x.mkString(","))
+}