Exemplo n.º 1
0
def test_remove_by_value():
    sll = SLList()
    for n in range(1, 6):
        sll.append(n)
    sll.remove_by_value(3)
    assert sll.size == 4
    assert sll.to_arraylist() == [1, 2, 4, 5]
Exemplo n.º 2
0
def test_get():
    sll = SLList()
    with pytest.raises(Exception):
        sll.get(4)
    for n in range(1, 10):
        sll.append(n)
    assert sll.get(4) == 5
    assert sll.get(11) == 9
Exemplo n.º 3
0
def test_remove_by_index():
    sll = SLList()
    for i in range(10):
        sll.append(1)
    sll.remove_by_index(5)
    assert sll.size == 9
    sll.remove_by_index(20)
    assert sll.size == 8
Exemplo n.º 4
0
def test_clear():
    sll = SLList()
    for n in range(1, 10):
        sll.append(n)
    assert sll.size == 9
    assert sll.to_arraylist() != SLList().to_arraylist()
    sll.clear()
    assert sll.size == 0
    assert sll.to_arraylist() == SLList().to_arraylist()
Exemplo n.º 5
0
def test_remove_all():
    sll = SLList()
    for n in range(5):
        sll.append(3)
    for m in range(5):
        sll.append(5)
    for x in range(7):
        sll.append(3)
    sll.remove_all(3)
    assert sll.size == 5
    sll.remove_all(5)
    assert sll.size == 0
    assert not sll.remove_all(9)
Exemplo n.º 6
0
def test_is_empty():
    sll = SLList()
    assert sll.is_empty()
    sll.append(1)
    assert not sll.is_empty()
Exemplo n.º 7
0
def test_index_of():
    sll = SLList()
    for n in range(1, 10):
        sll.append(n)
    assert sll.index_of(6) == 5
    assert sll.index_of(32) == -1
Exemplo n.º 8
0
def test_append():
    sll = SLList()
    for n in range(1, 10):
        sll.append(n)
        assert sll.to_arraylist()[-1] == n
        assert sll.size == n
Exemplo n.º 9
0
def test_contains():
    sll = SLList()
    assert not sll.contains(1)
    sll.append(1)
    assert sll.contains(1)