Skip to content

Instantly share code, notes, and snippets.

@defunkt
Created October 13, 2009 18:21
Show Gist options
  • Save defunkt/209422 to your computer and use it in GitHub Desktop.
Save defunkt/209422 to your computer and use it in GitHub Desktop.
require 'version_sorter'
require 'test/unit'
class VersionSorterTest < Test::Unit::TestCase
include VersionSorter
VERSIONS = %w( 1.0.9 1.0.10 1.10.1 yui3-999 2.0 1.9.1 yui3-990 3.1.4.2 1.0.9a )
EXPECTED = %w( 1.0.9 1.0.9a 1.0.10 1.9.1 1.10.1 2.0 3.1.4.2 yui3-990 yui3-999 )
def test_sorts_verisons_correctly
assert_equal EXPECTED, sort(VERSIONS)
end
def test_reverse_sorts_verisons_correctly
assert_equal EXPECTED.reverse, rsort(VERSIONS)
end
end
require 'benchmark'
versions = IO.read('data.txt').split("\n")
count = 100
Benchmark.bm(20) do |x|
x.report("sort") { count.times { VersionSorter.sort(versions) } }
x.report("rsort") { count.times { VersionSorter.rsort(versions) } }
end
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment