aboutsummaryrefslogtreecommitdiff
path: root/tests/run/collection-stacks.scala
blob: a41bef37ca8bd3b59768a438697903d7549d76df (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import scala.collection.{ immutable, mutable }

object Test extends dotty.runtime.LegacyApp {
  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[T] pushAll xs
  }

  def check[T](expected: T, got: T): Unit = {
    println(got + ": " + (expected == got))
  }

  // check #957
  check("3-2-1", immutableStack(1, 2, 3).iterator.mkString("-"))
  check("3-2-1", mutableStack(1, 2, 3).iterator.mkString("-"))

  println("apply")
  check(3, immutableStack(1, 2, 3).apply(0))
  check(3, mutableStack(1, 2, 3).apply(0))
  check(1, immutableStack(1, 2, 3).apply(2))
  check(1, 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("2-1", immutableStack(1, 2, 3).pop.mkString("-"))
  check(3, mutableStack(1, 2, 3).pop())
  check("2-1", { val s = mutableStack(1, 2, 3); s.pop(); s.toList.mkString("-") })
}

// vim: set ts=2 sw=2 et: