Exemplo n.º 1
0
def test_solution():
        import solution

        n1 = solution.ListNode(5)
        n2 = solution.ListNode(6, n1)
        n3 = solution.ListNode (4, n2)
        n4 = solution.ListNode(1, n3)
        llst = solution.LinkedList(n4)

        llst2 = solution.LinkedList(n1)

        r1 = solution.ListNode(6)
        r2 = solution.ListNode(5, r1)
        r3 = solution.ListNode(4, r2)
        r4 = solution.ListNode(1, r3)
        returnlst = solution.LinkedList(r4)

        llst.sort_ll()
        llst2.sort_ll()

        assert (llst.head.value == returnlst.head.value and
        llst.head.next.value == returnlst.head.next.value and
        llst.head.next.next.value == returnlst.head.next.next.value and
        llst.head.next.next.next.value == returnlst.head.next.next.next.value)
        
        assert (llst2.head.value == llst2.head.value and llst2.head.next == None)
Exemplo n.º 2
0
 def test_destroy(self):
     checklist = solution.LinkedList()
     checklist.add(0)
     checklist.add(1)
     checklist.add(2)
     checklist.destroy()
     self.assertTrue(checklist.empty())
Exemplo n.º 3
0
 def addAfter_and_test_delAfter(self):
     checklist = solution.LinkedList()
     checklist.add(0)
     checklist.addAfter(0, 1)
     checklist.addAfter(0)
     checklist.del_first()
     self.assertFalse(checklist.empty())
Exemplo n.º 4
0
 def test_bub_sort(self):
     checklist = solution.LinkedList()
     checklist.add(5)
     checklist.add(1)
     checklist.add(2)
     checklist.bub_sort()
     self.assertEqual(checklist.del_first(), 1, "Wrong first")
     self.assertEqual(checklist.del_first(), 2, "Wrong second")
     self.assertEqual(checklist.del_first(), 5, "Wrong last")
Exemplo n.º 5
0
 def test_addFirst_and_del_first(self):
     checklist = solution.LinkedList()
     checklist.addFirst(1)
     checklist.addFirst(2)
     checklist.addFirst(3)
     self.assertEqual(checklist.del_first(), 3)
     self.assertEqual(checklist.del_first(), 2)
     self.assertEqual(checklist.del_first(), 1)
     self.assertFalse(checklist.empty())
Exemplo n.º 6
0
import solution

n1 = solution.ListNode(5)
n2 = solution.ListNode(6, n1)
n3 = solution.ListNode (4, n2)
n4 = solution.ListNode(1, n3)
llst = solution.LinkedList(n4)

llst2 = solution.LinkedList(n1)

r1 = solution.ListNode(6)
r2 = solution.ListNode(5, r1)
r3 = solution.ListNode(4, r2)
r4 = solution.ListNode(1, r3)
returnlst = solution.LinkedList(r4)

def test_solution():
        llst.sort_ll()
        llst2.sort_ll()
        assert (llst.head.value == returnlst.head.value and
        llst.head.next.value == returnlst.head.next.value and
        llst.head.next.next.value == returnlst.head.next.next.value and
        llst.head.next.next.next.value == returnlst.head.next.next.next.value)
        assert (llst2.head.value == llst2.head.value and llst2.head.next == None)
    
Exemplo n.º 7
0
 def test_findIndexByValue(self):
     checklist = solution.LinkedList()
     checklist.add(0)
     checklist.add(1)
     checklist.add(2)
     self.assertEqual(checklist.findIndexByValue(1), 1, "wrong index")
Exemplo n.º 8
0
 def test_len_and_add(self):
     checklist = solution.LinkedList()
     checklist.add(0)
     checklist.add(1)
     checklist.add(2)
     self.assertEqual(checklist.len, 3, "Wrong lenght")