Implement hash equality for Version

This commit is contained in:
Jack Nagel 2013-12-09 19:43:07 -06:00
parent 8f42185e18
commit b6cbd08e93
2 changed files with 19 additions and 0 deletions

View File

@ -65,6 +65,20 @@ class VersionComparisonTests < Test::Unit::TestCase
R14B02 R14B01 R14B R13B04 R13B03 R13B02-1}.reverse
assert_equal versions, versions.sort_by { |v| version(v) }
end
def test_hash_equality
v1 = version('0.1.0')
v2 = version('0.1.0')
v3 = version('0.1.1')
assert v1.eql?(v2)
assert v2.eql?(v1)
assert !v1.eql?(v3)
assert_equal v1.hash, v2.hash
h = { v1 => :foo }
assert_equal :foo, h[v2]
end
end
class VersionParsingTests < Test::Unit::TestCase

View File

@ -189,6 +189,11 @@ class Version
max = [tokens.length, other.tokens.length].max
pad_to(max) <=> other.pad_to(max)
end
alias_method :eql?, :==
def hash
@version.hash
end
def to_s
@version.dup