summaryrefslogtreecommitdiff
path: root/test/files/run/list_map.scala
diff options
context:
space:
mode:
authorEugene Vigdorchik <eugene.vigdorchik@gmail.com>2013-05-22 19:51:47 +0400
committerEugene Vigdorchik <eugene.vigdorchik@gmail.com>2013-05-22 21:18:07 +0400
commit84d9b520c2836488e4e1268ad972d232ab54b1c7 (patch)
tree8e390d343894fa02f06fb6cbf8955b3c72381130 /test/files/run/list_map.scala
parent085b4d9bdb7ba9f9fe00c63e998e93278a34b161 (diff)
downloadscala-84d9b520c2836488e4e1268ad972d232ab54b1c7.tar.gz
scala-84d9b520c2836488e4e1268ad972d232ab54b1c7.tar.bz2
scala-84d9b520c2836488e4e1268ad972d232ab54b1c7.zip
SI-7502 removing non-existent element from ListMap returns same map.
Current imperative version constructs a new ListMap regardless of the fact the map doesn't contain the element. Replace it with the tail-recursive variant that conserves. Also replace some usages with the invariant now held.
Diffstat (limited to 'test/files/run/list_map.scala')
-rwxr-xr-xtest/files/run/list_map.scala26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/files/run/list_map.scala b/test/files/run/list_map.scala
new file mode 100755
index 0000000000..fba3aae228
--- /dev/null
+++ b/test/files/run/list_map.scala
@@ -0,0 +1,26 @@
+import collection.immutable.ListMap
+
+object Test {
+ def testImmutableMinus() {
+ val empty = ListMap.empty[Int, Int]
+
+ val m0 = ListMap(1 -> 1, 2 -> 2)
+ val m1 = m0 - 3
+ assert (m1 eq m0)
+ val m2 = m0 - 1
+ assert (m2.size == 1)
+ val m3 = m2 - 2
+ assert (m3 eq empty)
+
+ val m4 = ListMap(1 -> 1, 2 -> 2, 3 -> 3)
+ val m5 = m4 - 1
+ assert (m5 == ListMap(2 -> 2, 3 -> 3))
+ assert (m5.toList == (2, 2)::(3, 3)::Nil)
+
+ assert ((empty - 1) eq empty)
+ }
+
+ def main(args: Array[String]) {
+ testImmutableMinus()
+ }
+}