Пример #1
0
def generation_request():
    data = request.get_json() or {}
    # TODO add validation
    str_universe = data['universe']
    width = int(data['width'])
    
    universe = gol.string_to_universe(str_universe, width)

    u_output = {"universe": gol.universe_to_string(gol.universe_generation(universe, width)), "width": width}

    response = jsonify(u_output)
    response.status_code = 200
    response.headers['Location'] = "api/game"
    return response
Пример #2
0
 def setUp(self):
     self.cell_active_zero_neighbors = gol.string_to_universe(
         "000010000", 3)
     self.cell_active_one_neighbor = gol.string_to_universe("000011000", 3)
     self.cell_active_two_neighbors = gol.string_to_universe("001011000", 3)
     self.cell_active_three_neighbors = gol.string_to_universe(
         "001011010", 3)
     self.cell_active_four_neighbors = gol.string_to_universe(
         "101011010", 3)
     self.cell_active_five_neighbors = gol.string_to_universe(
         "101011110", 3)
     self.cell_active_full = gol.string_to_universe("111111111", 3)
     self.cell_inactive_two_neighbors = gol.string_to_universe(
         "010001000", 3)
     self.cell_inactive_three_neighbors = gol.string_to_universe(
         "100100001", 3)
     self.cell_inactive_one_neighbor = gol.string_to_universe(
         "000100000", 3)
     self.cell_inactive_four_neighbors = gol.string_to_universe(
         "010101010", 3)
Пример #3
0
 def setUp(self):
     self.single_cell = [[0]]
     self.three_by_three_singleton = gol.string_to_universe("000010000", 3)
     self.three_by_three_multiple = gol.string_to_universe("000011011", 3)
Пример #4
0
 def test_string_to_universe(self):
     """ Testing happy path scenario """
     self.assertEqual(gol.string_to_universe(self.three_by_three, 3), \
             [[0, 0, 0], [0, 0, 0], [0, 0, 0]])
Пример #5
0
 def test_string_not_divisible_by_width(self):
     """ Testing extra characters are dropped """
     self.assertEqual(gol.string_to_universe(self.three_by_three_short, 3), \
             [[0, 0, 0], [0, 0, 0]])
Пример #6
0
 def setUp(self):
     self.simple_universe = gol.string_to_universe("000010000", 3)
     self.tee_universe = gol.string_to_universe("000111010", 3)
     self.glider_universe = gol.string_to_universe("0100001011100000", 4)
Пример #7
0
 def test_zero_width(self):
     """ Testing zero width """
     self.assertEqual(gol.string_to_universe(self.three_by_three, 0), [])
Пример #8
0
 def test_empty_string(self):
     """ Testing empty string """
     self.assertEqual(gol.string_to_universe('', 3), [])