Esempio n. 1
0
 def test_pushpop(self):
     heap = XHeap(reversed(ascii_lowercase), key=self.key)
     for u, l in reversed(list(zip(ascii_uppercase, ascii_lowercase))):
         popped_item = heap.pushpop(u)
         heap.check()
         self.assertEqual(l, popped_item)
     self.assertSetEqual(set(ascii_uppercase), set(heap))
Esempio n. 2
0
 def test_remove(self):
     heap = XHeap(reversed(ascii_uppercase), key=self.key)
     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))
Esempio n. 3
0
 def test_pop(self):
     heap = XHeap(reversed(ascii_uppercase), key=self.key)
     sorted_items = []
     for c in reversed(ascii_uppercase):
         popped_item = heap.pop()
         heap.check()
         self.assertEqual(c, popped_item)
         sorted_items.append(popped_item)
     self.assertSequenceEqual(list(reversed(ascii_uppercase)), sorted_items)
     self.assertSetEqual(set(), set(heap))
Esempio n. 4
0
 def filled_heap(self):
     heap = XHeap(digits + ascii_uppercase, key=self.key)
     for c in digits:
         heap.remove(c)
     return heap
Esempio n. 5
0
 def test_check(self):
     XHeap(key=self.key).check()
     XHeap(ascii_uppercase, key=self.key).check()
     XHeap(reversed(ascii_uppercase), key=self.key).check()
Esempio n. 6
0
 def test_init(self):
     self.assertHeap([], [], XHeap(key=self.key))
     self.assertHeap([], [], XHeap([], key=self.key))
     self.assertHeap(ascii_uppercase, [], XHeap(ascii_uppercase, key=self.key))
Esempio n. 7
0
 def filled_heap(self):
     heap = XHeap(digits + ascii_uppercase, key=self.key)
     for c in digits:
         heap.remove(c)
     return heap
Esempio n. 8
0
 def empty_heap(self):
     return XHeap(key=self.key)
Esempio n. 9
0
 def test_push(self):
     heap = XHeap([], key=self.key)
     for c in reversed(ascii_uppercase):
         heap.push(c)
         heap.check()
     self.assertSetEqual(set(ascii_uppercase), set(heap))
Esempio n. 10
0
 def test_peek(self):
     heap = XHeap(reversed(ascii_uppercase), key=self.key)
     self.assertEqual('Z', heap.peek())