class SortedQueue_test(unittest.TestCase): def setUp(self): self.sorted_queue = SortedQueue() def test_put(self): self.sorted_queue.put('obj') self.assertEqual(self.sorted_queue.get(), 'obj') # write a test to check that the elements are really sorted in the # structure def test_queue_is_sorted(self): values = ['Purus', 'Ridiculus', 'Fermentum', 'Euismod', 'Sem', 'Purus', 'Purus', 'Sem', 'Ridiculus', 'Sem', 'Sem', 'Sem'] values_ordered = ['Fermentum', 'Euismod', 'Purus', 'Sem'] for item in values: self.sorted_queue.put(item) sorted_values = [] while True: try: sorted_values.append(self.sorted_queue.get_nowait()) except Empty: break self.assertEqual(sorted_values, values_ordered)
def setUp(self): self.sorted_queue = SortedQueue()