-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgameoflife-test.scm
64 lines (55 loc) · 1.9 KB
/
gameoflife-test.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(use-modules
(srfi srfi-64)
((game-of-life) #:renamer (symbol-prefix-proc 'gol:)))
(test-begin "game_logic")
;still life:
(define loaf (gol:new-instance gol:game-of-life))
(gol:send 'setgrid! loaf (list (list 0 1 1 0)
(list 1 0 0 1)
(list 0 1 0 1)
(list 0 0 1 0)))
(gol:send 'step! loaf)
(test-equal "loaf at t = 1"
(gol:send 'getgrid loaf)
(list (list 0 1 1 0)
(list 1 0 0 1)
(list 0 1 0 1)
(list 0 0 1 0)))
;oscillator:
(define toad (gol:new-instance gol:game-of-life))
(gol:send 'setgrid! toad (list (list 0 0 1 0)
(list 1 0 0 1)
(list 1 0 0 1)
(list 0 1 0 0)))
(gol:send 'step! toad)
(test-equal "toad at t = 1"
(gol:send 'getgrid toad)
(list (list 0 0 0 0)
(list 0 1 1 1)
(list 1 1 1 0)
(list 0 0 0 0)))
(gol:send 'step! toad)
(test-equal "toad at t = 2"
(gol:send 'getgrid toad)
(list (list 0 0 1 0)
(list 1 0 0 1)
(list 1 0 0 1)
(list 0 1 0 0)))
(test-end "game_logic")
(test-begin "utility_functions")
;pretty printing
(define loaf-grid (list (list 0 1 1 0)
(list 1 0 0 1)
(list 0 1 0 1)
(list 0 0 1 0)))
(test-equal "pretty print works with custom dead/alive chars"
(gol:pretty-print-grid loaf-grid #\x #\o)
"oxxo\nxoox\noxox\nooxo")
;loading from file
(define basic-grid (gol:grid-from-file "datasets/3x3.txt"))
(test-equal "loading a grid from file works"
basic-grid
(list (list 0 0 1)
(list 1 1 0)
(list 0 1 0)))
(test-end "utility_functions")