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
Esempio n. 2
0
def test_permitted_overfill():
    mg = RasterModelGrid((3, 7))
    for edge in ("top", "right", "bottom"):
        mg.status_at_node[mg.nodes_at_edge(edge)] = mg.BC_NODE_IS_CLOSED
    z = mg.add_zeros("topographic__elevation", at="node", dtype=float)
    z.reshape(mg.shape)[1, 1:-1] = [1.0, 0.2, 0.1, 1.0000000000000004, 1.5]
    _ = FlowAccumulator(mg)
    lmb = LakeMapperBarnes(mg, method="Steepest")
    lmb._closed = mg.zeros("node", dtype=bool)
    lmb._closed[mg.status_at_node == mg.BC_NODE_IS_CLOSED] = True
    open = StablePriorityQueue()
    edges = np.array([7])
    for edgenode in edges:
        open.add_task(edgenode, priority=z[edgenode])
    lmb._closed[edges] = True
    while True:
        try:
            lmb._fill_one_node_to_slant(z, mg.adjacent_nodes_at_node, lmb._pit,
                                        open, lmb._closed, True)
        except KeyError:
            break
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"]))
Esempio n. 4
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_inf_load_error():
    q = StablePriorityQueue()
    with pytest.raises(ValueError):
        q.add_task(float("inf"))
def test_type_return_2():
    q = StablePriorityQueue()
    q.add_task(np.pi)
    assert np.issubdtype(q.tasks_currently_in_queue().dtype, np.floating)
def test_type_return_1():
    q = StablePriorityQueue()
    q.add_task(2, priority=2)
    q.add_task(1, priority=1)
    assert np.issubdtype(q.tasks_currently_in_queue().dtype, np.integer)