コード例 #1
0
 def test_can_handle_bad_matrix(self):
     game = GameOfLife()
     bad_field = [[0, 0],
                  [0]]
     msg = 'invalid string entered'
     with self.assertRaisesRegex(ValueError, msg):
         game.start(bad_field)
コード例 #2
0
 def test_start_2x2_last_point_is_dead(self):
     game = GameOfLife()
     field_test = [[1, 1],
                   [1, 0]]
     result = game.start(field_test)
     correct_field = [[1, 1],
                      [1, 1]]
     self.assertTrue(result == correct_field)
コード例 #3
0
 def test_start_2x2_two_points_on_the_first_line_are_live(self):
     game = GameOfLife()
     field_test = [[1, 1],
                   [0, 0]]
     result = game.start(field_test)
     correct_field = [[0, 0],
                      [0, 0]]
     self.assertTrue(result == correct_field)
コード例 #4
0
 def test_start_2x2_first_point_live(self):
     game = GameOfLife()
     field_test = [[1, 0],
                   [0, 0]]
     result = game.start(field_test)
     correct_field = [[0, 0],
                      [0, 0]]
     self.assertTrue(result == correct_field)
コード例 #5
0
 def test_start_3x3_living_square(self):
     game = GameOfLife()
     field_test = [[1, 1, 0],
                   [1, 0, 0],
                   [0, 0, 0]]
     result = game.start(field_test)
     correct_field = [[1, 1, 0],
                      [1, 1, 0],
                      [0, 0, 0]]
     self.assertTrue(result == correct_field)
コード例 #6
0
 def test_start_4x8_column(self):
     game = GameOfLife()
     field_test = [[0, 0, 0, 0, 1, 0, 0, 0],
                   [0, 0, 0, 0, 1, 0, 0, 0],
                   [0, 0, 0, 0, 1, 0, 0, 0],
                   [0, 0, 0, 0, 0, 0, 0, 0]]
     result = game.start(field_test)
     correct_field = [[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, 0, 0, 0, 0, 0, 0, 0]]
     self.assertTrue(result == correct_field)
コード例 #7
0
 def test_can_create_game_of_life(self):
     game = GameOfLife()
     self.assertTrue(isinstance(game, GameOfLife))
コード例 #8
0
 def test_start_2x2_all_points_are_dead(self):
     game = GameOfLife()
     field_test = [[0, 0],
                   [0, 0]]
     result = game.start(field_test)
     self.assertTrue(result == field_test)
コード例 #9
0
 def compute_next_step(self):
     self.logger.log('Button clicked')
     game = GameOfLife()
     self.convert_field_to_binary(self.current_color_field)
     self.next_binary_field = game.start(self.current_binary_field)
     self.convert_field_to_color()
コード例 #10
0
 def compute_next_step(self):
     game = GameOfLife()
     self.convert_field_to_binary(self.current_color_field)
     self.next_binary_field = game.start(self.current_binary_field)
     self.convert_field_to_color()