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_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)