diff options
author | Aleksandar Prokopec <axel22@gmail.com> | 2012-06-27 13:34:49 +0200 |
---|---|---|
committer | Aleksandar Prokopec <axel22@gmail.com> | 2012-06-27 15:49:06 +0200 |
commit | 788ac7502154ca1329773ec869242df21015f5f3 (patch) | |
tree | bb330ef73645f25ce872900a8a485e066197cecf /test/files/run/t5986.scala | |
parent | 9a28ee1ffc085bc680c48b12ad632b9133adf020 (diff) | |
download | scala-788ac7502154ca1329773ec869242df21015f5f3.tar.gz scala-788ac7502154ca1329773ec869242df21015f5f3.tar.bz2 scala-788ac7502154ca1329773ec869242df21015f5f3.zip |
Fix SI-5986.
Here we had an issue that RedBlack does not work the same way
for sets - which are not supposed to replace an element if
it is the same (wrt equals) and maps - which should replace
the corresponding values.
Adding an overwrite parameter which decides whether to overwrite
added keys if they are the same in the ordering.
Fix tests.
Diffstat (limited to 'test/files/run/t5986.scala')
-rw-r--r-- | test/files/run/t5986.scala | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/files/run/t5986.scala b/test/files/run/t5986.scala new file mode 100644 index 0000000000..8cf7086f98 --- /dev/null +++ b/test/files/run/t5986.scala @@ -0,0 +1,36 @@ + + + +import scala.collection._ + + + +/** A sorted set should not replace elements when adding + * and the element already exists in the set. + */ +object Test { + + class Foo(val name: String, val n: Int) { + override def equals(obj: Any): Boolean = obj match { case other: Foo => name == other.name; case _ => false } + override def hashCode = name.## + override def toString = "Foo(" + name + ", " + n + ")" + } + + implicit val ordering: Ordering[Foo] = Ordering.fromLessThan[Foo] { (a, b) => a.name.compareTo(b.name) < 0 } + + def check[S <: Set[Foo]](set: S) { + def output(s: Set[Foo]) = println(s.toList.sorted.mkString(",")) + output(set + new Foo("bar", 2)) + output(set ++ List(new Foo("bar", 2), new Foo("bar", 3), new Foo("bar", 4))) + output(set union Set(new Foo("bar", 2), new Foo("baz", 3), new Foo("bazz", 4))) + } + + def main(args: Array[String]) { + check(Set(new Foo("bar", 1))) + check(immutable.Set(new Foo("bar", 1))) + check(mutable.Set(new Foo("bar", 1))) + check(immutable.SortedSet(new Foo("bar", 1))) + check(mutable.SortedSet(new Foo("bar", 1))) + } + +} |