class TC_UUID

Public Instance Methods

test_clock() click to toggle source
# File ../../../../../test/test_uuid.rb, line 124
def test_clock
        assert_equal 0, UUID::Nil.clock
        1000.times do |i| # clock is 14bit so 8191 suffice, but it's too slow
                u = UUID.create i
                assert_equal i, u.clock
        end
end
test_equality() click to toggle source
# File ../../../../../test/test_uuid.rb, line 132
def test_equality
        u1 = UUID.parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
        u2 = UUID.parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
        assert_equal u1.hash, u2.hash
        case u1
        when u2
                assert_equal true, true # ok
        else
                flunk "u1 != u2"
        end
end
test_pack() click to toggle source
# File ../../../../../test/test_uuid.rb, line 69
def test_pack
        u1 = UUID.pack 0x6ba7b810, 0x9dad, 0x11d1, 0x80, 0xb4,
        "\0000\3300O\33240\3310"
        assert_equal UUID::NameSpace_DNS, u1
end
test_parse() click to toggle source
# File ../../../../../test/test_uuid.rb, line 85
def test_parse
        u1 = UUID.pack 0x6ba7b810, 0x9dad, 0x11d1, 0x80, 0xb4,
        "\0000\3300O\33240\3310"
        u2 = UUID.parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
        u3 = UUID.parse "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
        assert_equal u1, u2
        assert_equal u1, u3
end
test_to_i() click to toggle source
# File ../../../../../test/test_uuid.rb, line 99
def test_to_i
        u1 = UUID.parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
        assert_equal 0x6ba7b8109dad11d180b400c04fd430c8, u1.to_i
end
test_to_s() click to toggle source
# File ../../../../../test/test_uuid.rb, line 94
def test_to_s
        u1 = UUID.parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
        assert_equal "6ba7b810-9dad-11d1-80b4-00c04fd430c8", u1.to_s
end
test_unpack() click to toggle source
# File ../../../../../test/test_uuid.rb, line 75
def test_unpack
        tl, tm, th, cl, ch, m = UUID::NameSpace_DNS.unpack
        assert_equal 0x6ba7b810, tl
        assert_equal 0x9dad, tm
        assert_equal 0x11d1, th
        assert_equal 0x80, cl
        assert_equal 0xb4, ch
        assert_equal "\0000\3300O\33240\3310", m
end
test_v1() click to toggle source
# File ../../../../../test/test_uuid.rb, line 28
def test_v1
        u1 = UUID.create
        u2 = UUID.create
        assert_not_equal u1, u2
end
test_v1_repeatability() click to toggle source
# File ../../../../../test/test_uuid.rb, line 34
def test_v1_repeatability
        u1 = UUID.create 1, 2, "345678"
        u2 = UUID.create 1, 2, "345678"
        assert_equal u1, u2
end
test_v3() click to toggle source
# File ../../../../../test/test_uuid.rb, line 40
def test_v3
        u1 = UUID.create_md5 "foo", UUID::NameSpace_DNS
        u2 = UUID.create_md5 "foo", UUID::NameSpace_DNS
        u3 = UUID.create_md5 "foo", UUID::NameSpace_URL
        assert_equal u1, u2
        assert_not_equal u1, u3
end
test_v4() click to toggle source
# File ../../../../../test/test_uuid.rb, line 56
def test_v4
        # This test  is not  perfect, because the  random nature of  version 4
        # UUID  it is  not always  true that  the three  objects  below really
        # differ.  But  in real  life it's  enough to say  we're OK  when this
        # passes.
        u1 = UUID.create_random
        u2 = UUID.create_random
        u3 = UUID.create_random
        assert_not_equal u1.raw_bytes, u2.raw_bytes
        assert_not_equal u1.raw_bytes, u3.raw_bytes
        assert_not_equal u2.raw_bytes, u3.raw_bytes
end
test_v5() click to toggle source
# File ../../../../../test/test_uuid.rb, line 48
def test_v5
        u1 = UUID.create_sha1 "foo", UUID::NameSpace_DNS
        u2 = UUID.create_sha1 "foo", UUID::NameSpace_DNS
        u3 = UUID.create_sha1 "foo", UUID::NameSpace_URL
        assert_equal u1, u2
        assert_not_equal u1, u3
end
test_version() click to toggle source

def test_time

assert_raises(RangeError) do
        UUID::Nil.time
end
0.times do |i|
        t = Time.at i, i
        u = UUID.create 0, t
        assert_equal t.tv_sec, u.time.tv_sec
        assert_equal t.tv_usec, u.time.tv_usec
end

end

# File ../../../../../test/test_uuid.rb, line 116
def test_version
        assert_equal 0, UUID::Nil.version
        assert_equal 1, UUID.create.version
        100.times do # x100 random tests may be enough?
                assert_equal 4, UUID.create_random.version
        end
end