mongo-ruby-driver/test/bson/timestamp_test.rb

37 lines
802 B
Ruby
Raw Normal View History

require './test/bson/test_helper'
2011-03-28 18:36:49 +00:00
2011-08-08 21:54:25 +00:00
class TimestampTest < Test::Unit::TestCase
2011-03-28 18:36:49 +00:00
def test_timestamp_equality
t1 = Timestamp.new(5000, 200)
t2 = Timestamp.new(5000, 200)
assert_equal t2, t1
end
2011-07-15 15:09:16 +00:00
def test_timestamp_range
t = 1;
while(t < 1_000_000_000 ) do
ts = Timestamp.new(t, 0)
doc = {:ts => ts}
bson = BSON::BSON_CODER.serialize(doc)
assert_equal doc[:ts], BSON::BSON_CODER.deserialize(bson)['ts']
t = t * 10
end
end
2011-03-28 18:36:49 +00:00
def test_implements_array_for_backward_compatibility
silently do
ts = Timestamp.new(5000, 200)
assert_equal 200, ts[0]
assert_equal 5000, ts[1]
2011-03-28 18:36:49 +00:00
array = ts.map {|t| t }
assert_equal 2, array.length
2011-03-28 18:36:49 +00:00
assert_equal 200, array[0]
assert_equal 5000, array[1]
end
2011-03-28 18:36:49 +00:00
end
end