Пример #1
0
def test_tick():
    vc1 = VectorClock()
    vc2 = vc1.tick(1)
    assert_not_equal(vc1[1], vc2[1])
    assert_equal(vc2[1], 1)
    assert_equal(vc2[2], 0)

    vc3 = vc2.tick(1)
    assert_equal(vc3[1], 2)
Пример #2
0
def test_equal():
    vc1 = VectorClock({1: 1, 2: 2})
    vc2 = VectorClock({1: 1, 2: 2})
    assert_equal(vc1, vc1)
    assert_equal(vc1, vc2)
    assert_equal(vc2, vc2)

    vc1 = VectorClock({1: 2})
    vc2 = VectorClock({1: 1})
    assert_not_equal(vc1, vc2)
    assert_true(vc1 != vc2)
    assert_false(vc1 == vc2)

    assert_not_equal(vc1, None)
    assert_not_equal(vc1, 1)
    assert_not_equal(vc1, {1: 2})
Пример #3
0
def test_race():
    vc1 = VectorClock({1: 1, 2: 2})
    vc2 = VectorClock({2: 2, 3: 3})
    assert_true(vc1.race(vc2))

    vc1 = VectorClock({2: 1})
    vc2 = VectorClock({2: 2})
    assert_false(vc1.race(vc2))
    assert_false(vc2.race(vc1))

    vc1 = VectorClock({2: 1})
    vc2 = VectorClock({2: 2, 3: 3})
    assert_false(vc1.race(vc2))

    vc1 = VectorClock({2: 2})
    vc2 = VectorClock({2: 2, 3: 3})
    assert_false(vc1.race(vc2))

    vc1 = VectorClock({2: 3})
    vc2 = VectorClock({2: 2, 3: 3})
    assert_true(vc1.race(vc2))

    vc1 = VectorClock({1: 1, 2: 2})
    vc2 = VectorClock({2: 3})
    assert_true(vc1.race(vc2))

    vc1 = VectorClock()
    vc2 = VectorClock({1: 1})
    assert_false(vc1.race(vc2))
    assert_false(vc2.race(vc1))

    vc1 = VectorClock()
    assert_false(vc1.race(vc1))
Пример #4
0
def test_obj():
    vc = VectorClock().tick('x')
    assert_equal(vc['x'], 1)
Пример #5
0
def test_init():
    vc = VectorClock()
    assert_equal(vc[0], 0)
    assert_equal(vc[1], 0)
    assert_equal(vc[2], 0)
Пример #6
0
def test_init_dict_negative():
    VectorClock({1: -1})
Пример #7
0
def test_init_dict_zero_ignored():
    vc = VectorClock({1: 0, 2: 1})
    assert_equal(vc, VectorClock({2: 1}))
Пример #8
0
def test_repr():
    vc = VectorClock({1: 1, 2: 2})
    assert_true('VectorClock' in repr(vc))
Пример #9
0
def test_str():
    vc = VectorClock({1: 1, 2: 2})
    assert_equal(str(vc), str({1: 1, 2: 2}))
Пример #10
0
def test_merge():
    vc1 = VectorClock({1: 1, 2: 2})
    vc2 = VectorClock()
    assert_equal(vc1.merge(vc2), vc1)

    vc1 = VectorClock({1: 1, 2: 2})
    vc2 = VectorClock({1: 1, 2: 3})
    assert_equal(vc1.merge(vc2), vc2)

    vc1 = VectorClock({1: 1, 2: 2})
    vc2 = VectorClock({2: 3, 3: 3})
    assert_equal(vc1.merge(vc2), VectorClock({1: 1, 2: 3, 3: 3}))
Пример #11
0
def test_init_dict():
    vc = VectorClock({1: 2, 2: 4, 3: 5})
    assert_equal(vc[0], 0)
    assert_equal(vc[1], 2)
    assert_equal(vc[2], 4)
    assert_equal(vc[3], 5)