Skip to content

Commit

Permalink
Update exercises/practice/game-of-life/src/game_of_life.clj
Browse files Browse the repository at this point in the history
Co-authored-by: Anastasios Chatzialexiou <[email protected]>
  • Loading branch information
ErikSchierboom and tasxatzial committed Jan 22, 2025
1 parent a090730 commit b1e70e1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 79 deletions.
13 changes: 6 additions & 7 deletions exercises/practice/game-of-life/.meta/generator.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
(deftest tick_test_{{idx}}
(testing {{description}}
(is
(=
[{{#expected~}}
{{.}}
{{/expected}}]
(game-of-life/tick
[{{#input.matrix~}}
(= [{{#expected~}}
{{.}}
{{/input.matrix}}])))))
{{/expected}}]
(game-of-life/tick
[{{#input.matrix~}}
{{.}}
{{/input.matrix}}])))))
{{/test_cases.tick}}
4 changes: 2 additions & 2 deletions exercises/practice/game-of-life/src/game_of_life.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns game-of-life)

(defn tick
"Return the next generation of the given matrix."
[matrix]
"Returns the next generation of the cells."
[cells]
;; function body
)
132 changes: 62 additions & 70 deletions exercises/practice/game-of-life/test/game_of_life_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,101 +5,93 @@
(deftest tick_test_1
(testing "empty matrix"
(is
(=
[]
(game-of-life/tick
[])))))
(= []
(game-of-life/tick
[])))))

(deftest tick_test_2
(testing "live cells with zero live neighbors die"
(is
(=
[[0 0 0]
[0 0 0]
[0 0 0]]
(game-of-life/tick
[[0 0 0]
[0 1 0]
[0 0 0]])))))
(= [[0 0 0]
[0 0 0]
[0 0 0]]
(game-of-life/tick
[[0 0 0]
[0 1 0]
[0 0 0]])))))

(deftest tick_test_3
(testing "live cells with only one live neighbor die"
(is
(=
[[0 0 0]
[0 0 0]
[0 0 0]]
(game-of-life/tick
[[0 0 0]
[0 1 0]
[0 1 0]])))))
(= [[0 0 0]
[0 0 0]
[0 0 0]]
(game-of-life/tick
[[0 0 0]
[0 1 0]
[0 1 0]])))))

(deftest tick_test_4
(testing "live cells with two live neighbors stay alive"
(is
(=
[[0 0 0]
[1 0 1]
[0 0 0]]
(game-of-life/tick
[[1 0 1]
[1 0 1]
[1 0 1]])))))
(= [[0 0 0]
[1 0 1]
[0 0 0]]
(game-of-life/tick
[[1 0 1]
[1 0 1]
[1 0 1]])))))

(deftest tick_test_5
(testing "live cells with three live neighbors stay alive"
(is
(=
[[0 0 0]
[1 0 0]
[1 1 0]]
(game-of-life/tick
[[0 1 0]
[1 0 0]
[1 1 0]])))))
(= [[0 0 0]
[1 0 0]
[1 1 0]]
(game-of-life/tick
[[0 1 0]
[1 0 0]
[1 1 0]])))))

(deftest tick_test_6
(testing "dead cells with three live neighbors become alive"
(is
(=
[[0 0 0]
[1 1 0]
[0 0 0]]
(game-of-life/tick
[[1 1 0]
[0 0 0]
[1 0 0]])))))
(= [[0 0 0]
[1 1 0]
[0 0 0]]
(game-of-life/tick
[[1 1 0]
[0 0 0]
[1 0 0]])))))

(deftest tick_test_7
(testing "live cells with four or more neighbors die"
(is
(=
[[1 0 1]
[0 0 0]
[1 0 1]]
(game-of-life/tick
[[1 1 1]
[1 1 1]
[1 1 1]])))))
(= [[1 0 1]
[0 0 0]
[1 0 1]]
(game-of-life/tick
[[1 1 1]
[1 1 1]
[1 1 1]])))))

(deftest tick_test_8
(testing "bigger matrix"
(is
(=
[[1 1 0 1 1 0 0 0]
[0 0 0 0 0 1 1 0]
[1 0 1 1 1 1 0 1]
[1 0 0 0 0 0 0 1]
[1 1 0 0 1 0 0 1]
[1 1 0 1 0 0 0 1]
[1 0 0 0 0 0 0 0]
[0 0 0 0 0 0 1 1]]
(game-of-life/tick
[[1 1 0 1 1 0 0 0]
[1 0 1 1 0 0 0 0]
[1 1 1 0 0 1 1 1]
[0 0 0 0 0 1 1 0]
[1 0 0 0 1 1 0 0]
[1 1 0 0 0 1 1 1]
[0 0 1 0 1 0 0 1]
[1 0 0 0 0 0 1 1]])))))
(= [[1 1 0 1 1 0 0 0]
[0 0 0 0 0 1 1 0]
[1 0 1 1 1 1 0 1]
[1 0 0 0 0 0 0 1]
[1 1 0 0 1 0 0 1]
[1 1 0 1 0 0 0 1]
[1 0 0 0 0 0 0 0]
[0 0 0 0 0 0 1 1]]
(game-of-life/tick
[[1 1 0 1 1 0 0 0]
[1 0 1 1 0 0 0 0]
[1 1 1 0 0 1 1 1]
[0 0 0 0 0 1 1 0]
[1 0 0 0 1 1 0 0]
[1 1 0 0 0 1 1 1]
[0 0 1 0 1 0 0 1]
[1 0 0 0 0 0 1 1]])))))

0 comments on commit b1e70e1

Please sign in to comment.