Sha256: b5ba8d4a1e84389279af8b1ddf6eb171608db340872c183e184740b0683450c8

Contents?: true

Size: 1.19 KB

Versions: 12

Compression:

Stored size: 1.19 KB

Contents

require 'test_helper'

class TimestampTest < Test::Unit::TestCase

  def test_timestamp_to_s
    t1 = Timestamp.new(5000, 200)
    assert_equal "seconds: 5000, increment: 200", t1.to_s
  end

  def test_timestamp_equality
    t1 = Timestamp.new(5000, 200)
    t2 = Timestamp.new(5000, 200)
    assert_equal t2, t1
  end

  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

  def test_timestamp_32bit_compatibility
    max_32bit_fixnum = (1 << 30) - 1
    test_val = max_32bit_fixnum + 10

    ts = Timestamp.new(test_val, test_val)
    doc = {:ts => ts}
    bson = BSON::BSON_CODER.serialize(doc)
    assert_equal doc[:ts], BSON::BSON_CODER.deserialize(bson)['ts']
  end

  def test_implements_array_for_backward_compatibility
    silently do
      ts = Timestamp.new(5000, 200)
      assert_equal 200, ts[0]
      assert_equal 5000, ts[1]

      array = ts.map {|t| t }
      assert_equal 2, array.length

      assert_equal 200, array[0]
      assert_equal 5000, array[1]
    end
  end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
mongo-1.8.4 test/bson/timestamp_test.rb
bson-1.8.4 test/bson/timestamp_test.rb
bson-1.8.4-java test/bson/timestamp_test.rb
mongo-1.8.4.rc0 test/bson/timestamp_test.rb
bson-1.8.4.rc0-java test/bson/timestamp_test.rb
bson-1.8.4.rc0 test/bson/timestamp_test.rb
bson-1.8.3-java test/bson/timestamp_test.rb
bson-1.8.3 test/bson/timestamp_test.rb
mongo-1.8.3 test/bson/timestamp_test.rb
bson-1.8.3.rc1-java test/bson/timestamp_test.rb
mongo-1.8.3.rc1 test/bson/timestamp_test.rb
bson-1.8.3.rc1 test/bson/timestamp_test.rb