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))
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
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
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
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
def test_pop(): colors = SingleLinkedList() colors.push("Magenta") colors.push("Alizarin") assert colors.pop() == "Alizarin" assert colors.pop() == "Magenta" assert colors.pop() is None
def test_pop(): colors = SingleLinkedList() colors.push('magenta') colors.push('red') assert colors.pop() == 'red' assert colors.pop() == 'magenta' assert colors.pop() == None
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
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
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"
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
def test_push(): colors = SingleLinkedList() colors.push("Pthalo Blue") assert colors.count() == 1 colors.push("Ultramarine Blue") assert colors.count() == 2
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
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
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
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
def test_tail_empty_list(): list = SingleLinkedList() assert list.tail().isEmpty()
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
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]'
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'
def test_push(): colors = SingleLinkedList() colors.push('blue') assert colors.count() == 1 colors.push('red') assert colors.count() == 2
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
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
def test_tail_list(): list = SingleLinkedList() list.prepend(1).prepend(2).prepend(3) assert list.tail().head() == 2 assert list.tail().tail().head() == 1
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
def test_size(): list = SingleLinkedList() assert list.size() == 0 list.prepend(1).prepend(2).prepend(3) assert list.size() == 3
def test_prepend_list(): list = SingleLinkedList() assert list.head() is None list.prepend(1).prepend(2).prepend(3) assert list.head() == 3