Skip to content

Instantly share code, notes, and snippets.

@olivernn
Last active April 5, 2017 13:21
Show Gist options
  • Save olivernn/c25a76edc1b23148a3cbd062da38dd55 to your computer and use it in GitHub Desktop.
Save olivernn/c25a76edc1b23148a3cbd062da38dd55 to your computer and use it in GitHub Desktop.
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