Ejemplo n.º 1
0
def test_push_back_grow_three():
    list = ArrayList()
    data = "a" * 200
    list.push_back(data)  # grows to 128 * 2 = 256
    explen = len(pack_frame(data))
    assert (explen == list.bytesConsumed)
    assert (list.initialSize * list.growthFactor**1 == len(list.storage))
    assert (1 == list.timesGrown)

    data = "b" * 200
    list.push_back(data)  # grows to 256 * 2 = 512
    explen += len(pack_frame(data))
    assert (explen == list.bytesConsumed)
    assert (list.initialSize * list.growthFactor**2 == len(list.storage))
    assert (2 == list.timesGrown)

    data = "c" * 200
    list.push_back(data)  # grows to 512 * 2 = 1024
    explen += len(pack_frame(data))
    assert (explen == list.bytesConsumed)
    assert (list.initialSize * list.growthFactor**3 == len(list.storage))
    assert (3 == list.timesGrown)

    assert (3 == list.size())
    for i in range(explen, len(list.storage)):
        assert (0 == list.storage[i])
    assert (0 != list.storage[explen - 1])
    assert (3 == list.elementCount)
Ejemplo n.º 2
0
def test_push_back_two():
    list = ArrayList()
    data1 = "first"
    list.push_back(data1)
    explen = len(pack_frame(data1))
    data2 = "second"
    list.push_back(data2)
    explen += len(pack_frame(data2))
    assert (2 == list.size())
    assert (explen == list.bytesConsumed)
    assert (data1 == list.at(0))
    assert (data2 == list.at(1))
Ejemplo n.º 3
0
def test_pack_unpack():
    input = "input string"
    pkinput = pk.dumps(input, pk.HIGHEST_PROTOCOL)
    serialized = pack_frame(input)
    assert (0 == serialized[0])
    assert (len(pkinput) == serialized[1])
    assert (pkinput == serialized[2:len(serialized)].tobytes('C'))
    assert (input == unpack_frame(serialized))
Ejemplo n.º 4
0
def test_push_back_three():
    list = ArrayList()
    data1 = "first"
    list.push_back(data1)
    explen = len(pack_frame(data1))
    data2 = "second"
    list.push_back(data2)
    explen += len(pack_frame(data2))
    data3 = "third"
    list.push_back(data3)
    explen += len(pack_frame(data3))
    assert (3 == list.size())
    assert (explen == list.bytesConsumed)
    for i in range(explen, len(list.storage)):
        assert (0 == list.storage[i])
    assert (data1 == list.at(0))
    assert (data2 == list.at(1))
    assert (data3 == list.at(2))
Ejemplo n.º 5
0
def test_push_back_one():
    list = ArrayList()
    data = "a thing"
    list.push_back(data)
    assert (0 != len(list.storage))
    assert (ArrayList.initialSize == len(list.storage))
    assert (1 == list.size())
    assert (len(pack_frame(data)) == list.bytesConsumed)
    assert (data == list.at(0))
Ejemplo n.º 6
0
def test_push_back_grow():
    list = ArrayList()
    data = "a" * 150
    list.push_back(data)
    explen = len(pack_frame(data))
    assert (1 == list.size())
    assert (explen == list.bytesConsumed)
    assert (256 == len(list.storage))
    for i in range(explen, len(list.storage)):
        assert (0 == list.storage[i])
    assert (0 != list.storage[explen - 1])
    assert (1 == list.timesGrown)
Ejemplo n.º 7
0
def test_pack_too_big():
    input = "1" * 256
    with pytest.raises(ValueError):
        pack_frame(input)