Skip to content

Commit

Permalink
More UT, covering board.py get_nbrs()
Browse files Browse the repository at this point in the history
  • Loading branch information
Lewis Gaul committed Nov 13, 2023
1 parent 86b9937 commit 3e51ac0
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/mut/core/engine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pytest

from minegauler.app.core import engine
from minegauler.app.shared.types import Difficulty, GameMode, UIMode, ReachSetting
from minegauler.app.shared.types import Difficulty, GameMode, ReachSetting, UIMode
from minegauler.app.shared.utils import GameOptsStruct

from .. import utils
Expand Down
79 changes: 75 additions & 4 deletions tests/mut/core/regular/board_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from minegauler.app.core.regular import Board, Coord
from minegauler.app.shared import utils
from minegauler.app.shared.types import CellContents
from minegauler.app.shared.types import CellContents, ReachSetting


class TestRegularBoard:
Expand Down Expand Up @@ -45,9 +45,80 @@ def test_get_nbrs(self, board):
nbrs = board.get_nbrs((1, 1), include_origin=True)
assert set(nbrs) == {
# fmt: off
(0, 0), (0, 1), (0, 2),
(1, 0), (1, 1), (1, 2),
(2, 0), (2, 1), (2, 2),
(0, 0), (1, 0), (2, 0),
(0, 1), (1, 1), (2, 1),
(0, 2), (1, 2), (2, 2),
# fmt: on
}

def test_get_nbrs_reach_short(self):
board = Board(5, 5, reach=ReachSetting.SHORT)

# Top left corner
nbrs = board.get_nbrs((0, 0))
assert set(nbrs) == {(0, 1), (1, 0)}

# Bottom right corner
nbrs = board.get_nbrs((4, 4))
assert set(nbrs) == {(3, 4), (4, 3)}

# Left edge
nbrs = board.get_nbrs((0, 1))
assert set(nbrs) == {(0, 0), (0, 2), (1, 1)}

# Middle
nbrs = board.get_nbrs((1, 1), include_origin=True)
assert set(nbrs) == {
# fmt: off
(1, 0),
(0, 1), (1, 1), (2, 1),
(1, 2),
# fmt: on
}

def test_get_nbrs_reach_long(self):
board = Board(6, 6, reach=ReachSetting.LONG)

# Far top left corner
nbrs = board.get_nbrs((0, 0))
assert set(nbrs) == {
# fmt: off
(1, 0), (2, 0),
(0, 1), (1, 1), (2, 1),
(0, 2), (1, 2), (2, 2),
# fmt: on
}

# Inner top left corner
nbrs = board.get_nbrs((1, 1))
assert set(nbrs) == {
# fmt: off
(0, 0), (1, 0), (2, 0), (3, 0),
(0, 1), (2, 1), (3, 1),
(0, 2), (1, 2), (2, 2), (3, 2),
(0, 3), (1, 3), (2, 3), (3, 3),
# fmt: on
}

# Bottom right edge
nbrs = board.get_nbrs((4, 5))
assert set(nbrs) == {
# fmt: off
(2, 3), (3, 3), (4, 3), (5, 3),
(2, 4), (3, 4), (4, 4), (5, 4),
(2, 5), (3, 5), (5, 5),
# fmt: on
}

# Middle
nbrs = board.get_nbrs((2, 2), include_origin=True)
assert set(nbrs) == {
# fmt: off
(0, 0), (1, 0), (2, 0), (3, 0), (4, 0),
(0, 1), (1, 1), (2, 1), (3, 1), (4, 1),
(0, 2), (1, 2), (2, 2), (3, 2), (4, 2),
(0, 3), (1, 3), (2, 3), (3, 3), (4, 3),
(0, 4), (1, 4), (2, 4), (3, 4), (4, 4),
# fmt: on
}

Expand Down
3 changes: 2 additions & 1 deletion tests/mut/core/regular/game_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from minegauler.app.core.regular.game import Game
from minegauler.app.core.regular.minefield import Minefield
from minegauler.app.core.regular.types import Coord
from minegauler.app.shared.types import Difficulty, GameState
from minegauler.app.shared.types import Difficulty, GameState, ReachSetting


logger = logging.getLogger(__name__)
Expand All @@ -40,6 +40,7 @@ def test_basic_create(self):
assert game.y_size == 5
assert game.mines == 6
assert game.per_cell == 1
assert game.reach is ReachSetting.NORMAL
assert game.lives == 1
assert game.first_success is False
assert game.state is GameState.READY
Expand Down

0 comments on commit 3e51ac0

Please sign in to comment.