def setup_test_case_two(): list_one = LinkedList() list_one.push(0) list_two = LinkedList() list_two.push(0) solution = Solution() result_list = (solution.add_two_numbers(list_one, list_two)) return result_list
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_void_all(self): s_list = LinkedList() 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_void(self): s_list = LinkedList() 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_void(self): n1 = Node(1) s_list = LinkedList() s_list.insert(None, n1) ht = s_list.get_head_tail() data = ht + s_list.list_all_nodes() res = [n1, n1, 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 brute_force_reverse(self) -> LinkedList: _linked_list = LinkedList() actual_node = self.head while actual_node is not None: _linked_list.insert_start(actual_node.data) actual_node = actual_node.next_node return _linked_list
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_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_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_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_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())
# Jangan lakukan perubahan apapun pada bagian ini. # Unit test ini akan digunakan oleh dosen/asisten # sebagai acuan dalam mengoreksi # hasil pekerjaan mahasiswa. # Jika ingin mencoba menjalankan unit test ini, # tekan Ctrl+Shift+S untuk membuka terminal shell # di bagian kanan bawah layar. # Ketik perintah pytest, lalu enter. # Jika masih ada AssertionError, berarti fungsi yang # dibuat belum benar. # Jika tidak ada AssertionError dan hasil pengujian # menunjukkan 100% sukses, berarti fungsi sudah benar. from main import LinkedList, Node list1 = LinkedList(Node(1, Node(2, Node(3, Node(4, Node(5)))))) list2 = LinkedList(Node(5, Node(5, Node(5, Node(5))))) list3 = LinkedList(Node(1, Node(51, Node(5, Node(7, Node(9, Node(3))))))) list4 = LinkedList() list5 = LinkedList(Node(13)) list6 = LinkedList(Node(200)) def test_sum_odd_1(): assert list1.sum_odd() == 9 def test_sum_odd_2(): assert list2.sum_odd() == 20
def test_find_all_void(self): s_list = LinkedList() data = s_list.find_all(3) res = [] self.assertEqual(data, res)
def test_len_0(self): s_list = LinkedList() data = s_list.len() res = 0 self.assertEqual(data, res)