Ejemplo n.º 1
0
 def test_search(self):
     lst = ArrayList()
     lst.num_items = 4
     lst.arr = [1, 2, 3, 20]
     self.assertEqual(search(lst, 3), 2)
     lst.arr = [70, 28, 1, 29]
     self.assertEqual(search(lst, 29), 3)
     self.assertEqual(search(lst, 2), None)
Ejemplo n.º 2
0
 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])
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 def test_pop(self):
     lst = ArrayList()
     lst.num_items = 2
     lst.arr = [1, 2]
     lst2 = ArrayList()
     lst2.num_items = 1
     lst2.arr = [1, None]
     self.assertEqual(pop(lst, 1), (lst2, 2))
     self.assertRaises(IndexError, pop, lst, 2)
     lst.arr = [1, 2, None, None]
     lst.capacity = 4
     lst.num_items = 2
     lst2.arr = [2, None]
     lst2.num_items = 1
     lst2.capacity = 2
     self.assertEqual(pop(lst, 0)[0].arr, [2, None])
Ejemplo n.º 5
0
 def test_contains(self):
     lst = ArrayList()
     lst.num_items = 4
     lst.arr = [1, 2, 3, 4]
     self.assertTrue(contains(lst, 2))
     self.assertFalse(contains(lst, 5))
     self.assertTrue(contains(lst, 4))
Ejemplo n.º 6
0
 def test_get(self):
     lst = ArrayList()
     lst.num_items = 3
     lst.arr = [1, 2, 3]
     self.assertEqual(get(lst, 2), 3)
     self.assertEqual(get(lst, 1,), 2)
     self.assertRaises(IndexError, get, lst, 3)
Ejemplo n.º 7
0
 def test_insert(self):
     lst = ArrayList()
     self.assertEqual(insert(lst, 5, 0).arr, [5, None])
     lst.num_items = 4
     lst.capacity = 4
     lst.arr = [1, 2, 3, 4]
     self.assertEqual(insert(lst, 5, 2).arr, [1, 2, 5, 3, 4, None, None, None])
     self.assertRaises(IndexError, insert, lst, 20, 6)
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 def test_str(self):
     lst = ArrayList()
     lst.num_items = 4
     lst.arr = [1, 2, 3, 4]
     self.assertEqual(str(lst), "[1, 2, 3, 4]")
Ejemplo n.º 10
0
 def test_get(self):
     arr = ArrayList()
     arr.arr = [0, 5, 6, 9]
Ejemplo n.º 11
0
 def test_enlarge(self):
     arr = ArrayList()
     x2_arr = array_list.enlarge(arr)
     self.assertEqual(arr == x2_arr, False)
     arr.arr = [0, 5, 6, 9]
     self.assertEqual(arr.arr[2], 6)