def test_push_and_pop(self): sut = LinkedList([1, 2]) sut.push(3) self.assertEqual(len(sut), 3) self.assertEqual(sut.pop(), 3) self.assertEqual(sut.pop(), 2) self.assertEqual(sut.pop(), 1) self.assertEqual(len(sut), 0) sut.push(4) self.assertEqual(len(sut), 1) self.assertEqual(sut.head().value(), 4)
def test_push_and_pop(self): sut = LinkedList([1, 2]) sut.push(3) self.assertEqual(len(sut), 3) self.assertEqual(sut.pop(), 3) self.assertEqual(sut.pop(), 2) self.assertEqual(sut.pop(), 1) self.assertEqual(len(sut), 0) sut.push(4) self.assertEqual(len(sut), 1) self.assertEqual(sut.head().value(), 4)
def main(): linked_list = LinkedList(['foo', 'bar']) print(list(linked_list)) linked_list.push('baz') print(list(linked_list)) for node in linked_list: print(f'node: {node}') print(list(linked_list.reversed()))
def test_pushing_to_empty_list_changes_head(self): sut = LinkedList() sut.push(5) self.assertEqual(len(sut), 1) self.assertEqual(sut.head().value(), 5)
def test_can_push_to_non_empty_list(self): sut = LinkedList([1, 2, 3]) sut.push(4) self.assertEqual(len(sut), 4)
def test_pushing_to_empty_list_changes_head(self): sut = LinkedList() sut.push(5) self.assertEqual(len(sut), 1) self.assertEqual(sut.head().value(), 5)
def test_can_push_to_non_empty_list(self): sut = LinkedList([1, 2, 3]) sut.push(4) self.assertEqual(len(sut), 4)