Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ruby Set#include? strangeness
require 'minitest/autorun'
require 'set'
class Foo
def initialize(s)
@s = s
end
def ==(other)
@s == other
end
def eql?(other)
@s.eql?(other)
end
def hash
@s.hash
end
end
class TestSet < MiniTest::Unit::TestCase
def setup
@foo = Foo.new("foo")
@set = Set.new([@foo])
@hsh = { @foo => true }
end
def test_set_include_obj
assert @set.include?(@foo)
end
def test_set_include_str
assert @set.include?("foo")
end
def test_hsh_include_obj
assert @hsh.include?(@foo)
end
def test_hsh_include_str
assert @hsh.include?("foo")
end
def test_eql
assert @foo.eql?("foo")
end
def test_hash
assert @foo.hash == "foo".hash
end
end
Run options: --seed 47214
# Running:
..FF..
Finished in 0.001374s, 4366.7614 runs/s, 4366.7614 assertions/s.
1) Failure:
TestSet#test_hsh_include_str [set_test.rb:42]:
Expected false to be truthy.
2) Failure:
TestSet#test_set_include_str [set_test.rb:34]:
Expected false to be truthy.
6 runs, 6 assertions, 2 failures, 0 errors, 0 skips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment