From 84d9b520c2836488e4e1268ad972d232ab54b1c7 Mon Sep 17 00:00:00 2001 From: Eugene Vigdorchik Date: Wed, 22 May 2013 19:51:47 +0400 Subject: 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. --- test/files/run/list_map.scala | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 test/files/run/list_map.scala (limited to 'test/files/run') 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() + } +} -- cgit v1.2.3