def test_length(self): l1 = LinkedList() self.assertEqual(len(l1), 0) l1.append(1) l1.append(2) self.assertEqual(len(l1), 2)
def test_diff_length(self, a, b): l1 = LinkedList() l1.append(a) l2 = LinkedList() l2.prepend(a) l2.append(b) self.assertEqual(l1 == l2, False)
def test_v2_nexist(self, v1, v2, lst): l1 = LinkedList() l2 = LinkedList() for item in lst: l1.append(item) l2.append(item) l1.insert_before(v1, v2) self.assertEqual(l1 == l2, True)
def test_n_nexist(self, n, lst): l1 = LinkedList() l2 = LinkedList() for item in lst: l1.append(item) l2.append(item) l1.delete_after(n) self.assertEqual(l1 == l2, True)
def test_setable(self, idx, v, lst): l1 = LinkedList() for item in lst: l1.append(item) s = l1.size l1[idx] = v self.assertEqual(l1.size, s) self.assertEqual(l1[idx], v)
def test_empty(self): l1 = LinkedList() size1 = l1.size l2 = LinkedList() size2 = l2.size l3 = l1 + l2 self.assertEqual(l3.size, 0) self.assertEqual(l1.size, size1) self.assertEqual(l2.size, size2)
def test_delete_end(self, n, lst): l1 = LinkedList() for item in lst: l1.append(item) l1.append(n) l1.delete_after(n) self.assertEqual(l1.size == len(lst) + 1, True)
def test_n_exist(self, n, lst): l1 = LinkedList() for item in lst: l1.append(item) l1.prepend(n) l1.delete_after(n) self.assertEqual(l1.size == len(lst), True) self.assertEqual(l1[1] == lst[1], True)
def test_v2_exist(self, v1, v2, lst): l1 = LinkedList() for item in lst: l1.append(item) l1.prepend(v2) l1.insert_before(v1, v2) self.assertEqual(l1.size == len(lst) + 2, True) self.assertEqual(l1.front.value == v1, True)
def test_copy(self): l1 = LinkedList() self.assertEqual(str(l1.copy()), "I'm so empty... experiencing existential angst!!!") l1.append(1) l1.append(2) l1.append(3) c_l1 = l1.copy() self.assertEqual(c_l1 == l1, True) n = l1.front nc = c_l1.front self.assertEqual(id(n) == id(nc), False)
def test_nonEmpty(self, lst1, lst2): l1 = LinkedList() for item in lst1: l1.append(item) size1 = l1.size l2 = LinkedList() for item in lst2: l2.append(item) size2 = l2.size l3 = l1 + l2 self.assertEqual(l3.size, size1 + size2) self.assertEqual(l1.size, size1) self.assertEqual(l2.size, size2)
def test_same_length(self, a, b): l1 = LinkedList() l1.append(a) l1.prepend(b) l2 = LinkedList() l2.prepend(a) l2.append(b) l3 = LinkedList() l3.append(b) l3.prepend(a) self.assertEqual(l1 == l2, False) self.assertEqual(l2 == l3, True)
def test_empty(self): l1 = LinkedList() l1.delete_after(1) self.assertEqual(str(l1), "I'm so empty... experiencing existential angst!!!")
def test_index_error(self): l1 = LinkedList() with self.assertRaises(IndexError): l1.__setitem__(2, 0)
def test_single_node(self, a, b): l1 = LinkedList() l1.append(a) l2 = LinkedList() l2.prepend(a) l3 = LinkedList() l3.append(b) self.assertEqual(l1 == l2, True) self.assertEqual(l2 == l3, False)
def test_empty(self): l1 = LinkedList() l2 = LinkedList() self.assertEqual(l1 == l2, True)
def test_diff_type(self, a): l1 = LinkedList() l1.append(a) self.assertEqual(l1 == [a], False)
def test_empty(self): l1 = LinkedList() l1.insert_before(1, 1) self.assertEqual(str(l1), "I'm so empty... experiencing existential angst!!!")