diff options
author | stepancheg <stepancheg@epfl.ch> | 2008-06-06 19:28:49 +0000 |
---|---|---|
committer | stepancheg <stepancheg@epfl.ch> | 2008-06-06 19:28:49 +0000 |
commit | ba0e0cdbf84df51272739b9faf91b8a5961d1989 (patch) | |
tree | 0cf4ec902c26024df1452ce5bd34e2215b87d0af /test | |
parent | c5de85e4329457b4d0b3019e0a8bb89c8132d7f1 (diff) | |
download | scala-ba0e0cdbf84df51272739b9faf91b8a5961d1989.tar.gz scala-ba0e0cdbf84df51272739b9faf91b8a5961d1989.tar.bz2 scala-ba0e0cdbf84df51272739b9faf91b8a5961d1989.zip |
unify mutable and immutable stacks behavior (#957)
Diffstat (limited to 'test')
-rwxr-xr-x | test/files/jvm/serialization.check | 4 | ||||
-rw-r--r-- | test/files/run/collection-stacks.check | 14 | ||||
-rw-r--r-- | test/files/run/collection-stacks.scala | 38 |
3 files changed, 54 insertions, 2 deletions
diff --git a/test/files/jvm/serialization.check b/test/files/jvm/serialization.check index 490be43d8a..f001f54c70 100755 --- a/test/files/jvm/serialization.check +++ b/test/files/jvm/serialization.check @@ -44,8 +44,8 @@ x = Queue(a,b,c) y = Queue(a,b,c) x equals y: true - y equals x: true -x = Stack(c, b, a) -y = Stack(c, b, a) +x = Stack(a, b, c) +y = Stack(a, b, c) x equals y: true - y equals x: true x = Map(42 -> FortyTwo) 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: |