Commit 7322ab26 authored by Adam Blank's avatar Adam Blank
Browse files

Update test_miniproject.py

parent f6edd540
No related merge requests found
Showing with 45 additions and 0 deletions
+45 -0
from collections import Counter, defaultdict
import random
import pytest
from src.floodfill import *
NUM_ITERS: int = 100000
@pytest.mark.parametrize('n, m', [(1, 1), (5, 5), (5, 10), (10, 5)])
def test_generate_random_grid(n: int, m: int):
random.seed(1000)
d: defaultdict[tuple[int, int], Counter[str]] = defaultdict(Counter)
for _ in range(NUM_ITERS):
grid: list[list[str]] = generate_random_grid(n, m)
assert n == len(grid)
for i in range(n):
assert m == len(grid[i])
for i in range(n):
for j in range(m):
d[(i, j)][grid[i][j]] += 1
for x in d:
assert pytest.approx(
1/2, 0.01) == d[x][' '] / NUM_ITERS # type: ignore
assert pytest.approx(
1/2, 0.01) == d[x]['W'] / NUM_ITERS # type: ignore
@pytest.mark.parametrize('n, m', [(1, 1), (5, 5), (5, 10), (10, 5), (10, 10)])
def test_all_coordinates(n: int, m: int):
assert set([(x, y) for x in range(n) for y in range(m)]) == set(
all_coordinates(generate_random_grid(n, m)))
def test_find_random_empty() -> None:
grid: list[list[str]] = [[' ', 'X', ' ', ' '], ['B', 'B', ' ', 'B']]
d: Counter[tuple[int, int]] = Counter()
for _ in range(NUM_ITERS):
d[find_random_empty(grid)] += 1
for x, y in d:
assert grid[x][y] == ' '
assert pytest.approx( # type: ignore
1/4, 0.01) == d[(x, y)] / NUM_ITERS
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment