diff options
author | Eugene Vigdorchik <eugene.vigdorchik@gmail.com> | 2013-05-22 19:51:47 +0400 |
---|---|---|
committer | Eugene Vigdorchik <eugene.vigdorchik@gmail.com> | 2013-05-22 21:18:07 +0400 |
commit | 84d9b520c2836488e4e1268ad972d232ab54b1c7 (patch) | |
tree | 8e390d343894fa02f06fb6cbf8955b3c72381130 /test | |
parent | 085b4d9bdb7ba9f9fe00c63e998e93278a34b161 (diff) | |
download | scala-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')
-rwxr-xr-x | test/files/run/list_map.scala | 26 |
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() + } +} |