示例#1
0
 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))
示例#2
0
 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))
示例#3
0
 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))
示例#4
0
 def filled_heap(self):
     heap = RemovalHeap(digits + ascii_uppercase)
     for c in digits:
         heap.remove(c)
     return heap
示例#5
0
 def test_check(self):
     RemovalHeap().check()
     RemovalHeap(ascii_uppercase).check()
     RemovalHeap(reversed(ascii_uppercase)).check()
示例#6
0
 def test_init(self):
     self.assertHeap([], [], RemovalHeap())
     self.assertHeap([], [], RemovalHeap([]))
     self.assertHeap(ascii_uppercase, [], RemovalHeap(ascii_uppercase))
示例#7
0
 def filled_heap(self):
     heap = RemovalHeap(digits + ascii_uppercase)
     for c in digits:
         heap.remove(c)
     return heap
示例#8
0
 def empty_heap(self):
     return RemovalHeap()
示例#9
0
 def test_push(self):
     heap = RemovalHeap()
     for c in reversed(ascii_uppercase):
         heap.push(c)
         heap.check()
     self.assertSetEqual(set(ascii_uppercase), set(heap))
示例#10
0
 def test_peek(self):
     heap = RemovalHeap(reversed(ascii_uppercase))
     self.assertEqual('A', heap.peek())
     self.assertEqual('A', heap[0])