mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/set.rb (Set#^): Fix XOR operation against a container that
holds duplicate values. [issue: #6444] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8368499bcc
commit
12f9e1b64d
2 changed files with 14 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Thu Nov 2 14:19:44 2006 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* 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 <matz@ruby-lang.org>
|
Thu Nov 2 10:00:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* string.c: class Symbol is no longer subclass of String. also
|
* string.c: class Symbol is no longer subclass of String. also
|
||||||
|
|
11
lib/set.rb
11
lib/set.rb
|
@ -294,8 +294,8 @@ class Set
|
||||||
# and the given enumerable object. (set ^ enum) is equivalent to
|
# and the given enumerable object. (set ^ enum) is equivalent to
|
||||||
# ((set | enum) - (set & enum)).
|
# ((set | enum) - (set & enum)).
|
||||||
def ^(enum)
|
def ^(enum)
|
||||||
n = dup
|
n = Set.new(enum)
|
||||||
enum.each { |o| if n.include?(o) then n.delete(o) else n.add(o) end }
|
each { |o| if n.include?(o) then n.delete(o) else n.add(o) end }
|
||||||
n
|
n
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1039,6 +1039,13 @@ class TC_Set < Test::Unit::TestCase
|
||||||
assert_equal(Set[2,4], ret)
|
assert_equal(Set[2,4], ret)
|
||||||
end
|
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
|
def test_eq
|
||||||
set1 = Set[2,3,1]
|
set1 = Set[2,3,1]
|
||||||
set2 = Set[1,2,3]
|
set2 = Set[1,2,3]
|
||||||
|
|
Loading…
Reference in a new issue