def test_average():
    list = SingleLinkedList().append(1).append(2).append(3).append(4)
    assert average(list) == 2.5
    list2 = SingleLinkedList().prepend(5).prepend(10).prepend(50).prepend(
        100).prepend(500)
    assert average(list2) == 133.0
    assert average(list.join(list2))
Пример #2
0
 def test_pop(self):
     colors = SingleLinkedList()
     colors.push('Magenta')
     colors.push('Alizarin')
     colors.push('Blue')
     assert colors.pop() == 'Blue'
     assert colors.pop() == 'Alizarin'
     assert colors.pop() == 'Magenta'
     assert colors.pop() is None
Пример #3
0
def test_popleft():
    colors = SingleLinkedList()
    colors.push('purple')
    colors.push('green')
    colors.push('yellow')
    assert colors.popleft() == 'purple'
    assert colors.popleft() == 'green'
    assert colors.popleft() == 'yellow'
    assert colors.popleft() == None
Пример #4
0
def test_unshift():
    colors = SingleLinkedList()
    colors.push("Viridian")
    colors.push("Sap Green")
    colors.push("Van Dyke")
    assert colors.unshift() == "Viridian"
    assert colors.unshift() == "Sap Green"
    assert colors.unshift() == "Van Dyke"
    assert colors.unshift() is None
Пример #5
0
 def test_unshift(self):
     colors = SingleLinkedList()
     colors.push('Viridian')
     colors.push('Sap Green')
     colors.push('Van Dyke')
     assert colors.unshift() == 'Viridian'
     assert colors.unshift() == 'Sap Green'
     assert colors.unshift() == 'Van Dyke'
     assert colors.unshift() is None
Пример #6
0
def test_pop():
    colors = SingleLinkedList()
    colors.push("Magenta")
    colors.push("Alizarin")
    assert colors.pop() == "Alizarin"
    assert colors.pop() == "Magenta"
    assert colors.pop() is None
Пример #7
0
def test_pop():
    colors = SingleLinkedList()
    colors.push('magenta')
    colors.push('red')
    assert colors.pop() == 'red'
    assert colors.pop() == 'magenta'
    assert colors.pop() == None
Пример #8
0
    def test_shift(self):
        for i in range(0, 800):
            colors = SingleLinkedList()
            colors.shift("Cadium Orange")
            assert colors.count == 1

            colors.shift("Carbazole Violet")
            assert colors.count == 2

            assert colors.pop() == "Cadium Orange"
            assert colors.count == 1
            assert colors.pop() == "Carbazole Violet"
            assert colors.count == 0
def test_copy():
    list = SingleLinkedList()
    list.append(1).append(2).append(3)
    copy = list.copy()
    assert not copy == list
    assert copy.size() == 3
    assert copy.size() == list.size()
    assert copy.head() == 1
Пример #10
0
class Stack:
    def __init__(self):
        self.__list = SingleLinkedList()

    def isEmpty(self):
        return self.__list.isEmpty()

    def size(self):
        return self.__list.size()

    def top(self):
        return self.__list.head()

    def push(self, element):
        self.__list.prepend(element)
        return self

    def pop(self):
        element = self.top()
        self.__list = self.__list.tail()
        return element
Пример #11
0
def test_last():
    colors = SingleLinkedList()
    colors.push("Cadmium Red Light")
    assert colors.last() == "Cadmium Red Light"
    colors.push("Hansa Yellow")
    assert colors.last() == "Hansa Yellow"
    colors.shift("Pthalo Green")
    assert colors.last() == "Hansa Yellow"
Пример #12
0
def test_remove():
    colors = SingleLinkedList()
    colors.push("Cobalt")
    colors.push("Zinc White")
    colors.push("Nickle Yellow")
    colors.push("Perinone")
    assert colors.remove("Cobalt") == 0
    assert colors.remove("Perinone") == 2
    assert colors.remove("Nickle Yellow") == 1
    assert colors.remove("Zinc White") == 0
def test_remove_last():
    list = SingleLinkedList()
    list.removeLast()
    assert list.isEmpty()
    list.append(1).removeLast()
    assert list.isEmpty()
    list.prepend(3).prepend(2).prepend(1)
    assert list.size() == 3
    list.removeLast()
    assert list.head() == 1
    assert list.size() == 2
    list.removeLast().removeLast().removeLast()
    assert list.size() == 0
Пример #14
0
def test_push():
    colors = SingleLinkedList()
    colors.push("Pthalo Blue")
    assert colors.count() == 1
    colors.push("Ultramarine Blue")
    assert colors.count() == 2
Пример #15
0
def test_shift():
    colors = SingleLinkedList()
    colors.shift("Cadmium Orange")
    assert colors.count() == 1
    colors.shift("Carbazole Violet")
    assert colors.count() == 2
    assert colors.pop() == "Cadmium Orange"
    assert colors.count() == 1
    assert colors.pop() == "Carbazole Violet"
    assert colors.count() == 0
Пример #16
0
def test_remove():
    colors = SingleLinkedList()
    colors.push('red')
    colors.push('white')
    colors.push('blue')
    colors.push('yellow')
    assert colors.count() == 4

    assert colors.remove('white') == True
    assert colors.count() == 3
    assert colors.dump() == '[red, blue, yellow]'

    assert colors.remove('blue') == True
    assert colors.count() == 2

    assert colors.remove('banana') == False

    assert colors.remove('yellow') == True
    assert colors.count() == 1
