-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Takes care of (literal) corner cases
- Loading branch information
Showing
2 changed files
with
29 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
class Grid: | ||
def __init__(self, size): | ||
self.diagram = [[] for i in range(0, size)] | ||
self.length = size | ||
self.diagram = [[Cell() for i in range(0, size)] for i in range(0, size)] | ||
|
||
def neighbour_coordinates(self, y_coordinate, x_coordinate): | ||
coords = [ | ||
(y_coordinate + y, x_coordinate + x) | ||
for y in range(-1, 2) | ||
for x in range(-1, 2) | ||
if (self.length > y_coordinate + y >= 0) and (self.length > x_coordinate + x >= 0) | ||
] | ||
coords.remove((y_coordinate, x_coordinate)) | ||
return coords | ||
|
||
|
||
class Cell: | ||
def __init__(self): | ||
pass | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
import pytest | ||
from game import Grid, Cell | ||
|
||
@pytest.fixture | ||
def ten_grid(): | ||
return Grid(10) | ||
|
||
class TestGrid: | ||
def test_give_size_builds_array_of_length_size(self): | ||
def test_give_size_builds_array_of_length_size(self, ten_grid): | ||
test_size = 10 | ||
test_grid = Grid(test_size) | ||
assert len(test_grid.diagram) == test_size | ||
assert len(ten_grid.diagram) == test_size | ||
|
||
def test_given_size_builds_array_of_cells(self, ten_grid): | ||
assert isinstance(ten_grid.diagram[2][4], Cell) | ||
|
||
def test_given_position_returns_correct_count_of_neighbours(self, ten_grid): | ||
assert len(ten_grid.neighbour_coordinates(1, 1)) == 8 | ||
assert len(ten_grid.neighbour_coordinates(0, 0)) == 3 | ||
assert len(ten_grid.neighbour_coordinates(9, 9)) == 3 | ||
assert len(ten_grid.neighbour_coordinates(0, 9)) == 3 | ||
assert len(ten_grid.neighbour_coordinates(9, 0)) == 3 |