def test_len_1(self): n1 = Node(1) s_list = LinkedList() s_list.add_in_tail(n1) data = s_list.len() res = 1 self.assertEqual(data, res)
def test_del_mass_first_1_all(self): n1 = Node(1) s_list = LinkedList() s_list.add_in_tail(n1) s_list.delete(1, True) ht = s_list.get_head_tail() data = ht + s_list.list_all_nodes() res = [None, None] self.assertEqual(data, res)
def test_clean_one(self): n1 = Node(1) s_list = LinkedList() s_list.add_in_tail(n1) s_list.clean() ht = s_list.get_head_tail() data = ht + s_list.list_all_nodes() res = [None, None] self.assertEqual(data, res)
def test_insert_end_2(self): n1 = Node(1) n2 = Node(2) s_list = LinkedList() s_list.add_in_tail(n1) s_list.insert(n1, n2) ht = s_list.get_head_tail() data = ht + s_list.list_all_nodes() res = [n1, n2, 1, 2] self.assertEqual(data, res)
def sum_list(list_1, list_2): if list_1.len() == list_2.len(): super_list = LinkedList() node_1, node_2 = list_1.head, list_2.head while node_1 != None: super_node = Node(node_1.value + node_2.value) super_list.add_in_tail(super_node) node_1 = node_1.next node_2 = node_2.next return super_list
def test_del_one_last_2(self): n1 = Node(1) n2 = Node(2) s_list = LinkedList() s_list.add_in_tail(n1) s_list.add_in_tail(n2) s_list.delete(2) ht = s_list.get_head_tail() data = ht + s_list.list_all_nodes() res = [n1, n1, 1] self.assertEqual(data, res)
def test_len_3(self): n1 = Node(1) n2 = Node(3) n3 = Node(3) s_list = LinkedList() s_list.add_in_tail(n1) s_list.add_in_tail(n2) s_list.add_in_tail(n3) data = s_list.len() res = 3 self.assertEqual(data, res)
def test_find_all_no_element(self): n1 = Node(1) n2 = Node(3) n3 = Node(3) s_list = LinkedList() s_list.add_in_tail(n1) s_list.add_in_tail(n2) s_list.add_in_tail(n3) data = s_list.find_all(2) res = [] self.assertEqual(data, res)
def test_find_all_full(self): n1 = Node(1) n2 = Node(3) n3 = Node(3) s_list = LinkedList() s_list.add_in_tail(n1) s_list.add_in_tail(n2) s_list.add_in_tail(n3) data = s_list.find_all(3) res = [n2, n3] self.assertEqual(data, res)
def test_insert_middle(self): n1 = Node(1) n2 = Node(2) n3 = Node(3) s_list = LinkedList() s_list.add_in_tail(n1) s_list.add_in_tail(n3) s_list.insert(n1, n2) ht = s_list.get_head_tail() data = ht + s_list.list_all_nodes() res = [n1, n3, 1, 2, 3] self.assertEqual(data, res)
def test_del_one_first_3(self): n1 = Node(1) n2 = Node(2) n3 = Node(3) s_list = LinkedList() s_list.add_in_tail(n1) s_list.add_in_tail(n2) s_list.add_in_tail(n3) s_list.delete(1) ht = s_list.get_head_tail() data = ht + s_list.list_all_nodes() res = [n2, n3, 2, 3] self.assertEqual(data, res)
def test_del_mass_no_element(self): n1 = Node(1) n2 = Node(1) n3 = Node(3) s_list = LinkedList() s_list.add_in_tail(n1) s_list.add_in_tail(n2) s_list.add_in_tail(n3) s_list.delete(4, True) ht = s_list.get_head_tail() data = ht + s_list.list_all_nodes() res = [n1, n3, 1, 1, 3] self.assertEqual(data, res)
from main import Node, LinkedList def sum_list(list_1, list_2): if list_1.len() == list_2.len(): super_list = LinkedList() node_1, node_2 = list_1.head, list_2.head while node_1 != None: super_node = Node(node_1.value + node_2.value) super_list.add_in_tail(super_node) node_1 = node_1.next node_2 = node_2.next return super_list n1 = Node(1) s_list = LinkedList() s_list.add_in_tail(n1) print(s_list.get_head_tail())