From ba0e0cdbf84df51272739b9faf91b8a5961d1989 Mon Sep 17 00:00:00 2001 From: stepancheg Date: Fri, 6 Jun 2008 19:28:49 +0000 Subject: unify mutable and immutable stacks behavior (#957) --- test/files/jvm/serialization.check | 4 ++-- test/files/run/collection-stacks.check | 14 +++++++++++++ test/files/run/collection-stacks.scala | 38 ++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 test/files/run/collection-stacks.check create mode 100644 test/files/run/collection-stacks.scala (limited to 'test') 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: -- cgit v1.2.3