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())
Exemple #2
0
 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())
Exemple #8
0
 def test_first(self):
     test_list = List(1, 2, 3)
     self.assertEqual(str(List.get_normal_order(test_list)), "1 2 3")
Exemple #9
0
 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"
Exemple #10
0
 def test_reverse(self):
     test_list = List(1, 2, 3, 4, 5, 6)
     assert str(test_list) == "6 5 4 3 2 1"
Exemple #11
0
 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"
Exemple #12
0
 def test_fifth(self):
     test_list = List(None)
     assert str(test_list) == "None"
Exemple #13
0
 def test_forth(self):
     test_list = List()
     assert str(test_list) == ""
Exemple #14
0
 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"