Implement hash equality for Version
This commit is contained in:
parent
8f42185e18
commit
b6cbd08e93
@ -65,6 +65,20 @@ class VersionComparisonTests < Test::Unit::TestCase
|
|||||||
R14B02 R14B01 R14B R13B04 R13B03 R13B02-1}.reverse
|
R14B02 R14B01 R14B R13B04 R13B03 R13B02-1}.reverse
|
||||||
assert_equal versions, versions.sort_by { |v| version(v) }
|
assert_equal versions, versions.sort_by { |v| version(v) }
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class VersionParsingTests < Test::Unit::TestCase
|
class VersionParsingTests < Test::Unit::TestCase
|
||||||
|
|||||||
@ -189,6 +189,11 @@ class Version
|
|||||||
max = [tokens.length, other.tokens.length].max
|
max = [tokens.length, other.tokens.length].max
|
||||||
pad_to(max) <=> other.pad_to(max)
|
pad_to(max) <=> other.pad_to(max)
|
||||||
end
|
end
|
||||||
|
alias_method :eql?, :==
|
||||||
|
|
||||||
|
def hash
|
||||||
|
@version.hash
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
@version.dup
|
@version.dup
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user