Пример #17
0
 def test_push(self):
     for i in range(0, 800):
         colors = SingleLinkedList()
         colors.push('Pthalo Blue')
         assert colors.count() == 1
         colors.push('Ultramarine Bleu')
         assert colors.count() == 2
         colors.push('Magenta')
         assert colors.count() == 3
         colors.push('Green')
         assert colors.count() == 4
         colors.push('Red')
         assert colors.count() == 5
Пример #18
0
 def test_get(self):
     for i in range(0, 800):
         colors = SingleLinkedList()
         colors.push('Vermillion')
         assert colors.get(0) == 'Vermillion'
         colors.push('Sap Green')
         assert colors.get(0) == 'Vermillion'
         assert colors.get(1) == 'Sap Green'
         colors.push('Cadmium Yellow Light')
         assert colors.get(0) == 'Vermillion'
         assert colors.get(1) == 'Sap Green'
         assert colors.get(2) == 'Cadmium Yellow Light'
         assert colors.pop() == 'Cadmium Yellow Light'
         assert colors.get(0) == 'Vermillion'
         assert colors.get(1) == 'Sap Green'
         assert colors.get(2) is None
         colors.pop()
         assert colors.get(0) == 'Vermillion'
         colors.pop()
         assert colors.get(0) is None
Пример #19
0
def test_tail_empty_list():
    list = SingleLinkedList()
    assert list.tail().isEmpty()
Пример #20
0
def test_get():
    colors = SingleLinkedList()
    colors.push('red')
    assert colors.get(0) == 'red'

    colors.push('yellow')
    assert colors.get(0) == 'red'
    assert colors.get(1) == 'yellow'

    colors.push('green')
    assert colors.get(0) == 'red'
    assert colors.get(1) == 'yellow'
    assert colors.get(2) == 'green'

    colors.pop()
    assert colors.get(0) == 'red'
    assert colors.get(1) == 'yellow'
    assert colors.get(2) == None

    colors.pop()
    assert colors.get(0) == 'red'
    assert colors.get(1) == None
    assert colors.get(2) == None

    colors.pop()
    assert colors.get(0) == None
    assert colors.get(1) == None
    assert colors.get(2) == None
Пример #21
0
def test_dump():
    colors = SingleLinkedList()
    colors.push('red')
    colors.push('white')
    colors.push('blue')
    colors.push('yellow')
    assert colors.dump() == '[red, white, blue, yellow]'

    colors.remove('white')
    assert colors.dump() == '[red, blue, yellow]'

    colors.pop()
    assert colors.dump() == '[red, blue]'

    colors.popleft()
    assert colors.dump() == '[blue]'
Пример #22
0
def test_last():
    colors = SingleLinkedList()
    colors.push('red')
    assert colors.last() == 'red'

    colors.push('yellow')
    assert colors.last() == 'yellow'

    colors.push('blue')
    assert colors.last() == 'blue'
Пример #23
0
def test_push():
    colors = SingleLinkedList()
    colors.push('blue')
    assert colors.count() == 1
    colors.push('red')
    assert colors.count() == 2
Пример #24
0
def test_get():
    colors = SingleLinkedList()
    colors.push("Vermillion")
    assert colors.get(0) == "Vermillion"
    colors.push("Sap Green")
    assert colors.get(0) == "Vermillion"
    assert colors.get(1) == "Sap Green"
    colors.push("Cadmium Yellow Light")
    assert colors.get(0) == "Vermillion"
    assert colors.get(1) == "Sap Green"
    assert colors.get(2) == "Cadmium Yellow Light"
    assert colors.pop() == "Cadmium Yellow Light"
    assert colors.get(0) == "Vermillion"
    assert colors.get(1) == "Sap Green"
    assert colors.get(2) == None
    colors.pop()
    assert colors.get(0) == "Vermillion"
    colors.pop()
    assert colors.get(0) == None
Пример #25
0
 def test_remove(self):
     for i in range(0, 800):
         colors = SingleLinkedList()
         colors.push('Cobalt')
         colors.push('Zinc White')
         colors.push('Nickle Yellow')
         colors.push('Perinone')
         assert colors.remove('Nickle Yellow') == 2
         # colors.dump('before perinone')
         assert colors.remove('Perinone') == 2
         # colors.dump('after perinone')
         assert colors.remove('Zinc White') == 1
Пример #26
0
def test_tail_list():
    list = SingleLinkedList()
    list.prepend(1).prepend(2).prepend(3)
    assert list.tail().head() == 2
    assert list.tail().tail().head() == 1
Пример #27
0
 def test_last(self):
     for i in range(0, 800):
         colors = SingleLinkedList()
         colors.push('Cadmium Red Light')
         assert colors.last() == 'Cadmium Red Light'
         colors.push('Hansa Yellow')
         assert colors.last() == 'Hansa Yellow'
         colors.shift('Pthalo Green')
         assert colors.last() == 'Hansa Yellow'
def test_join():
    list = SingleLinkedList()
    list2 = SingleLinkedList()
    list.join(list2)
    assert list.isEmpty()
    list.prepend(1).prepend(2).prepend(3)
    list2.prepend(4).prepend(5).prepend(6)
    list.join(list2)
    assert list.head() == 6
    assert list.size() == 6
Пример #29
0
def test_size():
    list = SingleLinkedList()
    assert list.size() == 0
    list.prepend(1).prepend(2).prepend(3)
    assert list.size() == 3
Пример #30
0
def test_prepend_list():
    list = SingleLinkedList()
    assert list.head() is None
    list.prepend(1).prepend(2).prepend(3)
    assert list.head() == 3