Пример #1
0
def test_DynamicOneDimensionalArray():
    DODA = DynamicOneDimensionalArray
    A = DODA(int, 0)
    A.append(1)
    A.append(2)
    A.append(3)
    A.append(4)
    A.delete(0)
    A.delete(0)
    A.delete(15)
    A.delete(-1)
    A.delete(1)
    A.delete(2)
    assert A._data == [4, None, None]
    assert A.size == 3
    A.fill(4)
    assert A._data == [4, 4, 4]
    b = DynamicOneDimensionalArray(int, 0)
    b.append(1)
    b.append(2)
    b.append(3)
    b.append(4)
    b.append(5)
    assert b._data == [1, 2, 3, 4, 5, None, None]
    assert list(reversed(b)) == [5, 4, 3, 2, 1]
Пример #2
0
def test_DynamicOneDimensionalArray():
    DODA = DynamicOneDimensionalArray
    A = DODA(int, 0)
    A.append(1)
    A.append(2)
    A.append(3)
    A.append(4)
    assert str(A) == "['1', '2', '3', '4']"
    A.delete(0)
    A.delete(0)
    A.delete(15)
    A.delete(-1)
    A.delete(1)
    A.delete(2)
    assert A._data == [4, None, None]
    assert str(A) == "['4']"
    assert A.size == 3
    A.fill(4)
    assert A._data == [4, 4, 4]
    b = DynamicOneDimensionalArray(int, 0)
    b.append(1)
    b.append(2)
    b.append(3)
    b.append(4)
    b.append(5)
    assert b._data == [1, 2, 3, 4, 5, None, None]
    assert list(reversed(b)) == [5, 4, 3, 2, 1]

    A = DODA(int, 0, backend=Backend.CPP)
    A.append(1)
    A.append(2)
    A.append(3)
    A.append(4)
    assert str(A) == "['1', '2', '3', '4']"
    A.delete(0)
    A.delete(0)
    A.delete(15)
    A.delete(-1)
    A.delete(1)
    A.delete(2)
    assert [A[i] for i in range(A.size)] == [4, None, None]
    assert A.size == 3
    A.fill(4)
    assert [A[0], A[1], A[2]] == [4, 4, 4]
    b = DODA(int, 0, backend=Backend.CPP)
    b.append(1)
    b.append(2)
    b.append(3)
    b.append(4)
    b.append(5)
    assert [b[i] for i in range(b.size)] == [1, 2, 3, 4, 5, None, None]