Permalink
Browse files

improving the version algo

  • Loading branch information...
1 parent 8e36fe4 commit 97a78c03618661d9a7a813c6ada1dccb84f48671 reiz committed Apr 6, 2012
Showing with 18 additions and 5 deletions.
  1. +1 −1 README.markdown
  2. +1 −1 lib/naturalsorter/version.rb
  3. +4 −3 lib/versioncmp.rb
  4. +4 −0 spec/naturalsorter_spec.rb
  5. +8 −0 spec/versioncmp_spec.rb
View
@@ -49,7 +49,7 @@ Get newest.
You should add this line to your Gemfile
-`gem 'naturalsorter', '0.2.1'`
+`gem 'naturalsorter', '0.2.2'`
and run this command in your app root directory
@@ -1,3 +1,3 @@
module Naturalsorter
- VERSION = "0.2.1"
+ VERSION = "0.2.2"
end
View
@@ -35,8 +35,7 @@ def self.compare(a, b)
break if offset1 >= a.length() || offset2 >= b.length()
part1 = Versioncmp.getAPiece(offset1, a);
- part2 = Versioncmp.getAPiece(offset2, b);
-
+ part2 = Versioncmp.getAPiece(offset2, b);
offset1 += part1.length() + 1;
offset2 += part2.length() + 1;
@@ -95,7 +94,9 @@ def self.checkForRC(a, b)
return Versioncmp.getRcValue(a, b)
end
end
- return Versioncmp.compareString(big, small);
+ return 1 if a.length > b.length
+ return -1 if a.length < b.length
+ return 0
end
def self.isRc(a)
@@ -60,6 +60,10 @@
it "1.2, 1.1 is 1.1, 1.2" do
Naturalsorter::Sorter.sort_version_desc(["0.4", "0.1", "1.1", "1.2", "1.0", "1.0.RC1"]).should eql(["1.2", "1.1", "1.0", "1.0.RC1", "0.4", "0.1"])
end
+
+ it "1.2, 1.1 is 1.1, 1.2" do
+ Naturalsorter::Sorter.sort_version_desc(["0.4", "0.1", "1.1", "1.1.1", "1.2", "1.2.1", "1.0", "1.0.RC1"]).should eql(["1.2.1", "1.2", "1.1.1", "1.1", "1.0", "1.0.RC1", "0.4", "0.1"])
+ end
it "1.2, 1.1 is 1.1, 1.2" do
Naturalsorter::Sorter.sort_version(["1.1", "1.2", "1.0"]).should eql(["1.0", "1.1", "1.2"])
View
@@ -10,6 +10,14 @@
Versioncmp.compare("1.1", "1.0").should eql(1)
end
+ it "1.1.1 is bigger than 1.1" do
+ Versioncmp.compare("1.1.1", "1.1").should eql(1)
+ end
+
+ it "1.1 is smaller than 1.1.1" do
+ Versioncmp.compare("1.1", "1.1.1").should eql(-1)
+ end
+
it "equal" do
Versioncmp.compare("1.1", "1.1").should eql(0)
end

0 comments on commit 97a78c0

Please sign in to comment.