def test_shortListAddAndDeleteAscendingTrue(self): ordList = OrderedList(True) ordList.add(0) ordList.add(10) ordList.add(4) self.assertEqual(ordList.head.value, 0) self.assertEqual(ordList.tail.value, 10) self.assertEqual(ordList.len(), 3) delEl = ordList.delete(10) self.assertEqual(ordList.head.value, 0) self.assertEqual(ordList.tail.value, 4) self.assertEqual(ordList.len(), 2) ordList.add(11) ordList.add(15) self.assertEqual(ordList.head.value, 0) self.assertEqual(ordList.tail.value, 15) self.assertEqual(ordList.len(), 4) delEl = ordList.delete(11) self.assertEqual(ordList.head.value, 0) self.assertEqual(ordList.tail.value, 15) self.assertEqual(ordList.len(), 3) ordList.add(-8) delEl = ordList.delete(15) self.assertEqual(ordList.head.value, -8) self.assertEqual(ordList.tail.value, 4) self.assertEqual(ordList.len(), 3)
def test_delete_desc(self): orderedList = OrderedList(False) orderedList.add(2) orderedList.add(4) orderedList.add(6) orderedList.add(8) orderedList.add(10) orderedList.add(10) orderedList.add(2) self.assertEqual(orderedList.get_all_values(), [10, 10, 8, 6, 4, 2, 2]) self.assertEqual(orderedList.len(), 7) orderedList.delete(1) self.assertEqual(orderedList.get_all_values(), [10, 10, 8, 6, 4, 2, 2]) self.assertEqual(orderedList.len(), 7) orderedList.delete(8) self.assertEqual(orderedList.get_all_values(), [10, 10, 6, 4, 2, 2]) self.assertEqual(orderedList.len(), 6) orderedList.delete(4) self.assertEqual(orderedList.get_all_values(), [10, 10, 6, 2, 2]) self.assertEqual(orderedList.len(), 5) orderedList.delete(2) self.assertEqual(orderedList.get_all_values(), [10, 10, 6, 2]) self.assertEqual(orderedList.len(), 4) orderedList.delete(10) self.assertEqual(orderedList.get_all_values(), [10, 6, 2]) self.assertEqual(orderedList.len(), 3) orderedList.delete(6) self.assertEqual(orderedList.get_all_values(), [10, 2]) self.assertEqual(orderedList.len(), 2)
def test_delete(self): orderedList = OrderedList(True) orderedList.add(2) orderedList.add(4) orderedList.add(6) orderedList.add(8) orderedList.add(10) orderedList.add(2) self.assertEqual(orderedList.get_all_values(), [2, 2, 4, 6, 8, 10]) self.assertEqual(orderedList.len(), 6) orderedList.delete(2) self.assertEqual(orderedList.get_all_values(), [2, 4, 6, 8, 10]) self.assertEqual(orderedList.len(), 5) orderedList.delete(10) self.assertEqual(orderedList.get_all_values(), [2, 4, 6, 8]) self.assertEqual(orderedList.len(), 4) orderedList.delete(3) self.assertEqual(orderedList.get_all_values(), [2, 4, 6, 8]) self.assertEqual(orderedList.len(), 4) orderedList.delete(6) self.assertEqual(orderedList.get_all_values(), [2, 4, 8]) self.assertEqual(orderedList.len(), 3) orderedList.delete(8) self.assertEqual(orderedList.get_all_values(), [2, 4]) self.assertEqual(orderedList.len(), 2) orderedList.add(4) self.assertEqual(orderedList.get_all_values(), [2, 4, 4]) self.assertEqual(orderedList.len(), 3) orderedList.delete(4) self.assertEqual(orderedList.get_all_values(), [2, 4]) self.assertEqual(orderedList.len(), 2)
def test_shortListDeleteAscendingFalse(self): ordList = OrderedList(False) ordList.add(0) ordList.add(10) ordList.add(4) ordList.add(-1) ordList.add(16) ordList.add(9) ordList.add(11) delEl = ordList.delete(444) self.assertEqual(delEl, False) self.assertEqual(ordList.len(), 7) delEl = ordList.delete(-1) self.assertEqual(delEl, True) self.assertEqual(ordList.head.value, 16) self.assertEqual(ordList.head.next.value, 11) self.assertEqual(ordList.tail.value, 0) self.assertEqual(ordList.tail.prev.value, 4) self.assertEqual(ordList.len(), 6) delEl = ordList.delete(16) self.assertEqual(delEl, True) self.assertEqual(ordList.head.value, 11) self.assertEqual(ordList.head.next.value, 10) self.assertEqual(ordList.tail.value, 0) self.assertEqual(ordList.tail.prev.value, 4) self.assertEqual(ordList.len(), 5) delEl = ordList.delete(9) self.assertEqual(delEl, True) self.assertEqual(ordList.head.value, 11) self.assertEqual(ordList.head.next.value, 10) self.assertEqual(ordList.tail.value, 0) self.assertEqual(ordList.tail.prev.value, 4) self.assertEqual(ordList.len(), 4) delEl = ordList.delete(10) self.assertEqual(delEl, True) self.assertEqual(ordList.head.value, 11) self.assertEqual(ordList.head.next.value, 4) self.assertEqual(ordList.tail.value, 0) self.assertEqual(ordList.tail.prev.value, 4) self.assertEqual(ordList.len(), 3) delEl = ordList.delete(11) self.assertEqual(delEl, True) self.assertEqual(ordList.head.value, 4) self.assertEqual(ordList.head.next.value, 0) self.assertEqual(ordList.tail.value, 0) self.assertEqual(ordList.tail.prev.value, 4) self.assertEqual(ordList.len(), 2) delEl = ordList.delete(4) self.assertEqual(delEl, True) self.assertEqual(ordList.head.value, 0) self.assertEqual(ordList.head.next, None) self.assertEqual(ordList.tail.value, 0) self.assertEqual(ordList.tail.prev, None) self.assertEqual(ordList.len(), 1) delEl = ordList.delete(0) self.assertEqual(delEl, True) self.assertEqual(ordList.head, None) self.assertEqual(ordList.tail, None) self.assertEqual(ordList.len(), 0)