diff --git a/ChangeLog b/ChangeLog index 3bb07ee2d0..056f30fd15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Nov 2 14:19:44 2006 Akinori MUSHA + + * lib/set.rb (Set#^): Fix XOR operation against a container that + holds duplicate values. [issue: #6444] + Thu Nov 2 10:00:06 2006 Yukihiro Matsumoto * string.c: class Symbol is no longer subclass of String. also diff --git a/lib/set.rb b/lib/set.rb index ace02e08f2..66ffc898a1 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -294,8 +294,8 @@ class Set # and the given enumerable object. (set ^ enum) is equivalent to # ((set | enum) - (set & enum)). def ^(enum) - n = dup - enum.each { |o| if n.include?(o) then n.delete(o) else n.add(o) end } + n = Set.new(enum) + each { |o| if n.include?(o) then n.delete(o) else n.add(o) end } n end @@ -1039,6 +1039,13 @@ class TC_Set < Test::Unit::TestCase assert_equal(Set[2,4], ret) end + def test_xor + set = Set[1,2,3,4] + ret = set ^ [2,4,5,5] + assert_not_same(set, ret) + assert_equal(Set[1,3,5], ret) + end + def test_eq set1 = Set[2,3,1] set2 = Set[1,2,3]