Skip to content

Commit

Permalink
Add property testing example using hypothesis library
Browse files Browse the repository at this point in the history
  • Loading branch information
lkeegan committed May 15, 2023
1 parent 7dd0c91 commit da00ca8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ tests = [
"pytest-randomly",
"pytest-qt",
"pytest-xvfb",
"ipytest"
"ipytest",
"hypothesis",
]

# Command line scripts installed as part of the installation
Expand Down
12 changes: 12 additions & 0 deletions tests/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
from effective_software_testing.board import Board
import pytest
import numpy as np
from hypothesis import given, assume, example
from hypothesis.strategies import integers

board_sizes = [1, 2, 3, 4, 5]
players = [player for player in Player]


@pytest.mark.parametrize("n", board_sizes)
@given(x=integers(0, 99), y=integers(0, 99))
@example(x=0, y=1)
def test_hypothesis_empty_board_is_empty(n: int, x: int, y: int) -> None:
assume(x < n)
assume(y < n)
board = Board(n)
assert board.square(x, y) is None


@pytest.mark.parametrize("n", board_sizes)
def test_empty_board_is_empty(n: int) -> None:
board = Board(n)
Expand Down

0 comments on commit da00ca8

Please sign in to comment.