Sha256: 00d4add03e54dafee5d2cdc323d6005fe7e1dcd3504495e69ae2922e394b62c2
Contents?: true
Size: 1.93 KB
Versions: 1
Compression:
Stored size: 1.93 KB
Contents
require File.dirname(__FILE__) + '/test_helper' class Time def ==(other) # Ignore microseconds for testing. to_i == other.to_i end end class TupleTest < Test::Unit::TestCase should "dump and load arrays of simple types" do t = [1, true, :foo, "foo", -1001, false, nil, Time.now] assert_equal t, Tuple.load(Tuple.dump(t)) end should "dump and load fixnums and bignums" do t = [2**64, 2**32, 2**32 - 1, 2**31, 2**31 - 1, 1, 0] t = t + t.collect {|n| -n} assert_equal t, Tuple.load(Tuple.dump(t)) end should "convert single value into array" do assert_equal [1], Tuple.load(Tuple.dump(1)) end should "sort tuples using binary" do now = Time.now tuples = [ [1, "foo"], [1, true], [2], [1], [nil], [true], [:foo, -1], [:foo, -2**64], [:foo, 2**64], [1, "foo", 7, nil, false, true], [1, "foo", 7, nil, false, false], ["charles", "atlas"], ["charles", "atlas", "shrugged"], ["charles", "atlantic"], ["charles", "atlas jr."], ["charles", "atlas", "world's", "strongest", "man"], ["charles", "atlas", 5], [now, "foo"], [now, "bar"], [now - 24 * 60 * 60], ] expected = [ [nil], [1], [1, "foo"], [1, "foo", 7, nil, false, false], [1, "foo", 7, nil, false, true], [1, true], [2], ["charles", "atlantic"], ["charles", "atlas"], ["charles", "atlas", 5], ["charles", "atlas", "shrugged"], ["charles", "atlas", "world's", "strongest", "man"], ["charles", "atlas jr."], [:foo, -18446744073709551616], [:foo, -1], [:foo, 18446744073709551616], [now - 24 * 60 * 60], [now, "bar"], [now, "foo"], [true] ] assert_equal expected, tuples.sort_by {|t| Tuple.dump(t)} 100.times do assert_equal expected, tuples.shuffle.sort_by {|t| Tuple.dump(t)} end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ninjudd-tuple-0.0.7 | test/tuple_test.rb |