require 'test/unit'
load '../gol.rb'
class TestNil < Test::Unit::TestCase
def setup
@nil_hash = Hash.new
end
def test_nil_element_is_nil
assert_nil @nil_hash['foo']['foo']
end
def test_nil_size_is_zero
assert_equal 0, @nil_hash['foo'].size
end
end
class TestGoL < Test::Unit::TestCase
def setup
@world = GoL.new
@world.create(1,0)
end
def test_grid_exists
assert_equal Hash, @world.grid.class
end
def test_cell_does_not_exist
assert_nil @world.grid[1][1]
assert_nil @world.grid[92][0]
end
def test_create
@world.create(1,1)
assert_equal true, @world.grid[1][1]
end
def test_destroy_with_one_cell
@world.destroy(1,0)
assert_equal 0, @world.grid[1].size
end
def test_destroy_with_two_cells
@world.create(1,1)
@world.destroy(1,0)
assert_nil @world.grid[1][0]
assert_equal true, @world.grid[1][1]
end
def test_zero_neighbor_count
assert_equal 0, @world.neighbor_count(1,0)
end
def test_two_neighbor_count
@world.create(1,1)
@world.create(0,0)
assert_equal 2, @world.neighbor_count(1,0)
end
def test_population_tick
future = @world.poptick
assert_equal @world.grid, future.grid
end
def test_eight_vacancy_count
assert_equal 8, @world.vacancy_count(1,0)
end
def test_lonely_cell_dies
@world.turn
assert_nil @world.grid[1][0]
end
=begin
def test_crowded_cell_dies
(1..2).each {|y| @world.create(1,y); @world.create(-1,y) }
@world.turn
assert_nil @world.grid[1][0]
end
def test_spousal_cell_lives
@world.create(1,1)
assert(
@world.grid[1][0],
"Expected #{@world.grid[1][0].inspect} to be true before turn."
)
@world.turn
assert(
@world.grid[1][0],
"Expected #{@world.grid[1][0].inspect} to be true after turn."
)
end
def test_family_cell_lives
@world.create(1,1)
@world.create(-1,1)
assert(
@world.grid[1][0],
"Expected #{@world.grid[1][0].inspect} to be true before turn."
)
@world.turn
assert(
@world.grid[1][0],
"Expected #{@world.grid[1][0].inspect} to be true after turn."
)
end
=end
end