tags:

views:

29

answers:

1

I'm trying to use the difference method (array1 - array2), and it isn't working as expected.

My unit test:

a = DeepsEdge.new(Set[1,2])
b = DeepsEdge.new(Set[3,4])
c = DeepsEdge.new(Set[3,4])
assert a != b, "these are equal and should not be"
assert_equal c, b
assert_not_equal a, b
assert_not_same c, b
x = [a,b]
y = [c]
assert_equal x, [a,c]
assert_equal y, [b]
assert b.eql?(c), 'b not eql? to c' #tests up to and including this line pass
assert_equal x-y, [a] #does not pass  

I'm not sure what is going on here. The class DeepsEdge includes comparable. I have overloaded <=> and eql?. How can I get x-y to return [a] rather than [a,c]?

+1  A: 

My guess is that while you overrode eql?, you forgot to override hash.

Jörg W Mittag
Yep. That was it.
philosodad