Beispiel #1
0
    def test_node_equal(self):
        n1 = Node(1)
        n2 = Node(2)
        n1.next = n2

        n3 = Node(1)
        n4 = Node(2)
        n3.next = n4
        self.assertEqual(n1, n3)
def test_slinked_list():
    print('test list with multiple items')
    n1 = Node(1)
    n2 = Node(2)
    n3 = Node(3)
    n4 = Node(4)
    n5 = Node(5)
    n6 = Node(6)
    n7 = Node(7)
    n8 = Node(8)
    n9 = Node(9)
    sl = LinkedList()
    sl.add(n1)
    sl.add(n2)
    sl.add(n3)
    sl.add(n4)
    sl.add(n5)
    sl.add(n6)
    sl.add(n7)
    sl.add(n8)
    sl.add(n9)
    print(sl.traverse())
    reverse_rec(sl)
    print(sl.traverse())
    reverse_rec(sl)
    print(sl.traverse())
    reverse_loop(sl)
    print(sl.traverse())
    reverse_loop(sl)
    print(sl.traverse())
def test_slinked_list_single():
    print('test a single item in list')
    n1 = Node(1)
    sl = LinkedList()
    sl.add(n1)
    print(sl.traverse())
    reverse_rec(sl)
    print(sl.traverse())
    reverse_loop(sl)
    print(sl.traverse())
Beispiel #4
0
 def test_node_repr(self):
     n = Node(1)
     n2 = Node(2)
     n.next = n2
     self.assertEqual(repr(n),
                      "Node({}, {})".format(repr(n.value), repr(n.next)))
Beispiel #5
0
 def test_next(self):
     n1 = Node(1)
     n2 = Node(2)
     n1.next = n2
     self.assertIs(n1.next, n2)
Beispiel #6
0
 def test_next_set_invalid(self):
     with self.assertRaises(ValueError):
         n = Node(1)
         n.next = "Hello"
Beispiel #7
0
 def test_next_set_none(self):
     n = Node(1)
     n.next = None
     self.assertIsNone(n.next)