Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
 def test_empty_world_has_0_living_cell_count(self):
     world = World.empty()
     self.assertEqual(world.living_cell_count, 0)
Ejemplo n.º 7
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))
Ejemplo n.º 8
0
    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))
Ejemplo n.º 9
0
 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)
Ejemplo n.º 10
0
 def test_world_has_default_dimensions(self):
     world = World.empty()
     self.assertEqual((1, 1), world.dimensions)
Ejemplo n.º 11
0
 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)
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
 def test_dead_locations_not_in_living_locations(self):
     world = World.empty()
     world.set_dead_at(self.location)
     self.assertEqual(world.living_locations, [])
Ejemplo n.º 14
0
 def test_living_locations_includes_living_cells(self):
     world = World.empty()
     world.set_living_at(self.location)
     self.assertEqual(world.living_locations, [self.location])
Ejemplo n.º 15
0
 def test_an_empty_world_stays_empty_after_a_tick(self):
     world = World.empty()
     next_world = world.tick()
     self.assertTrue(next_world.is_empty)
Ejemplo n.º 16
0
 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)
Ejemplo n.º 17
0
 def test_empty_world_renders_as_expected(self):
     world = World.empty()
     render = WorldRenderer(world).render()
     expected = '-'
     self.assertEqual(render, expected)