-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
42 lines (31 loc) · 1.21 KB
/
test_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""This module contains tests covering utils.py not "utilities for testing"."""
import random
import pytest
from game import Game
from utils import Coordinate, Direction, PriorityQueue
@pytest.mark.parametrize(
"pair",
((x, y) for x in range(10) for y in range(10)),
)
def test_coord_tuple_equality(pair) -> None:
assert Coordinate(pair[0], pair[1]) == pair
def test_priority_queue(game: Game) -> None:
"""Test items with lowest priority are popped first."""
order = [(game, Direction.random())]
for successor in game.successors:
order.append((successor, Direction.random()))
pq = PriorityQueue()
for _ in range(25): # 25 rounds of random shuffling
assert pq.empty
state_priority_pairs = [(successor, i * 10) for i, successor in enumerate(order)]
random.shuffle(state_priority_pairs)
for item, priority in state_priority_pairs:
pq.push(item=item, priority=priority)
assert item in pq
assert pq.has_items
for item in order:
assert pq.pop() == item
assert pq.empty
@pytest.mark.parametrize("n", range(10))
def test_coord_random(n):
assert len(Coordinate.random(n=n, grid_width=5, grid_height=5)) == n