diff --git a/pyproject.toml b/pyproject.toml index bacc0ef..2543c7a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -requires = ["hatchling"] -build-backend = "hatchling.build" +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" [project] name = "conway" @@ -19,4 +19,9 @@ classifiers = [ [project.urls] "Homepage" = "https://git.weber.codes/tom/gameoflife" -"Bug Tracker" = "https://git.weber.codes/tom/gameoflife/issues" \ No newline at end of file +"Bug Tracker" = "https://git.weber.codes/tom/gameoflife/issues" + +[tool.pytest.ini_options] +addopts = [ + "--import-mode=importlib", +] \ No newline at end of file diff --git a/src/conway/gameoflife.py b/src/conway/gameoflife.py index 67141e6..430355b 100644 --- a/src/conway/gameoflife.py +++ b/src/conway/gameoflife.py @@ -31,6 +31,7 @@ class State(object): def randomBoard(self): self.board = np.random.binomial(1, 0.5, (self.width, self.depth)) return self.board + def terminal_render(self): print("-" * (self.width + 2)) for i in self.board: @@ -89,6 +90,7 @@ class State(object): alive += 1 return alive + def get_anime(size=100, steps=100, start="random"): state = State(size, size, start) anime = PlotlyAnimation(state, steps) @@ -99,11 +101,12 @@ def main(): # state = State(20, 20, [(0, 1), (1, 2), (2, 0), (2, 1), (2, 2)]) state = State(100, 100, "random") - #animation = PltAnimation(state) - #ani = animation.animate() - #plt.show() + # animation = PltAnimation(state) + # ani = animation.animate() + # plt.show() animation = PlotlyAnimation(state, 100) animation.show() + if __name__ == "__main__": main() diff --git a/tests/test_anime.py b/tests/test_anime.py new file mode 100644 index 0000000..d72dd77 --- /dev/null +++ b/tests/test_anime.py @@ -0,0 +1,12 @@ +import pytest +import conway.anime as anime +import conway.gameoflife as gol + + +class TestPlotlyAnimation: + state = gol.State(10, 10, "random") + steps = 10 + plotly_anime = anime.PlotlyAnimation(state, steps) + def test_frame_gen(self): + assert self.plotly_anime.frames.shape == (11,10,10) + assert len(self.plotly_anime.frame_gen()) == 2 * self.steps + 1 \ No newline at end of file diff --git a/tests/test_gameoflife.py b/tests/test_gameoflife.py new file mode 100644 index 0000000..77f4270 --- /dev/null +++ b/tests/test_gameoflife.py @@ -0,0 +1,17 @@ +import pytest +import numpy as np +import conway.gameoflife as gol + + +class TestState: + def test_neighbours(self): + state = gol.State(10, 10) + n1 = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) + assert state.checkNeighbours(n1, 1, 1) == 8 + assert state.checkNeighbours(n1, 1, 1, neighbourhood="neumann") == 4 + n2 = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) + assert state.checkNeighbours(n2, 1, 1) == 0 + assert state.checkNeighbours(n2, 1, 1, neighbourhood="neumann") == 0 + n3 = np.array([[1, 0, 1], [0, 1, 0], [1, 0, 1]]) + assert state.checkNeighbours(n3, 1, 1, neighbourhood="moore") == 4 + assert state.checkNeighbours(n3, 1, 1, neighbourhood="neumann") == 0