def test_add_subtract_examine():
    q = StablePriorityQueue()
    q.add_task("b", priority=2)
    q.add_task("a", priority=1)
    q.add_task(0, priority=0)
    q.add_task("c", priority=2)
    q.remove_task(0)
    assert q.pop_task() == "a"

    assert q.peek_at_task() == "b"

    assert np.all(q.tasks_currently_in_queue() == np.array(["b", "c"]))

    assert q.pop_task() == "b"

    assert np.all(q.tasks_ever_in_queue() == np.array(["b", "a", "0", "c"]))
def test_overwrite():
    q = StablePriorityQueue()
    q.add_task(0, priority=5)
    q.add_task(1, priority=1)
    q.add_task(0, priority=0)
    assert q.pop_task() == 0
    assert len(q.tasks_currently_in_queue()) == 1
示例#3
0
def test_add_subtract_examine():
    q = StablePriorityQueue()
    q.add_task('b', priority=2)
    q.add_task('a', priority=1)
    q.add_task(0, priority=0)
    q.add_task('c', priority=2)
    q.remove_task(0)
    assert q.pop_task() == 'a'

    assert q.peek_at_task() == 'b'

    assert np.all(q.tasks_currently_in_queue() == np.array(['b', 'c']))

    assert q.pop_task() == 'b'

    assert np.all(q.tasks_ever_in_queue() == np.array(['b', 'a', '0', 'c']))
def test_empty_pop():
    q = StablePriorityQueue()
    with pytest.raises(KeyError):
        q.pop_task()