pyproject addition and simple tests for ci
ci/woodpecker/push/woodpecker Pipeline was successful Details

master
Tom Weber 2 years ago
parent 6c34b9940f
commit b86934cf49

@ -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"
"Bug Tracker" = "https://git.weber.codes/tom/gameoflife/issues"
[tool.pytest.ini_options]
addopts = [
"--import-mode=importlib",
]

@ -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()

@ -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

@ -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
Loading…
Cancel
Save