def _do_test_2d_integration(test): """ dig, render, and render_2d_board on boards """ exp_fname = os.path.join(TEST_DIRECTORY, 'test_outputs', f'test2d_integration_{test:02d}.pickle') inp_fname = os.path.join(TEST_DIRECTORY, 'test_inputs', f'test2d_integration_{test:02d}.pickle') with open(inp_fname, 'rb') as f: inputs = pickle.load(f) with open(exp_fname, 'rb') as f: expected = pickle.load(f) game = lab.new_game_2d(*inputs[0]) for location, exp in zip(inputs[1], expected): num, g, render, renderx, ascii_, ascii_x = exp assert lab.dig_2d(game, *location) == num for key in g: assert game[key] == g[key] assert lab.render_2d_locations(game) == render assert lab.render_2d_locations(game, xray=True) == renderx assert lab.render_2d_board(game) == ascii_ assert lab.render_2d_board(game, xray=True) == ascii_x last_state = game['state'] if last_state in {'victory', 'defeat'}: for r in range(game['dimensions'][0]): for c in range(game['dimensions'][1]): assert lab.dig_2d(game, *location) == 0 assert game['state'] == last_state else: for r in range(game['dimensions'][0]): for c in range(game['dimensions'][1]): if game['mask'][r][c]: assert lab.dig_2d(game, *location) == 0 assert game['state'] == 'ongoing'''
def test_dig(self): for t in ('complete', 'mine', 'small'): with self.subTest(test=t): with open('test_outputs/test2d_dig%s.pickle' % t, 'rb') as f: expected = pickle.load(f) with open('test_inputs/test2d_dig%s.pickle' % t, 'rb') as f: inputs = pickle.load(f) game = inputs['game'] revealed = lab.dig_2d(game, inputs['row'], inputs['col']) self.assertEqual(revealed, expected['revealed']) for name in expected['game']: self.assertEqual(game[name], expected['game'][name])
def test_dig_2d(test): exp_fname = os.path.join(TEST_DIRECTORY, 'test_outputs', f'test2d_dig{test}.pickle') inp_fname = os.path.join(TEST_DIRECTORY, 'test_inputs', f'test2d_dig{test}.pickle') with open(exp_fname, 'rb') as f: expected = pickle.load(f) with open(inp_fname, 'rb') as f: inputs = pickle.load(f) game = inputs['game'] revealed = lab.dig_2d(game, inputs['row'], inputs['col']) assert revealed == expected['revealed'] for name in expected['game']: assert game[name] == expected['game'][name]
def run_integration_test(self, t): """ dig, render, and render_ascii on boards """ with open('test_outputs/test2d_integration%d.pickle' % t, 'rb') as f: expected = pickle.load(f) with open('test_inputs/test2d_integration%s.pickle' % t, 'rb') as f: inputs = pickle.load(f) results = [] game = inputs['game'] for coord in inputs['coords']: results.append((('dig', lab.dig_2d(game, *coord)), ('game', game), ('render', lab.render_2d(game)), ('render/xray', lab.render_2d(game, True)), ('render_ascii', lab.render_ascii(game)), ('render_ascii/xray', lab.render_ascii(game, True)))) self.assertEqual(results, expected)
def test_2d_integration(test): """ dig, render, and render_ascii on boards """ exp_fname = os.path.join(TEST_DIRECTORY, 'test_outputs', f'test2d_integration{test}.pickle') inp_fname = os.path.join(TEST_DIRECTORY, 'test_inputs', f'test2d_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) results = [] game = inputs['game'] for location, exp in zip(inputs['coords'], expected): result = (('dig', lab.dig_2d(game, *location)), ('game', game), ('render', lab.render_2d(game)), ('render/xray', lab.render_2d(game, True)), ('render_ascii', lab.render_ascii(game)), ('render_ascii/xray', lab.render_ascii(game, True))) assert result == exp
def handle_dig_2d(params): dug_2d = lab.dig_2d(current_game_2d, params['row'], params['col']) status = current_game_2d['state'] return [status, dug_2d]
def ui_dig_2d(d): game, row, col = d["game"], d["row"], d["col"] nb_dug = lab.dig_2d(game, row, col) status = game['state'] return [game, status, nb_dug]