def test_world_can_render_with_arbitrary_characters(self): world = World.empty() world.set_living_at(Location(0, 0)) world.set_living_at(Location(2, 0)) render = WorldRenderer(world).render() expected = 'XOX' self.assertEqual(render, expected)
def test_world_with_live_and_dead_cell_renders_as_expected(self): world = World.empty() world.set_living_at(Location(0, 0)) world.set_living_at(Location(2, 0)) render = WorldRenderer(world).render() expected = '+-+' self.assertEqual(render, expected)
def test_world_renders_according_to_dimensions(self): world = World.empty(min_location=Location(0, 0), max_location=Location(2, 0)) render = WorldRenderer(world).render() expected = ('---') self.assertEqual(render, expected)
def test_world_that_is_vertical_renders_properly(self): world = World.empty() world.set_living_at(Location(0, 0)) world.set_living_at(Location(0, 2)) render = WorldRenderer(world).render() expected = ('+\n' '-\n' '+') self.assertEqual(render, expected)
def test_a_world_with_one_cell_is_empty_after_a_tick(self): # Potential smell here, given that we have to use real location # instance here for this to pass. Mock approach will not work. self.location = Location(0, 0) world = World.empty() world.set_living_at(self.location) next_world = world.tick() self.assertTrue(next_world.is_empty)
def test_empty_world_has_0_living_cell_count(self): world = World.empty() self.assertEqual(world.living_cell_count, 0)
def test_set_living_at_below_min_location_y_lowers_min_location(self): world = World.empty(min_location=Location(0, 0), max_location=Location(3, 3)) world.set_living_at(Location(0, -1)) self.assertEqual(world.dimensions, (4, 5))
def test_set_living_at_beyond_max_location_y_expands_max_location(self): world = World.empty(min_location=Location(0, 0), max_location=Location(3, 3)) world.set_living_at(Location(0, 4)) self.assertEqual(world.dimensions, (4, 5))
def test_world_dimensions_come_from_min_max_locations(self): world = World.empty(min_location=Location(0, 0), max_location=Location(3, 3)) self.assertEqual((4, 4), world.dimensions)
def test_world_has_default_dimensions(self): world = World.empty() self.assertEqual((1, 1), world.dimensions)
def test_2_by_2_world_with_one_living_cell_has_3_dead_cells(self): world = World.empty(min_location=Location(0, 0), max_location=Location(1, 1)) world.set_living_at(self.location) self.assertEqual(world.dead_cell_count, 3)
def test_an_empty_world_with_10_by_10_dimensions_has_100_dead_cells(self): world = World.empty(min_location=Location(0, 0), max_location=Location(9, 9)) self.assertEqual(world.dead_cell_count, 100)
def test_dead_locations_not_in_living_locations(self): world = World.empty() world.set_dead_at(self.location) self.assertEqual(world.living_locations, [])
def test_living_locations_includes_living_cells(self): world = World.empty() world.set_living_at(self.location) self.assertEqual(world.living_locations, [self.location])
def test_an_empty_world_stays_empty_after_a_tick(self): world = World.empty() next_world = world.tick() self.assertTrue(next_world.is_empty)
def test_an_empty_world_with_2_by_2_dimensions_has_4_dead_cells(self): world = World.empty(min_location=Location(0, 0), max_location=Location(1, 1)) self.assertEqual(world.dead_cell_count, 4)
def test_empty_world_renders_as_expected(self): world = World.empty() render = WorldRenderer(world).render() expected = '-' self.assertEqual(render, expected)