예제 #1
0
 def test_xminheap_pushpop_method_lower_priority(self):
     mh = XMinHeap({'first': 'test'})
     mh.push('first', 1)
     result = mh.pushpop('second', 2)
     self.assertEqual(len(mh), 1)
     self.assertEqual(result, 'first') # get the lowest priority item back
     result2 = mh.pop()
     self.assertEqual(result2, 'second')
예제 #2
0
 def test_xminheap_pushpop_method(self):
     mh = XMinHeap({'first': 'test'})
     mh.push('first', 2)
     result = mh.pushpop('second', 1)
     self.assertEqual(len(mh), 1)
     self.assertEqual(result, 'second') # get the lowest priority item back, even if it is the one that was just placed on queue
     result2 = mh.pop()
     self.assertEqual(result2, 'first')
예제 #3
0
 def test_xminheap_pushpop_method_lower_priority(self):
     mh = XMinHeap({'first': 'test'})
     mh.push('first', 1)
     result = mh.pushpop('second', 2)
     self.assertEqual(len(mh), 1)
     self.assertEqual(result, 'first')  # get the lowest priority item back
     result2 = mh.pop()
     self.assertEqual(result2, 'second')
예제 #4
0
 def test_xminheap_pushpop_method(self):
     mh = XMinHeap({'first': 'test'})
     mh.push('first', 2)
     result = mh.pushpop('second', 1)
     self.assertEqual(len(mh), 1)
     self.assertEqual(
         result, 'second'
     )  # get the lowest priority item back, even if it is the one that was just placed on queue
     result2 = mh.pop()
     self.assertEqual(result2, 'first')
예제 #5
0
 def test_xminheap_push_and_pop_items(self):
     mh = XMinHeap({'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, 'first')
     # 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, 'fourth')
     # pop on an empty queue returns None
     fifthpop = mh.pop()
     self.assertEqual(len(mh), 0)
     self.assertEqual(fifthpop, None)
예제 #6
0
 def test_xminheap_constructor_attributes(self):
     mh = XMinHeap({'first': 'test'})
     self.assertEqual(mh.first, 'test')
예제 #7
0
 def test_xminheap_type(self):
     mh = XMinHeap()
     self.assertTrue(type(mh) == type(XMinHeap()))
예제 #8
0
 def test_xminheap_constructor(self):
     mh = XMinHeap()
     self.assertFalse(mh)  # queue that is empty is False
     mh.push('first', 1)
     self.assertTrue(mh)  # queue that contains item is True
예제 #9
0
 def test_xminheap_push_and_pop_items(self):
     mh = XMinHeap({'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, 'first')
     # 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, 'fourth')
     # pop on an empty queue returns None
     fifthpop = mh.pop()
     self.assertEqual(len(mh), 0)
     self.assertEqual(fifthpop, None)
예제 #10
0
 def test_xminheap_constructor(self):
     mh = XMinHeap()
     self.assertFalse(mh) # queue that is empty is False
     mh.push('first', 1)
     self.assertTrue(mh) # queue that contains item is True