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_shortListAscendingTrue(self): ordList = OrderedList(True) self.assertEqual(ordList.head, None) self.assertEqual(ordList.tail, None) self.assertEqual(ordList.len(), 0) ordList.add(4) self.assertEqual(ordList.head.value, 4) self.assertEqual(ordList.tail.value, 4) self.assertEqual(ordList.len(), 1) ordList.add(-1) self.assertEqual(ordList.head.value, -1) self.assertEqual(ordList.tail.value, 4) self.assertEqual(ordList.len(), 2) ordList.add(0) self.assertEqual(ordList.head.value, -1) self.assertEqual(ordList.head.next.value, 0) self.assertEqual(ordList.tail.value, 4) self.assertEqual(ordList.len(), 3) ordList.add(10) self.assertEqual(ordList.head.value, -1) self.assertEqual(ordList.tail.value, 10) self.assertEqual(ordList.tail.prev.value, 4) self.assertEqual(ordList.len(), 4)
def test_shortListAscendingFalse(self): ordList = OrderedList(False) self.assertEqual(ordList.head, None) self.assertEqual(ordList.tail, None) self.assertEqual(ordList.len(), 0) ordList.add(-10) self.assertEqual(ordList.head.value, -10) self.assertEqual(ordList.tail.value, -10) self.assertEqual(ordList.len(), 1) ordList.add(20) self.assertEqual(ordList.head.value, 20) self.assertEqual(ordList.tail.value, -10) self.assertEqual(ordList.len(), 2) ordList.add(21) self.assertEqual(ordList.head.value, 21) self.assertEqual(ordList.head.next.value, 20) self.assertEqual(ordList.tail.value, -10) self.assertEqual(ordList.tail.prev.value, 20) self.assertEqual(ordList.len(), 3) ordList.add(-2) self.assertEqual(ordList.head.value, 21) self.assertEqual(ordList.head.next.value, 20) self.assertEqual(ordList.tail.value, -10) self.assertEqual(ordList.tail.prev.value, -2) self.assertEqual(ordList.len(), 4)
def test_clean(self): orderedList = OrderedList(True) self.assertEqual(orderedList.len(), 0) orderedList.add(1) self.assertEqual(orderedList.len(), 1) orderedList.add(2) self.assertEqual(orderedList.len(), 2) orderedList.add(3) self.assertEqual(orderedList.len(), 3) orderedList.clean(True) self.assertEqual(orderedList.get_all(), []) self.assertEqual(orderedList.len(), 0) orderedList.add(10) self.assertEqual(orderedList.len(), 1) orderedList.clean(True) self.assertEqual(orderedList.len(), 0) orderedList.add(5) self.assertEqual(orderedList.len(), 1)
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_find(self): orderedList = OrderedList(True) orderedList.add(1) orderedList.add(3) orderedList.add(5) orderedList.add(7) orderedList.add(9) self.assertEqual(orderedList.get_all_values(), [1, 3, 5, 7, 9]) self.assertEqual(orderedList.len(), 5) self.assertEqual(orderedList.find(5).value, 5) self.assertEqual(orderedList.find(1).value, 1) self.assertEqual(orderedList.find(10), None) with self.assertRaises(TypeError): self.assertEqual(orderedList.find(None), None)
def test_find_desc(self): orderedList = OrderedList(False) orderedList.add(1) orderedList.add(3) orderedList.add(5) orderedList.add(7) orderedList.add(9) self.assertEqual(orderedList.get_all_values(), [9, 7, 5, 3, 1]) self.assertEqual(orderedList.len(), 5) self.assertEqual(orderedList.find(4), None) self.assertEqual(orderedList.find(0), None) self.assertEqual(orderedList.find(9).value, 9) self.assertEqual(orderedList.find(1).value, 1) with self.assertRaises(TypeError): self.assertEqual(orderedList.find(None), None)
def test_add(self): orderedList = OrderedList(True) self.assertEqual(orderedList.len(), 0) orderedList.add(5) self.assertEqual(orderedList.get_all_values(), [5]) self.assertEqual(orderedList.len(), 1) orderedList.add(5) self.assertEqual(orderedList.get_all_values(), [5, 5]) self.assertEqual(orderedList.len(), 2) orderedList.add(8) self.assertEqual(orderedList.get_all_values(), [5, 5, 8]) self.assertEqual(orderedList.len(), 3) orderedList.add(8) self.assertEqual(orderedList.get_all_values(), [5, 5, 8, 8]) self.assertEqual(orderedList.len(), 4) orderedList.clean(True) orderedList.add(5) orderedList.add(3) self.assertEqual(orderedList.get_all_values(), [3, 5]) self.assertEqual(orderedList.len(), 2) orderedList.add(1) self.assertEqual(orderedList.get_all_values(), [1, 3, 5]) self.assertEqual(orderedList.len(), 3) orderedList.add(6) self.assertEqual(orderedList.get_all_values(), [1, 3, 5, 6]) self.assertEqual(orderedList.len(), 4) orderedList.add(4) self.assertEqual(orderedList.get_all_values(), [1, 3, 4, 5, 6]) self.assertEqual(orderedList.len(), 5) orderedList.add(4) self.assertEqual(orderedList.get_all_values(), [1, 3, 4, 4, 5, 6]) self.assertEqual(orderedList.len(), 6) orderedList.add(1) self.assertEqual(orderedList.get_all_values(), [1, 1, 3, 4, 4, 5, 6]) self.assertEqual(orderedList.len(), 7) orderedList.add(6) self.assertEqual(orderedList.get_all_values(), [1, 1, 3, 4, 4, 5, 6, 6]) self.assertEqual(orderedList.len(), 8)
def test_add_desc(self): orderedList = OrderedList(False) self.assertEqual(orderedList.len(), 0) orderedList.add(5) self.assertEqual(orderedList.get_all_values(), [5]) self.assertEqual(orderedList.len(), 1) orderedList.add(5) self.assertEqual(orderedList.get_all_values(), [5, 5]) self.assertEqual(orderedList.len(), 2) orderedList.add(8) self.assertEqual(orderedList.get_all_values(), [8, 5, 5]) self.assertEqual(orderedList.len(), 3) orderedList.add(3) self.assertEqual(orderedList.get_all_values(), [8, 5, 5, 3]) self.assertEqual(orderedList.len(), 4) orderedList.add(1) self.assertEqual(orderedList.get_all_values(), [8, 5, 5, 3, 1]) self.assertEqual(orderedList.len(), 5) orderedList.add(6) self.assertEqual(orderedList.get_all_values(), [8, 6, 5, 5, 3, 1]) self.assertEqual(orderedList.len(), 6) orderedList.add(9) self.assertEqual(orderedList.get_all_values(), [9, 8, 6, 5, 5, 3, 1]) self.assertEqual(orderedList.len(), 7) orderedList.add(9) self.assertEqual(orderedList.get_all_values(), [9, 9, 8, 6, 5, 5, 3, 1]) self.assertEqual(orderedList.len(), 8) orderedList.add(1) self.assertEqual(orderedList.get_all_values(), [9, 9, 8, 6, 5, 5, 3, 1, 1]) self.assertEqual(orderedList.len(), 9)
def test_shortListFindAscendingFalse(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) findEl = ordList.find(10) self.assertEqual(findEl.value, 10) findEl = ordList.find(16) self.assertEqual(findEl.value, 16) findEl = ordList.find(-222) self.assertEqual(findEl, None) findEl = ordList.find(9999) self.assertEqual(findEl, None)
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)