Example #1
0
 def test_xmaxheap_pushpop_method_lower_priority(self):
     mh = XMaxHeap({'first': 'test'})
     mh.push('first', 2)
     result = mh.pushpop('second', 1)
     self.assertEqual(len(mh), 1)
     self.assertEqual(result, 'first') # get the highest priority item back
     result2 = mh.pop()
     self.assertEqual(result2, 'second')
Example #2
0
 def test_xmaxheap_pushpop_method(self):
     mh = XMaxHeap({'first': 'test'})
     mh.push('first', 1)
     result = mh.pushpop('second', 2)
     self.assertEqual(len(mh), 1)
     self.assertEqual(result, 'second') # get the highest priority item back, even if it is the one that was just placed on queue
     result2 = mh.pop()
     self.assertEqual(result2, 'first')
Example #3
0
 def test_xmaxheap_pushpop_method_lower_priority(self):
     mh = XMaxHeap({'first': 'test'})
     mh.push('first', 2)
     result = mh.pushpop('second', 1)
     self.assertEqual(len(mh), 1)
     self.assertEqual(result, 'first')  # get the highest priority item back
     result2 = mh.pop()
     self.assertEqual(result2, 'second')
Example #4
0
 def test_xmaxheap_pushpop_method(self):
     mh = XMaxHeap({'first': 'test'})
     mh.push('first', 1)
     result = mh.pushpop('second', 2)
     self.assertEqual(len(mh), 1)
     self.assertEqual(
         result, 'second'
     )  # get the highest priority item back, even if it is the one that was just placed on queue
     result2 = mh.pop()
     self.assertEqual(result2, 'first')
Example #5
0
 def test_xmaxheap_push_and_pop_items(self):
     mh = XMaxHeap({'first': 'test'})
     mh.push('first', 1)
     mh.push('second', 2)
     mh.push('third', 2)
     mh.push('fourth', 3)
     self.assertEqual(len(mh), 4)
     # pop first item off
     firstpop = mh.pop()
     self.assertEqual(len(mh), 3)
     self.assertEqual(firstpop, 'fourth')
     # pop second item off
     secondpop = mh.pop()
     self.assertEqual(len(mh), 2)
     self.assertEqual(secondpop,
                      'second')  # when matching priority, uses FIFO
     # pop third item off
     thirdpop = mh.pop()
     self.assertEqual(len(mh), 1)
     self.assertEqual(thirdpop, 'third')  # FIFO sequence
     # pop fourth and last item
     fourthpop = mh.pop()
     self.assertEqual(len(mh), 0)
     self.assertEqual(fourthpop, 'first')
     # pop on an empty queue returns None
     fifthpop = mh.pop()
     self.assertEqual(len(mh), 0)
     self.assertEqual(fifthpop, None)
Example #6
0
 def test_xmaxheap_constructor_attributes(self):
     mh = XMaxHeap({'first': 'test'})
     self.assertEqual(mh.first, 'test')
Example #7
0
 def test_xmaxheap_type(self):
     mh = XMaxHeap()
     self.assertTrue(type(mh) == type(XMaxHeap()))
Example #8
0
 def test_xmaxheap_contructor(self):
     mh = XMaxHeap()
     self.assertFalse(mh)  # queue that is empty is False
     mh.push('first', 1)
     self.assertTrue(mh)  # queue that contains item is True
Example #9
0
 def test_xmaxheap_push_and_pop_items(self):
     mh = XMaxHeap({'first': 'test'})
     mh.push('first', 1)
     mh.push('second', 2)
     mh.push('third', 2)
     mh.push('fourth', 3)
     self.assertEqual(len(mh), 4)
     # pop first item off
     firstpop = mh.pop()
     self.assertEqual(len(mh), 3)
     self.assertEqual(firstpop, 'fourth')
     # pop second item off
     secondpop = mh.pop()
     self.assertEqual(len(mh), 2)
     self.assertEqual(secondpop, 'second') # when matching priority, uses FIFO
     # pop third item off
     thirdpop = mh.pop()
     self.assertEqual(len(mh), 1)
     self.assertEqual(thirdpop, 'third')  # FIFO sequence
     # pop fourth and last item
     fourthpop = mh.pop()
     self.assertEqual(len(mh), 0)
     self.assertEqual(fourthpop, 'first')
     # pop on an empty queue returns None
     fifthpop = mh.pop()
     self.assertEqual(len(mh), 0)
     self.assertEqual(fifthpop, None)
Example #10
0
 def test_xmaxheap_contructor(self):
     mh = XMaxHeap()
     self.assertFalse(mh) # queue that is empty is False
     mh.push('first', 1)
     self.assertTrue(mh) # queue that contains item is True