Esempio n. 1
0
    def testStepMethod(self):
        world = World(width=10, height=10)

        # this is a static pattern for classic game of life rules
        world[0, 0].alive = True
        world[0, 1].alive = True
        world[1, 0].alive = True
        world[1, 1].alive = True

        # these cells will never transition from alive to dead as
        # long as no other neighbor cells become alive.
        self.assertEqual(world[0, 0].age, 0)
        self.assertEqual(world[0, 1].age, 0)
        self.assertEqual(world[1, 0].age, 0)
        self.assertEqual(world[1, 1].age, 0)

        self.assertEqual(len([c for c in world if c.alive]), 4)

        for trip in range(1, 10):
            world.step()
            alive_cells = [c for c in world if c.alive]
            self.assertEqual(len(alive_cells), 4)
            self.assertEqual(world.generation, trip)
            for cell in alive_cells:
                self.assertEqual(cell.age, trip)

        world.reset()

        world[0, 0].alive = True

        world.step()
        self.assertEqual(len([c for c in world if c.alive]), 0)
Esempio n. 2
0
    def testStepMethod(self):
        world = World(width=10, height=10)

        # this is a static pattern for classic game of life rules
        world[0, 0].alive = True
        world[0, 1].alive = True
        world[1, 0].alive = True
        world[1, 1].alive = True

        # these cells will never transition from alive to dead as
        # long as no other neighbor cells become alive.
        self.assertEqual(world[0, 0].age, 0)
        self.assertEqual(world[0, 1].age, 0)
        self.assertEqual(world[1, 0].age, 0)
        self.assertEqual(world[1, 1].age, 0)

        self.assertEqual(len([c for c in world if c.alive]), 4)

        for trip in range(1, 10):
            world.step()
            alive_cells = [c for c in world if c.alive]
            self.assertEqual(len(alive_cells), 4)
            self.assertEqual(world.generation, trip)
            for cell in alive_cells:
                self.assertEqual(cell.age, trip)

        world.reset()

        world[0, 0].alive = True

        world.step()
        self.assertEqual(len([c for c in world if c.alive]), 0)
Esempio n. 3
0
    def testResetMethod(self):

        world = World(width=10, height=10)

        self.assertEqual(len([c for c in world if c.alive]), 0)

        world[0, 0].alive = True
        world[1, 0].alive = True
        world[0, 1].alive = True
        world[1, 1].alive = True

        self.assertEqual(len([c for c in world if c.alive]), 4)

        world.step()

        self.assertEqual(len([c for c in world if c.alive]), 4)
        self.assertEqual(world.generation, 1)

        world.reset()
        self.assertEqual(len(world.cells), world.width * world.height)
        self.assertEqual(len([c for c in world if c.alive]), 0)
        self.assertEqual(world.generation, 0)
Esempio n. 4
0
    def testResetMethod(self):

        world = World(width=10, height=10)

        self.assertEqual(len([c for c in world if c.alive]), 0)

        world[0, 0].alive = True
        world[1, 0].alive = True
        world[0, 1].alive = True
        world[1, 1].alive = True

        self.assertEqual(len([c for c in world if c.alive]), 4)

        world.step()

        self.assertEqual(len([c for c in world if c.alive]), 4)
        self.assertEqual(world.generation, 1)

        world.reset()
        self.assertEqual(len(world.cells), world.width * world.height)
        self.assertEqual(len([c for c in world if c.alive]), 0)
        self.assertEqual(world.generation, 0)