Example #1
0
 def create_evolve_assert(self, initial_state, final_state, evolutions=1):
     """
     Helper function for tests.
     """
     testLife = Life(self.grid_to_coords(initial_state))
     for i in range(0, evolutions):
         testLife.evolve()
     self.assertEqual(self.grid_to_coords(final_state),
                      self.normalise_coords(testLife.state))
Example #2
0
    def test_non_square(self):
        startState = [ [0,0,0,0,0],
                       [0,1,1,1,0],
                       [0,0,0,0,0] ]

        nextState =  [ [0,0,1,0,0],
                       [0,0,1,0,0],
                       [0,0,1,0,0]]

        testLife = Life()
        self.assertEqual(nextState, testLife.evolve(startState))
    	self.assertEqual(startState, testLife.evolve(nextState))
Example #3
0
    def test_seeded_outcome(self):
        startState = [ [0,0,0,0,0],
                       [0,0,0,0,0],
                       [0,1,1,1,0],
                       [0,0,0,0,0],
                       [0,0,0,0,0] ]

        nextState =  [ [0,0,0,0,0],
                       [0,0,1,0,0],
                       [0,0,1,0,0],
                       [0,0,1,0,0],
                       [0,0,0,0,0] ]

        testLife = Life()
        self.assertEqual(nextState, testLife.evolve(startState))
        self.assertEqual(startState, testLife.evolve(nextState))
    def test_survival_population(self):
        """Test that a cell survives due to not being over/under populated"""
        survivalState = [[1, 1, 0], [1, 0, 0], [0, 0, 0]]

        finalState = [[1, 1, 0], [1, 1, 0], [0, 0, 0]]

        testLife = Life(survivalState, 3)
        self.assertEqual(finalState, next(testLife.evolve(1)))
    def test_over_population(self):
        """Test that a cell does die due to over-population"""
        overState = [[0, 1, 0], [1, 1, 1], [0, 1, 0]]

        finalState = [[1, 1, 1], [1, 0, 1], [1, 1, 1]]

        testLife = Life(overState, 3)
        self.assertEqual(finalState, next(testLife.evolve(1)))
    def test_under_population(self):
        """Test that a cell dies due to under-population"""
        underState = [[0, 0, 0], [0, 1, 0], [0, 0, 0]]

        finalState = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

        testLife = Life(underState, 3)
        self.assertEqual(finalState, next(testLife.evolve(1)))
Example #7
0
 def test_spinner(self):
     sA = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 1, 1, 1, 0],
           [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
     sB = [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 1, 0, 0],
           [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]
     testLife = Life()
     self.assertEqual(sB, testLife.evolve(sA))
     self.assertEqual(sA, testLife.evolve(sB))
    def test_no_interaction(self):
        """Test that nothing occurs when initial state is dead"""
        emptyState = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
        """Test that nothing occurs when initial state is dead"""
        finalState = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

        testLife = Life(emptyState, 3)
        self.assertEqual(finalState, next(testLife.evolve(1)))
    def test_reproduction_population(self):
        """Test that a cell is born due to reproduction"""

        birthState = [[1, 1, 1], [0, 0, 0], [0, 0, 0]]

        finalState = [[0, 1, 0], [0, 1, 0], [0, 0, 0]]

        testLife = Life(birthState, 3)
        self.assertEqual(finalState, next(testLife.evolve(1)))
Example #10
0
 def test_glider(self):
     # Test based on this sequence:
     # https://camo.githubusercontent.com/f865db6a304d36aa7fef6c060729a2d635cd5c14/687474703a2f2f7777772d726f68616e2e736473752e6564752f7e72636172726574652f7465616368696e672f4d2d3539365f706174742f696d616765732f676c696465722e676966
     # The glider is a cell arrangement which keeps going indefinitely.
     t0 = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 1, 0, 1, 0, 0],
           [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]
     t1 = [[0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0], [0, 0, 0, 1, 1, 0],
           [0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]
     t2 = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0],
           [0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]
     t3 = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0],
           [0, 0, 0, 1, 1, 0], [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0]]
     t4 = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0],
           [0, 0, 1, 0, 1, 0], [0, 0, 0, 1, 1, 0], [0, 0, 0, 0, 0, 0]]
     testLife = Life()
     self.assertEqual(t1, testLife.evolve(t0))
     self.assertEqual(t2, testLife.evolve(t1))
     self.assertEqual(t3, testLife.evolve(t2))
     self.assertEqual(t4, testLife.evolve(t3))
Example #11
0
    def test_creation(self):
        startState = [ [0,1,0],
                       [1,1,1],
                       [0,1,0] ]

        endState =   [ [1,1,1],
                       [1,0,1],
                       [1,1,1] ]

        testLife = Life()
        self.assertEqual(endState, testLife.evolve(startState))
Example #12
0
    def test_overcrowding(self):
        startState = [ [1,1,1],
                       [1,1,1],
                       [1,1,1] ]

        endState =   [ [1,0,1],
                       [0,0,0],
                       [1,0,1] ]

        testLife = Life()
        self.assertEqual(endState, testLife.evolve(startState))
Example #13
0
    def test_seeded_generation(self):
        """Tests a seeded input"""
        seedState = [[0, 0, 0], [1, 1, 1], [0, 0, 0]]

        state1 = [[0, 1, 0], [0, 1, 0], [0, 1, 0]]

        state2 = [[0, 0, 0], [1, 1, 1], [0, 0, 0]]

        testLife = Life(seedState, 3)

        states = testLife.evolve(2)

        self.assertEqual(state1, next(states))
        self.assertEqual(state2, next(states))
Example #14
0
 def test_overpopulation(self):
     s0 = [[0, 1, 1], [1, 1, 1], [0, 0, 0]]
     target = [[0, 0, 1], [0, 0, 1], [1, 1, 0]]
     testLife = Life()
     self.assertEqual(target, testLife.evolve(s0))
Example #15
0
 def test_create(self):
     s0 = [[0, 0, 1], [1, 0, 1], [0, 0, 0]]
     target = [[1, 1, 0], [1, 1, 0], [0, 0, 0]]
     testLife = Life()
     self.assertEqual(target, testLife.evolve(s0))
Example #16
0
 def test_no_interaction(self):
     emptyState = [  [0,0,0],
                     [0,0,0],
                     [0,0,0]  ]
     testLife = Life()
     self.assertEqual(emptyState, testLife.evolve(emptyState))
Example #17
0
 def test_survival(self):
     s0 = [[0, 1, 1], [0, 1, 1], [0, 0, 0]]
     target = [[0, 1, 1], [0, 1, 1], [0, 0, 0]]
     testLife = Life()
     self.assertEqual(target, testLife.evolve(s0))