summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorstepancheg <stepancheg@epfl.ch>2008-06-06 19:28:49 +0000
committerstepancheg <stepancheg@epfl.ch>2008-06-06 19:28:49 +0000
commitba0e0cdbf84df51272739b9faf91b8a5961d1989 (patch)
tree0cf4ec902c26024df1452ce5bd34e2215b87d0af /test/files/run
parentc5de85e4329457b4d0b3019e0a8bb89c8132d7f1 (diff)
downloadscala-ba0e0cdbf84df51272739b9faf91b8a5961d1989.tar.gz
scala-ba0e0cdbf84df51272739b9faf91b8a5961d1989.tar.bz2
scala-ba0e0cdbf84df51272739b9faf91b8a5961d1989.zip
unify mutable and immutable stacks behavior (#957)
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/collection-stacks.check14
-rw-r--r--test/files/run/collection-stacks.scala38
2 files changed, 52 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..ec557cb91d
--- /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.push(xs: _*)
+ s
+ }
+
+ def immutableStack[T](xs: T*): immutable.Stack[T] = {
+ immutable.Stack.Empty push xs
+ }
+
+ def check[T](expected: T, got: T) {
+ println(got + ": " + (expected == got))
+ }
+
+ // check #957
+ check("1-2-3", immutableStack(1, 2, 3).elements.mkString("-"))
+ check("1-2-3", mutableStack(1, 2, 3).elements.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: