def test_get_index(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) self.assertEqual(llist.get_index(3), 2)
def test_append(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) self.assertEqual(str(llist), '1234')
def test_count(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) self.assertEqual(llist.count(), 4)
def test_get_node_at(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) self.assertEqual(llist.get_node_at(2).data, 3)
def test_delete_at(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.delete_at(2) self.assertEqual(str(llist), '124')
def test_Swap(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.swap(2,3) self.assertEqual(str(llist), '1324')
def test_insert_after(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.insert_after(2, 2.5) self.assertEqual(str(llist), '122.534')
def test_delete_alternate(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.delete_alternate() self.assertEqual(str(llist), '13')
def test_count_rotations(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.append(6) llist.append(7) llist.append(8) llist.append(9) llist.rotate(3) self.assertEqual(3, llist.count_rotations())
def test_sort_012_inplace(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(2) llist.append(2) llist.append(1) llist.append(1) llist.append(0) llist.append(0) llist.append(0) llist.sort_012_inplace() self.assertEqual(str(llist), '000111222')
def test_k_reverse(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.append(6) llist.append(7) llist.append(8) llist.append(9) llist.k_reverse(2) self.assertEqual(str(llist), '214365879')
def test_num_sum_list_alt(self): llist = LinkedList() llist.append(9) llist.append(9) llist.append(9) llist.append(9) llist.append(9) llistb = LinkedList() llistb.append(9) llistb.append(9) llistb.append(9) llistc = llist.num_sum_list_alt(llistb) self.assertEqual(str(llistc), '100998')
def test_count_012(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(2) llist.append(2) llist.append(1) llist.append(1) llist.append(0) llist.append(0) llist.append(0) llist.sort_0_1_2() self.assertEqual(str(llist), '000111222')
def test_segregate_even_odd(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.append(6) llist.append(7) llist.append(8) llist.append(9) llist.segregate_even_odd() self.assertEqual(str(llist), '246813579')
def test_k_reverse(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.append(6) llist.append(7) llist.append(8) llist.append(9) llist.alternate_k_reverse(3) self.assertEqual(str(llist), '321456987')
def test_num_list_sum(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llistb = LinkedList() llistb.append(4) llistb.append(5) llistb.append(9) llistb.append(2) llistb.append(3) llistb.append(1) res = llist.num_list_sum(llistb) self.assertEqual(str(res), '572331')
def test_palindrome(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(2) llist.append(1) self.assertTrue(llist.is_palindrome())
def test_occurrences(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(1) llist.append(4) llist.append(1) self.assertEqual(llist.occurrences(1), 3)
def test_print_reverse(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) self.assertEqual(llist.print_reverse(), '54321')
def test_middle(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) self.assertEqual(llist.get_middle(), 3)
def test_reverse_index(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) self.assertEqual(llist.reverse_index(4), 1)
def test_reverse(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.reverse() self.assertEqual(str(llist), '54321')
def test_detect_loop(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.head.next.next.next.next.next = llist.head self.assertTrue(llist.detect_loop())
def test_last_to_first(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.last_to_first() self.assertEqual(str(llist), '51234')
def test_clear(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.clear() self.assertIsNone(llist.head)
def test_pairwise_swap(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.append(6) llist.pairwise_swap() self.assertEqual(str(llist), '214365')
def test_rotate(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.append(6) llist.rotate(3) self.assertEqual(str(llist), '456123')
def test_build_tree_llist(self): llist = LinkedList() llist.append(10) llist.append(12) llist.append(15) llist.append(25) llist.append(30) llist.append(36) root = Node.build_tree_llist(llist.head) self.assertEqual('101225301536', root.str_pre_order()) self.assertEqual('251230103615', root.str_in_order())
def test_alternate_split(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.append(6) a, b = llist.alternate_split() self.assertEqual(str(a), '135') self.assertEqual(str(b), '246')
def test_detect_and_remove_loop(self): llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) llist.head.next.next.next.next.next = llist.head.next.next self.assertTrue(llist.detect_loop()) llist.detect_and_remove_loop() self.assertFalse(llist.detect_loop())