예제 #1
0
    def test_lt(self):
        a = priorityqueue.Producer(1, 1, range(100))
        b = priorityqueue.Producer(1, 10, range(100))

        # 0 0, but b has smaller item_cost
        self.assertFalse(a < b, 'b has higher priority')
        self.assertTrue(b < a, 'b has higher priority')

        # 0 0.1
        b.get()
        self.assertTrue(a < b, 'b consumed 1')
        self.assertFalse(b < a, 'b consumed 1')

        # 1 0.1
        a.get()
        self.assertFalse(a < b, 'a consumed 1')
        self.assertTrue(b < a, 'a consumed 1')

        # 1 0.2
        b.get()
        self.assertFalse(a < b, 'a b consumed 1')
        self.assertTrue(b < a, 'a b consumed 1')

        # 1 1
        for _ in range(8):
            b.get()
        self.assertFalse(a < b, 'a b consumed 1')
        self.assertTrue(b < a, 'a consume 1 b consumed 10')

        # 1 1.1
        b.get()
        self.assertTrue(a < b, 'a b consumed 1')
        self.assertFalse(b < a, 'a b consumed 1')
예제 #2
0
    def test_consumed(self):
        a = priorityqueue.Producer(1, 1, [1, 2])
        b = priorityqueue.Producer(1, 10, range(20))

        self.assertEqual(1, a.get())
        self.assertEqual(2, a.get())
        self.assertRaises(priorityqueue.Empty, a.get)

        for i in range(20):
            b.get()

        self.assertEqual(a.consumed, b.consumed)
예제 #3
0
    def test_lt_init(self):
        a = priorityqueue.Producer(1, 1, [1, 2])
        b = priorityqueue.Producer(1, 1, [1, 2])

        self.assertFalse(a < b, 'both empty')
        self.assertFalse(b < a, 'both empty')

        a.get()
        b.get()

        self.assertFalse(a < b, 'both empty')
        self.assertFalse(b < a, 'both empty')
예제 #4
0
    def test_init(self):

        cq = priorityqueue.Producer(1, 1, [])
        self.assertEqual(1, cq.priority)
        self.assertEqual(0, cq.consumed)
        self.assertEqual(priorityqueue.default_priority / cq.priority,
                         cq.item_cost)