summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/collection-stacks.check14
-rw-r--r--test/files/run/collection-stacks.scala38
-rw-r--r--test/files/run/deeps.check83
-rw-r--r--test/files/run/deeps.scala111
-rw-r--r--test/files/run/t0485.check32
-rw-r--r--test/files/run/t0485.scala54
-rw-r--r--test/files/run/unittest_collection.scala103
7 files changed, 435 insertions, 0 deletions
diff --git a/test/files/run/collection-stacks.check b/test/files/run/collection-stacks.check
new file mode 100644
index 0000000000..fcb39c460c
--- /dev/null
+++ b/test/files/run/collection-stacks.check
@@ -0,0 +1,14 @@
+1-2-3: true
+1-2-3: true
+apply
+1: true
+1: true
+3: true
+3: true
+top
+3: true
+3: true
+pop
+1-2: true
+3: true
+1-2: true
diff --git a/test/files/run/collection-stacks.scala b/test/files/run/collection-stacks.scala
new file mode 100644
index 0000000000..b159be07aa
--- /dev/null
+++ b/test/files/run/collection-stacks.scala
@@ -0,0 +1,38 @@
+import scala.collection._
+
+object Test extends Application {
+ def mutableStack[T](xs: T*): mutable.Stack[T] = {
+ val s = new mutable.Stack[T]
+ s.pushAll(xs)
+ s
+ }
+
+ def immutableStack[T](xs: T*): immutable.Stack[T] = {
+ immutable.Stack.Empty pushAll xs
+ }
+
+ def check[T](expected: T, got: T) {
+ println(got + ": " + (expected == got))
+ }
+
+ // check #957
+ check("1-2-3", immutableStack(1, 2, 3).iterator.mkString("-"))
+ check("1-2-3", mutableStack(1, 2, 3).iterator.mkString("-"))
+
+ println("apply")
+ check(1, immutableStack(1, 2, 3).apply(0))
+ check(1, mutableStack(1, 2, 3).apply(0))
+ check(3, immutableStack(1, 2, 3).apply(2))
+ check(3, mutableStack(1, 2, 3).apply(2))
+
+ println("top")
+ check(3, immutableStack(1, 2, 3).top)
+ check(3, mutableStack(1, 2, 3).top)
+
+ println("pop")
+ check("1-2", immutableStack(1, 2, 3).pop.mkString("-"))
+ check(3, mutableStack(1, 2, 3).pop())
+ check("1-2", { val s = mutableStack(1, 2, 3); s.pop(); s.toList.mkString("-") })
+}
+
+// vim: set ts=2 sw=2 et:
diff --git a/test/files/run/deeps.check b/test/files/run/deeps.check
new file mode 100644
index 0000000000..f1925fcbc1
--- /dev/null
+++ b/test/files/run/deeps.check
@@ -0,0 +1,83 @@
+false
+false
+true
+
+false
+false
+true
+
+x=Array(1)
+y=Array(1)
+false
+false
+true
+
+x=Array(Array(1), Array(1))
+y=Array(Array(1), Array(1))
+false
+false
+true
+
+x=Array(Array(Array(1), Array(1)), Array(Array(1), Array(1)))
+y=Array(Array(Array(1), Array(1)), Array(Array(1), Array(1)))
+false
+false
+true
+
+false
+false
+true
+false
+false
+true
+Array(true, false)
+Array(true, false)
+[true;false]
+true;false
+
+Array([Z@0000000, [Z@0000000)
+Array(Array(true, false), Array(true, false))
+[[true;false];[true;false]]
+true;false;true;false
+
+Array([[Z@0000000, [[Z@0000000)
+Array(Array(Array(true, false), Array(true, false)), Array(Array(true, false), Array(true, false)))
+[[[true;false];[true;false]];[[true;false];[true;false]]]
+true;false;true;false;true;false;true;false
+
+Array(1.0, 0.0)
+Array(1.0, 0.0)
+[1.0;0.0]
+1.0;0.0
+
+Array([D@0000000, [D@0000000)
+Array(Array(1.0, 0.0), Array(1.0, 0.0))
+[[1.0;0.0];[1.0;0.0]]
+1.0;0.0;1.0;0.0
+
+Array([[D@0000000, [[D@0000000)
+Array(Array(Array(1.0, 0.0), Array(1.0, 0.0)), Array(Array(1.0, 0.0), Array(1.0, 0.0)))
+[[[1.0;0.0];[1.0;0.0]];[[1.0;0.0];[1.0;0.0]]]
+1.0;0.0;1.0;0.0;1.0;0.0;1.0;0.0
+
+Array(a, b)
+Array(a, b)
+[a;b]
+a;b
+
+Array([Ljava.lang.String;@0000000, [Ljava.lang.String;@0000000)
+Array(Array(a, b), Array(a, b))
+[[a;b];[a;b]]
+a;b;a;b
+
+Array([[Ljava.lang.String;@0000000, [[Ljava.lang.String;@0000000)
+Array(Array(Array(a, b), Array(a, b)), Array(Array(a, b), Array(a, b)))
+[[[a;b];[a;b]];[[a;b];[a;b]]]
+a;b;a;b;a;b;a;b
+
+[[true; false]; [false]]
+[[1; 2]; [3]]
+[[1; 2]; [3]]
+
+Array(boo, and, foo)
+Array(a)
diff --git a/test/files/run/deeps.scala b/test/files/run/deeps.scala
new file mode 100644
index 0000000000..c93c040ef8
--- /dev/null
+++ b/test/files/run/deeps.scala
@@ -0,0 +1,111 @@
+//############################################################################
+// deepEquals / deepToString
+//############################################################################
+
+//############################################################################
+// need to revisit array equqality
+object Test extends Application {
+
+ def testEquals1 {
+ println(Array(1) == Array(1))
+ println(Array(1) equals Array(1))
+ println(Array(1) deepEquals Array(1))
+ println
+ }
+
+ def testEquals2 {
+ println(Array(Array(1), Array(2)) == Array(Array(1), Array(2)))
+ println(Array(Array(1), Array(2)) equals Array(Array(1), Array(2)))
+ println(Array(Array(1), Array(2)) deepEquals Array(Array(1), Array(2)))
+ println
+ }
+
+ def testEquals3 {
+ val a1 = Array(1)
+ val b1 = Array(1)
+ val a2 = Array(a1, b1)
+ val b2 = Array(a1, b1)
+ val a3 = Array(a2, b2)
+ val b3 = Array(a2, b2)
+ def test[T](x: Array[T], y: Array[T]) {
+ println("x=" + x.deepToString)
+ println("y=" + y.deepToString)
+ println(x == y)
+ println(x equals y)
+ println(x deepEquals y)
+ println
+ }
+ test(a1, b1)
+ test(a2, b2)
+ test(a3, b3)
+ }
+
+ def testEquals4 {
+ println("boo:and:foo".split(':') == "boo:and:foo".split(':'))
+ println("boo:and:foo".split(':') equals "boo:and:foo".split(':'))
+ println("boo:and:foo".split(':') deepEquals "boo:and:foo".split(':'))
+
+ val xs = new java.util.ArrayList[String](); xs.add("a")
+ val ys = new java.util.ArrayList[String](); ys.add("a")
+ println(xs.toArray == ys.toArray)
+ println(xs.toArray equals ys.toArray)
+ println(xs.toArray deepEquals ys.toArray)
+ }
+
+ def testToString1 {
+ def sweep(s: String) =
+ s.replaceAll("D@[0-9a-fA-F]+", "D@0000000")
+ .replaceAll("Z@[0-9a-fA-F]+", "Z@0000000")
+ .replaceAll(";@[0-9a-fA-F]+", ";@0000000")
+ def test[T](a: Array[T]) {
+ println(sweep(a.toString))
+ println(a.deepToString)
+ println(a.deepMkString("[", ";", "]"))
+ println(a.deepMkString(";"))
+ println
+ }
+
+ val ba1 = Array(true, false)
+ val ba2 = Array(ba1, ba1)
+ val ba3 = Array(ba2, ba2)
+ test(ba1)
+ test(ba2)
+ test(ba3)
+
+ val da1 = Array(1.0d, 0.0d)
+ val da2 = Array(da1, da1)
+ val da3 = Array(da2, da2)
+ test(da1)
+ test(da2)
+ test(da3)
+
+ val sa1 = Array("a", "b")
+ val sa2 = Array(sa1, sa1)
+ val sa3 = Array(sa2, sa2)
+ test(sa1)
+ test(sa2)
+ test(sa3)
+ }
+
+ def testToString2 {
+ println(Array(Array(true, false), Array(false)).deepMkString("[", "; ", "]"))
+ println(Array(Array('1', '2'), Array('3')).deepMkString("[", "; ", "]"))
+ println(Array(Array(1, 2), Array(3)).deepMkString("[", "; ", "]"))
+ println
+ }
+
+ def testToString3 {
+ println("boo:and:foo".split(':').deepToString)
+
+ val xs = new java.util.ArrayList[String](); xs.add("a")
+ println(xs.toArray.deepToString)
+ }
+
+ testEquals1
+ testEquals2
+ testEquals3
+ testEquals4
+ testToString1
+ testToString2
+ testToString3
+}
diff --git a/test/files/run/t0485.check b/test/files/run/t0485.check
new file mode 100644
index 0000000000..3a462cfdc1
--- /dev/null
+++ b/test/files/run/t0485.check
@@ -0,0 +1,32 @@
+m1={(10,20), (20,30)}
+m2={(10,20)}
+m1.size > m2.size is true
+m1 equals m2 is true
+
+m1={(10,20), (20,30)}
+m2={(10,20)}
+m1.size > m2.size is true
+m1 equals m2 is true
+
+m1={(10,20), (20,30)}
+m2={(10,20)}
+m1.size > m2.size is true
+m1 equals m2 is true
+
+java.lang.CloneNotSupportedException: The underlying map doesn't implement the Cloneable interface
+
+s1=[10, 20]
+s2=[10]
+s1.size > s2 is true
+s1 equals s2 is true
+
+s1=[10, 20]
+s2=[10]
+s1.size > s2 is true
+s1 equals s2 is true
+
+s1=[10, 20]
+s2=[10]
+s1.size > s2 is true
+s1 equals s2 is true
+
diff --git a/test/files/run/t0485.scala b/test/files/run/t0485.scala
new file mode 100644
index 0000000000..9e2017aacc
--- /dev/null
+++ b/test/files/run/t0485.scala
@@ -0,0 +1,54 @@
+import scala.collection.jcl
+
+object Test extends Application {
+ testMap
+ testSet
+}
+
+object testMap {
+ def toString(m1: collection.Map[Int, Int]): String =
+ m1.toList.sort((x, y) => x < y).mkString("{", ", ", "}")
+ def test(m1: jcl.Map[Int, Int]) {
+ try {
+ m1.put(10, 20)
+ val m2 = m1.clone()
+ m1.put(20, 30)
+ println("m1="+toString(m1))
+ println("m2="+toString(m2))
+ println("m1.size > m2.size is "+ (m1.size > m2.size))
+ m1.remove((20, 30))
+ println("m1 equals m2 is "+ (m1 equals m2))
+ println()
+ }
+ catch {
+ case e: Exception =>
+ println(e); println()
+ }
+ }
+ test(new jcl.HashMap[Int, Int])
+ // Clone on IdentityHashMap of java-ibm-1.6 behaves differently than all others
+ // Therefore, for now we will not perform this test on it.
+ // test(new jcl.IdentityHashMap[Int, Int])
+ test(new jcl.LinkedHashMap[Int, Int])
+ test(new jcl.TreeMap[Int, Int])
+ test(new jcl.WeakHashMap[Int, Int])
+}
+
+object testSet {
+ def toString(s1: collection.Set[Int]): String =
+ s1.toList.sort((x, y) => x < y).mkString("[", ", ", "]")
+ def test(s1: jcl.Set[Int]) {
+ s1.add(10)
+ val s2 = s1.clone()
+ s1.add(20)
+ println("s1="+toString(s1))
+ println("s2="+toString(s2))
+ println("s1.size > s2 is "+ (s1.size > s2.size))
+ s1.remove(20)
+ println("s1 equals s2 is "+ (s1 equals s2))
+ println()
+ }
+ test(new jcl.HashSet[Int])
+ test(new jcl.LinkedHashSet[Int])
+ test(new jcl.TreeSet[Int])
+}
diff --git a/test/files/run/unittest_collection.scala b/test/files/run/unittest_collection.scala
new file mode 100644
index 0000000000..5d7ab97425
--- /dev/null
+++ b/test/files/run/unittest_collection.scala
@@ -0,0 +1,103 @@
+
+object Test {
+
+ import scala.testing.SUnit._
+ import scala.collection.mutable.{ArrayBuffer, Buffer, BufferProxy, ListBuffer}
+
+ trait BufferTest extends Assert {
+ def doTest(x:Buffer[String]) = {
+ // testing method +=
+ x += "one"
+ assertEquals("retrieving 'one'", x(0), "one")
+ assertEquals("length A ", x.length, 1)
+ x += "two"
+ assertEquals("retrieving 'two'", x(1), "two")
+ assertEquals("length B ", x.length, 2)
+
+ // testing method -= (removing last element)
+ x -= "two"
+
+ assertEquals("length C ", x.length, 1)
+
+ try { x(1); fail("no exception for removed element") }
+ catch { case i:IndexOutOfBoundsException => }
+
+ try { x.remove(1); fail("no exception for removed element") }
+ catch { case i:IndexOutOfBoundsException => }
+
+ x += "two2"
+ assertEquals("length D ", x.length, 2)
+
+ // removing first element
+ x.remove(0)
+ assertEquals("length E ", x.length, 1)
+
+ // toList
+ assertEquals("toList ", x.toList, List("two2"))
+
+ // clear
+ x.clear
+ assertEquals("length F ", x.length, 0)
+
+ // copyToBuffer
+ x += "a"
+ x += "b"
+ val dest = new ArrayBuffer[String]
+ x copyToBuffer dest
+ assertEquals("dest", List("a", "b"), dest.toList)
+ assertEquals("source", List("a", "b"), x.toList)
+ }
+ }
+
+ class TArrayBuffer extends TestCase("collection.mutable.ArrayBuffer") with Assert with BufferTest {
+
+ var x: ArrayBuffer[String] = _
+
+ override def runTest = { setUp; doTest(x); tearDown }
+
+ override def setUp = { x = new scala.collection.mutable.ArrayBuffer }
+
+ override def tearDown = { x.clear; x = null }
+ }
+
+ class TListBuffer extends TestCase("collection.mutable.ListBuffer") with Assert with BufferTest {
+
+ var x: ListBuffer[String] = _
+
+ override def runTest = { setUp; doTest(x); tearDown }
+
+ override def setUp = { x = new scala.collection.mutable.ListBuffer }
+
+ override def tearDown = { x.clear; x = null }
+
+ }
+
+ class TBufferProxy extends TestCase("collection.mutable.BufferProxy") with Assert with BufferTest {
+
+ class BBuf(z:ListBuffer[String]) extends BufferProxy[String] {
+ def self = z
+ }
+
+ var x: BufferProxy[String] = _
+
+ override def runTest = { setUp; doTest(x); tearDown }
+
+ override def setUp = { x = new BBuf(new scala.collection.mutable.ListBuffer) }
+
+ override def tearDown = { x.clear; x = null }
+
+ }
+
+ def main(args:Array[String]) = {
+ val ts = new TestSuite(
+ //new TArrayBuffer,
+ new TListBuffer//,
+ //new TBufferProxy
+ )
+ val tr = new TestResult()
+ ts.run(tr)
+ for(val failure <- tr.failures) {
+ Console.println(failure)
+ }
+ }
+}