Exemple #1
0
def test_tuple_score():
	pq= PriorityQueue()
	assert pq.is_empty()
	pq.push((4,0,2),ord('A'))
	(score,item ) = pq.pop()
	assert score== (4,0,2)
	assert item==ord('A')
	pq.push((1,0,2),ord('B'))
	pq.push((2,0,2),ord('C'))
	pq.push((3,0,2),ord('D'))
	pq.push((40,0,2),ord('E'))
	pq.push((0,0,2),ord('F'))
	pq.push((50,0,2),ord('G'))
	(score,item )=pq.pop()
	assert score == (50,0,2)
	assert pq.get_score_by_item(ord('E')) == (40,0,2)
	assert pq.get_score_by_item(ord('F')) == (0,0,2)
	assert pq.get_score_by_item(ord('D')) == (3,0,2)
	assert item ==ord('G')
	(score,item )=pq.pop()
	assert score == (40,0,2)
	assert item ==ord('E')
	(score,item )=pq.pop()
	assert score == (3,0,2)
	assert item ==ord('D')
	(score,item )=pq.pop()
	assert score == (2,0,2)
	assert item ==ord('C')
	pq.pop()
	pq.pop()
	assert pq.is_empty()
Exemple #2
0
def test_tuple_score():
    pq = PriorityQueue()
    assert pq.is_empty()
    pq.push((4, 0, 2), ord("A"))
    (score, item) = pq.pop()
    assert score == (4, 0, 2)
    assert item == ord("A")
    pq.push((1, 0, 2), ord("B"))
    pq.push((2, 0, 2), ord("C"))
    pq.push((3, 0, 2), ord("D"))
    pq.push((40, 0, 2), ord("E"))
    pq.push((0, 0, 2), ord("F"))
    pq.push((50, 0, 2), ord("G"))
    (score, item) = pq.pop()
    assert score == (50, 0, 2)
    assert pq.get_score_by_item(ord("E")) == (40, 0, 2)
    assert pq.get_score_by_item(ord("F")) == (0, 0, 2)
    assert pq.get_score_by_item(ord("D")) == (3, 0, 2)
    assert item == ord("G")
    (score, item) = pq.pop()
    assert score == (40, 0, 2)
    assert item == ord("E")
    (score, item) = pq.pop()
    assert score == (3, 0, 2)
    assert item == ord("D")
    (score, item) = pq.pop()
    assert score == (2, 0, 2)
    assert item == ord("C")
    pq.pop()
    pq.pop()
    assert pq.is_empty()
Exemple #3
0
def test_tuple_score_sorting():
	pq= PriorityQueue()
	pq.push((10,0,0),ord('B'))
	pq.push((10,2,6),ord('C'))
	pq.push((10,3,2),ord('D'))
	pq.push((10,4,3),ord('E'))
	pq.push((10,2,2),ord('F'))
	pq.push((10,0,2),ord('G'))
	(score,item ) = pq.pop()
	assert score== (10,4,3)
	assert item==ord('E')
	(score,item ) = pq.pop()
	assert score== (10,3,2)
	assert item==ord('D')
	(score,item ) = pq.pop()
	assert score== (10,2,6)
	assert item==ord('C')
	(score,item ) = pq.pop()
	assert score== (10,2,2)
	assert item==ord('F')
	(score,item ) = pq.pop()
	assert score== (10,0,2)
	assert item==ord('G')
	pq.push((1,10,4),ord('X'))
	pq.push((5,0,6),ord('Y'))
	pq.push((1,8,2),ord('Z'))
	pq.change_score(ord('Y'),(100,100,100))
	pq.change_score(ord('Z'),(0,0,0))
	(score,item ) = pq.pop()
	assert score== (100,100,100)
	assert item==ord('Y')
	(score,item ) = pq.pop()
	assert score== (10,0,0)
	assert item==ord('B')
	(score,item ) = pq.pop()
	assert score== (1,10,4)
	assert item==ord('X')
	(score,item ) = pq.pop()
	assert score== (0,0,0)
	assert item==ord('Z')
	assert pq.is_empty()
Exemple #4
0
def test_tuple_score_sorting():
    pq = PriorityQueue()
    pq.push((10, 0, 0), ord("B"))
    pq.push((10, 2, 6), ord("C"))
    pq.push((10, 3, 2), ord("D"))
    pq.push((10, 4, 3), ord("E"))
    pq.push((10, 2, 2), ord("F"))
    pq.push((10, 0, 2), ord("G"))
    (score, item) = pq.pop()
    assert score == (10, 4, 3)
    assert item == ord("E")
    (score, item) = pq.pop()
    assert score == (10, 3, 2)
    assert item == ord("D")
    (score, item) = pq.pop()
    assert score == (10, 2, 6)
    assert item == ord("C")
    (score, item) = pq.pop()
    assert score == (10, 2, 2)
    assert item == ord("F")
    (score, item) = pq.pop()
    assert score == (10, 0, 2)
    assert item == ord("G")
    pq.push((1, 10, 4), ord("X"))
    pq.push((5, 0, 6), ord("Y"))
    pq.push((1, 8, 2), ord("Z"))
    pq.change_score(ord("Y"), (100, 100, 100))
    pq.change_score(ord("Z"), (0, 0, 0))
    (score, item) = pq.pop()
    assert score == (100, 100, 100)
    assert item == ord("Y")
    (score, item) = pq.pop()
    assert score == (10, 0, 0)
    assert item == ord("B")
    (score, item) = pq.pop()
    assert score == (1, 10, 4)
    assert item == ord("X")
    (score, item) = pq.pop()
    assert score == (0, 0, 0)
    assert item == ord("Z")
    assert pq.is_empty()
Exemple #5
0
def test_is_empty():
	pq=PriorityQueue()
	assert pq.is_empty()
	pq.push(10,ord('A'))
	assert not pq.is_empty()
	pq.pop()
	assert pq.is_empty()
	pq.push(9,ord('B'))
	assert not pq.is_empty()
	pq.push(8,ord('C'))
	assert not pq.is_empty()
	pq.pop()
	assert not pq.is_empty()
	pq.pop()
	assert pq.is_empty()
	pq.push(7,ord('D'))
	assert not pq.is_empty()
	pq.push(6,ord('E'))
	assert not pq.is_empty()
	pq.push(5,ord('F'))
	assert not pq.is_empty()
	pq.push(4,ord('G'))
	assert not pq.is_empty()
	pq.pop()
	assert not pq.is_empty()
	pq.pop()
	assert not pq.is_empty()
	pq.pop()
	assert not pq.is_empty()
	pq.pop()
	assert pq.is_empty()
Exemple #6
0
def test_is_empty():
    pq = PriorityQueue()
    assert pq.is_empty()
    pq.push(10, ord("A"))
    assert not pq.is_empty()
    pq.pop()
    assert pq.is_empty()
    pq.push(9, ord("B"))
    assert not pq.is_empty()
    pq.push(8, ord("C"))
    assert not pq.is_empty()
    pq.pop()
    assert not pq.is_empty()
    pq.pop()
    assert pq.is_empty()
    pq.push(7, ord("D"))
    assert not pq.is_empty()
    pq.push(6, ord("E"))
    assert not pq.is_empty()
    pq.push(5, ord("F"))
    assert not pq.is_empty()
    pq.push(4, ord("G"))
    assert not pq.is_empty()
    pq.pop()
    assert not pq.is_empty()
    pq.pop()
    assert not pq.is_empty()
    pq.pop()
    assert not pq.is_empty()
    pq.pop()
    assert pq.is_empty()