-
Notifications
You must be signed in to change notification settings - Fork 16
/
game_of_life_test.rb
53 lines (43 loc) · 1.69 KB
/
game_of_life_test.rb
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
# Rules
# each cell 2 possible states, life of death
# 8 neighbours
# - any life cell < 2 neighbours dies
# - any life cell > 3 neighbours dies
# - any live cell with 2 or 3 neighbours lives to next generation
# - any dead cell with exactly 3 live neighbours becomes a live cell
# first generation: apply pattern
#
### EXAMPLE ##########################################################################################################
# WRITE YOUR OWN TESTS, OF COURSE
# test-driven development is the best, this is just to show you how it should work (if it's not clear from rules)
# Plus varying parameters on initialization allows you to do cooler things, like play with different sizes, seeds, etc.
#######################################################################################################################
require File.join(File.dirname(__FILE__), 'game_of_life')
require 'rubygems'
require 'test/unit'
class GameOfLifeTest < Test::Unit::TestCase
def setup
@game = GameOfLife.new(3)
end
def test_should_kill_with_no_neighbours
@game.state = [[1,0,0],[0,0,0],[0,0,0]]
after = @game.evolve
assert_equal after[0][0], 0
end
def test_should_kill_with_just_one_neighbour
@game.state = [[0,0,0],[1,0,0],[1,0,0]]
after = @game.evolve
assert_equal after[1][0], 0
assert_equal after[2][0], 0
end
def test_should_kill_with_more_than_3_neighbours
@game.state = [[1,1,1],[1,1,1],[1,1,1]]
after = @game.evolve
assert_equal after, [[0,0,0],[0,0,0],[0,0,0]]
end
def test_should_give_birth_if_3_neighbours
@game.state = [[1,0,0],[1,1,0],[0,0,0]]
after = @game.evolve
assert_equal after, [[1,1,1],[1,1,1],[1,1,1]]
end
end