def test_remove(self): lst = ArrayList() self.assertEqual(remove(lst, 0), ArrayList()) lst.arr = [1, 2, None, None] lst.capacity = 4 lst.num_items = 2 self.assertEqual(remove(lst, 2).arr, [1, None]) lst.arr = [1, 2, 3, None] lst.capacity = 4 lst.num_items = 3 self.assertEqual(remove(lst, 2).arr, [1, 3, None, None])
def test_array_list6(self): lst = ArrayList() for i in range(3): lst = array_list.insert(lst, i, i) lst2 = ArrayList() lst2.arr = [0, 1, 2, None] lst2.capacity = 4 lst2.num_items = 3 self.assertEqual(lst, lst2) lst = array_list.remove(lst, 1) self.assertEqual(lst.capacity, lst2.capacity) lst2.arr = [2, None] lst2.capacity = 2 lst2.num_items = 1 self.assertEqual(array_list.remove(lst, 0), lst2)
def test_array_list6(self): lst = ArrayList() for i in range(3): lst = array_list.insert(lst, i, i) lst2 = ArrayList() lst2.arr = [0, 1, 2, None] lst2.capacity = 4 lst2.num_items = 3 self.assertEqual(lst, lst2) lst = array_list.remove(lst, 1) self.assertEqual(lst.capacity, lst2.capacity) lst2.arr = [2, None] lst2.capacity = 2 lst2.num_items = 1 print("L1: ", lst.arr) print("L2: ", lst2.arr) # self.assertEqual(array_list.remove(lst, 0), lst2) array_list.remove(lst, 0) print("Removed 0 from list 1") print("L1: ", lst.arr) print("L2: ", lst2.arr)
def array_to_linked(list1): if list1.length > 1: value, list1 = array_list.remove(list1, 0) return Pair(value, array_to_linked(list1)) return Pair(list1.lst[0], None)