def testDeleteElement(self): self.assertEquals( None, List(['pegasus', 'andromeda']).delete('andromeda').find('andromeda')) self.assertEquals(['pegasus', 'andromeda'], List().add('pegasus').add('andromeda').add( 'mars').delete('mars').values()) self.assertEquals( [], List(['pegasus', 'andromeda']).delete('pegasus').delete('andromeda').values())
def to_array(cls, stack): array = [None for _ in range(stack.max_size)] curr_node = stack.head size = 0 while size != stack.max_size: if array[size] is not None: array[size] = stack[curr_node] curr_node = List.next_index(stack, curr_node) size += 1 else: break return array
def testFindElement(self): self.assertEquals('pegasus', List('pegasus').find('pegasus').value())
def testToEmptyList(self): self.assertEquals([], List('pluton').empty().values())
def testGetListValues(self): self.assertEquals(self.testList, List(['andromeda', 'pegasus', 'olympo']).values())
def testAddItem(self): self.assertEquals( ListNode('fred').value(), List().add('fred').find('fred').value()) self.assertEquals(self.testList, List().add(self.testList).values())
def testIsEmpty(self): self.assertTrue(List().isEmpty())
def test_first(self): test_list = List(1, 2, 3) self.assertEqual(str(List.get_normal_order(test_list)), "1 2 3")
def test_second(self): test_list = List(1, 2, 3) test_list.append(4) assert str(List.get_normal_order(test_list)) == "1 2 3 4"
def test_reverse(self): test_list = List(1, 2, 3, 4, 5, 6) assert str(test_list) == "6 5 4 3 2 1"
def test_sixth(self): test_list = List(1, 2, 3) test_list += [4, 5] assert str(List.get_normal_order(test_list)) == "1 2 3 4 5"
def test_fifth(self): test_list = List(None) assert str(test_list) == "None"
def test_forth(self): test_list = List() assert str(test_list) == ""
def test_third(self): test_list = List(1, 2, 3, 4) tail_list = List(5, 6) test_list += tail_list assert str(List.get_normal_order(test_list)) == "1 2 3 4 5 6"