def test_list_add(self): linked_list = LinkedList() self.assertTrue(linked_list.is_empty()) values = [1, 10, 100, 1000] for v in values: linked_list.add(v) self.assertEqual(linked_list.size(), len(values))
def test_list_search(self): linked_list = LinkedList() values = [1, 10, 100, 1000] for v in values: linked_list.add(v) self.assertTrue(linked_list.search(10)) self.assertFalse(linked_list.search(2))
def test_remove_duplicates(self): linked_list = LinkedList() values = [900, 600, 500, 500, 400, 400, 300, 200, 170, 90, 27, 1] for v in values: linked_list.add(v) linked_list.print_data() self.assertEqual(linked_list.size(), 12) remove_duplicates(linked_list.get_head()) linked_list.print_data() self.assertEqual(linked_list.size(), 10)
def test_get_node(self): linked_list = LinkedList() self.assertTrue(linked_list.is_empty()) values = [1, 10, 100, 1000] for v in values: linked_list.add(v) linked_list.print_data() value_1 = get_node(linked_list.head, 2) value_2 = get_node_improved(linked_list.head, 2) self.assertEqual(value_1, value_2) self.assertEqual(100, value_2)
def test_list_remove(self): linked_list = LinkedList() values = [1, 10, 100, 1000] for v in values: linked_list.add(v) linked_list.remove(10) self.assertEqual(linked_list.size(), len(values) - 1) linked_list.remove(2) self.assertEqual(linked_list.size(), len(values) - 1) linked_list.remove(1000) self.assertEqual(linked_list.size(), len(values) - 2)
def test_compare_lists(self): linked_list = LinkedList() linked_list1 = LinkedList() self.assertTrue(linked_list.is_empty()) self.assertTrue(linked_list1.is_empty()) values = [1, 10, 100, 1000] for v in values: linked_list.add(v) linked_list1.add(v) linked_list.print_data() linked_list1.print_data() self.assertTrue(compare_lists(linked_list.get_head(), linked_list1.get_head())) linked_list1.remove(10) self.assertFalse(compare_lists(linked_list.get_head(), linked_list1.get_head()))