def test_pushpop(self): heap = RemovalHeap(reversed(ascii_uppercase)) for u, l in zip(ascii_uppercase, ascii_lowercase): popped_item = heap.pushpop(l) heap.check() self.assertEqual(u, popped_item) self.assertSetEqual(set(ascii_lowercase), set(heap))
def test_remove(self): heap = RemovalHeap(reversed(ascii_uppercase)) for c in reversed(ascii_uppercase): wanted = set(heap) wanted.remove(c) heap.remove(c) heap.check() self.assertSetEqual(wanted, set(heap)) self.assertSetEqual(set(), set(heap))
def test_pop(self): heap = RemovalHeap(reversed(ascii_uppercase)) sorted_items = [] for c in ascii_uppercase: popped_item = heap.pop() heap.check() self.assertEqual(c, popped_item) sorted_items.append(popped_item) self.assertSequenceEqual(ascii_uppercase, sorted_items) self.assertSetEqual(set(), set(heap))
def filled_heap(self): heap = RemovalHeap(digits + ascii_uppercase) for c in digits: heap.remove(c) return heap
def test_check(self): RemovalHeap().check() RemovalHeap(ascii_uppercase).check() RemovalHeap(reversed(ascii_uppercase)).check()
def test_init(self): self.assertHeap([], [], RemovalHeap()) self.assertHeap([], [], RemovalHeap([])) self.assertHeap(ascii_uppercase, [], RemovalHeap(ascii_uppercase))
def empty_heap(self): return RemovalHeap()
def test_push(self): heap = RemovalHeap() for c in reversed(ascii_uppercase): heap.push(c) heap.check() self.assertSetEqual(set(ascii_uppercase), set(heap))
def test_peek(self): heap = RemovalHeap(reversed(ascii_uppercase)) self.assertEqual('A', heap.peek()) self.assertEqual('A', heap[0])