Skip to content

Commit

Permalink
Teach version to consider dev string when comparing
Browse files Browse the repository at this point in the history
Versions now use their dev strings when comparing
themselves to another version. This is currently
just naive alphabetical order so "RC10" < "RC2"

Versions with no dev string are deemed to be more
recent than ones with dev string regardless of the 
content of the dev string.
  • Loading branch information
samaaron committed Jan 28, 2015
1 parent 085e67b commit 84fbba7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
20 changes: 15 additions & 5 deletions app/server/sonicpi/lib/sonicpi/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,24 @@ def <=>(other)
if ((other.is_a? Version) &&
(@major < other.major) or
((@major == other.major) && (@minor < other.minor)) or
((@major == other.major) && (@minor == other.minor) && (@patch < other.patch)))
-1
((@major == other.major) && (@minor == other.minor) && (@patch < other.patch)) or
if (@dev && other.dev)
((@major == other.major) && (@minor == other.minor) && (@patch == other.patch) && (@dev.to_s < other.dev.to_s))
else
((@major == other.major) && (@minor == other.minor) && (@patch == other.patch) && @dev)
end)
return -1
elsif
((other.is_a? Version) &&
(@major > other.major) or
(@major > other.major) or
((@major == other.major) && (@minor > other.minor)) or
((@major == other.major) && (@minor == other.minor) && (@patch > other.patch)))
return 1
((@major == other.major) && (@minor == other.minor) && (@patch > other.patch)) or
if (@dev && other.dev)
((@major == other.major) && (@minor == other.minor) && (@patch == other.patch) && (@dev.to_s > other.dev.to_s))
else
((@major == other.major) && (@minor == other.minor) && (@patch == other.patch) && other.dev)
end)
return 1
elsif ((other.is_a? Version) &&
(@major == other.major) &&
(@minor == other.minor) &&
Expand Down
24 changes: 24 additions & 0 deletions app/server/sonicpi/test/test_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ def test_greater_than
assert_equal(true, v1 > v2)
end

def test_greater_than_with_dev
v1 = Version.new(2, 1, 1)
v2 = Version.new(2, 1, 1, "dev")
assert_equal(true, v1 > v2)
end

def test_less_than_with_dev
v1 = Version.new(2, 1, 1, "dev")
v2 = Version.new(2, 1, 1)
assert_equal(true, v1 < v2)
end

def test_less_than_with_both_dev
v1 = Version.new(2, 1, 1, "a")
v2 = Version.new(2, 1, 1, "b")
assert_equal(true, v1 < v2)
end

def test_greater_than_with_both_dev
v1 = Version.new(2, 1, 1, "c")
v2 = Version.new(2, 1, 1, "a")
assert_equal(true, v1 > v2)
end

def test_less_than_or_equal_equality
v1 = Version.new(2, 1, 0, "RC12")
v2 = Version.new(2, 1, 0, "RC12")
Expand Down

0 comments on commit 84fbba7

Please sign in to comment.