Example #1
0
 def test_newlarge4dgame(self):
     """ Testing new_game on a large 4-D board """
     with open('test_outputs/testnd_newlarge4dgame.pickle', 'rb') as f:
         expected = pickle.load(f)
     with open('test_inputs/testnd_newlarge4dgame.pickle', 'rb') as f:
         inputs = pickle.load(f)
     result = lab.new_game_nd(inputs['dimensions'], inputs['bombs'])
     for i in ('dimensions', 'board', 'mask', 'state'):
         self.assertEqual(result[i], expected[i])
Example #2
0
def test_adjacent3d():
    ''' Test for get_adjacent_indices function'''
    expected = [(4,13,0),(6,13,0),(5,12,0),(5,14,0),(6,14,0),(4,12,0),(6,12,0),(4,14,0),(5,13,1),(4,13,1),(6,13,1),(5,12,1),(5,14,1),(6,14,1),(4,12,1),(6,12,1),(4,14,1), (5,13,0)]
    expected = sorted(expected)
    game = lab.new_game_nd((10,20,3), [])
    res = lab.get_adjacent_indices(game, (5,13,0))
    res_tuples = []
    for index in res:
        res_tuples.append(tuple(index))
    assert res_tuples == expected
Example #3
0
def test_newlarge4dgame():
    """ Testing new_game on a large 4-D board """
    exp_fname = os.path.join(TEST_DIRECTORY, 'test_outputs', 'testnd_newlarge4dgame.pickle')
    inp_fname = os.path.join(TEST_DIRECTORY, 'test_inputs', 'testnd_newlarge4dgame.pickle')
    with open(exp_fname, 'rb') as f:
        expected = pickle.load(f)
    with open(inp_fname, 'rb') as f:
        inputs = pickle.load(f)
    result = lab.new_game_nd(inputs['dimensions'], inputs['bombs'])
    for i in ('dimensions', 'board', 'mask', 'state'):
        assert result[i] == expected[i]
Example #4
0
 def _test_integration(self, n):
     with open('test_outputs/testnd_integration%s.pickle' % n, 'rb') as f:
         expected = pickle.load(f)
     with open('test_inputs/testnd_integration%s.pickle' % n, 'rb') as f:
         inputs = pickle.load(f)
     g = lab.new_game_nd(inputs['dimensions'], inputs['bombs'])
     for location, results in zip(inputs['digs'], expected):
         squares_revealed, game, rendered, rendered_xray = results
         res = lab.dig_nd(g, location)
         self.assertEqual(res, squares_revealed)
         for i in ('dimensions', 'board', 'mask', 'state'):
             self.assertEqual(g[i], game[i])
         self.assertEqual(lab.render_nd(g), rendered)
         self.assertEqual(lab.render_nd(g, True), rendered_xray)
Example #5
0
def test_nd_integration(test):
    exp_fname = os.path.join(TEST_DIRECTORY, 'test_outputs', f'testnd_integration{test}.pickle')
    inp_fname = os.path.join(TEST_DIRECTORY, 'test_inputs', f'testnd_integration{test}.pickle')
    with open(exp_fname, 'rb') as f:
        expected = pickle.load(f)
    with open(inp_fname, 'rb') as f:
        inputs = pickle.load(f)
    g = lab.new_game_nd(inputs['dimensions'], inputs['bombs'])
    for location, results in zip(inputs['digs'], expected):
        squares_revealed, game, rendered, rendered_xray = results
        res = lab.dig_nd(g, location)
        assert res == squares_revealed
        for i in ('dimensions', 'board', 'mask', 'state'):
            assert g[i] == game[i]
        assert lab.render_nd(g) == rendered
        assert lab.render_nd(g, True) == rendered_xray
Example #6
0
def handle_new_game_nd(params):
    global current_game_nd
    current_game_nd = lab.new_game_nd(params['dimensions'],
                                      [tuple(i) for i in params['bombs']])
Example #7
0
def ui_new_game_nd(d):
    global current_game_nd
    current_game_nd = lab.new_game_nd(d["dimensions"],
                                      [tuple(i) for i in d["bombs"]])
    return