Created
May 8, 2009 15:07
-
-
Save fearoffish/108816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Comments may or may not make sense. | |
class Array | |
def bigger?( ary ) | |
# Check that self element is greater than comparison element | |
# Uses 0 if either is nil | |
if (self[0]||0) > (ary[0]||0) | |
return true | |
else | |
# if either of them don't exist as elements, comparison is bigger | |
# so return false | |
return false unless self[0] && ary[0] | |
# Otherwise carry on and compare the next level | |
return self[1, self.size].bigger?(ary[1, ary.size]) | |
end | |
end | |
end | |
# And now so we can compare the software strings | |
def bigger_than?( str1, str2 ) | |
str1.split(".").map {|x| x.to_i }.bigger?(str2.split(".").map {|x| x.to_i }) | |
end | |
require 'test/unit' | |
class ArrayTest < Test::Unit::TestCase | |
def test_with_the_same_version_number_count_should_find_versions_with_higher_major_numbers_biggest | |
assert [3].bigger?( [2] ) | |
end | |
def test_that_minor_versions_are_irrelevant_with_higher_major_numbers | |
assert [2, 3].bigger?( [1, 4] ) | |
assert [2].bigger?( [1, 10] ) | |
end | |
def test_that_longer_version_numbers_work | |
assert [2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1].bigger?( [1, 4, 1, 1, 1, 1, 1, 1] ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment