From 4a64ac9c7b94b249087cd25712dfb547013f5ed4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 30 Jan 2007 15:17:05 +0000 Subject: fixed flathashtable. --- test/files/run/colltest.scala | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/files/run/colltest.scala (limited to 'test/files/run/colltest.scala') diff --git a/test/files/run/colltest.scala b/test/files/run/colltest.scala new file mode 100644 index 0000000000..024f2fb1f4 --- /dev/null +++ b/test/files/run/colltest.scala @@ -0,0 +1,50 @@ +import collection.mutable._ +class TestSet(s0: Set[int], s1: Set[int]) { + val Iterations = 1000000 + val Range = 100000 + val testEachStep = false + val Threshold = 20000 + val r = new java.util.Random(12345) + def test(s: Set[int], n: int): Any = { + val v = n >> 3 + n & 7 match { + case 0 | 1 | 2 => s contains v + case 3 => s += v + case 4 => s -= v + case 5 => if (s.size > Threshold) s -= v else s += v + case 6 => s += v + case 7 => s.size + } + } + def explain(n: int, s: Set[int]): String = n & 7 match { + case 0 | 1 | 2 => "contains" + case 3 => "add" + case 4 => "remove" + case 5 => if (s.size > Threshold) "remove" else "add" + case 6 => "add" + case 7 => "size" + } + def checkSubSet(pre: String, s0: Set[int], s1: Set[int]) { + for (val e <- s0.elements) + if (!(s1 contains e)) { + assert(false, pre+" element: "+e+"\n S0 = "+s0+"\n S1 = "+s1) + } + } + for (val i <- 0 until Iterations) { + val n = r.nextInt(Range) + val res0 = test(s0, n) + val res1 = test(s1, n) + //Console.println("operation = "+explain(n, s0)+", value ="+(n >> 3)+", result0 = "+res0) + if (testEachStep) { + checkSubSet("superfluous", s0, s1) + checkSubSet("missing", s1, s0) + } + if (res0 != res1) + assert(false, "DIFFERENCE , operation = "+explain(n, s0)+", value ="+(n >> 3)+ + ", result0 = "+res0+", result1 = "+res1) + } + Console.println("succeeded for "+Iterations+" iterations.") +} +object Test extends Application { + new TestSet(HashSet.empty, new LinkedHashSet) +} -- cgit v1.2.3