Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
 def test_render(self):
     """ Testing render on a small board """
     with open('test_inputs/test2d_render.pickle', 'rb') as f:
         inp = pickle.load(f)
     result = lab.render_2d(inp)
     expected = [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
                 [' ', ' ', ' ', ' ', ' ', '1', '1', '1'],
                 [' ', ' ', ' ', ' ', '1', '2', '_', '_'],
                 ['1', '2', '1', '2', '2', '_', '_', '_'],
                 ['_', '_', '_', '_', '_', '_', '_', '_'],
                 ['_', '_', '_', '_', '_', '_', '_', '_'],
                 ['_', '_', '_', '_', '_', '_', '_', '_'],
                 ['_', '_', '_', '_', '_', '_', '_', '_'],
                 ['_', '_', '_', '_', '_', '_', '_', '_'],
                 ['_', '_', '_', '_', '_', '_', '_', '_']]
     self.assertEqual(result, expected)
Exemplo n.º 4
0
def test_render_2d():
    """ Testing render on a small board """
    with open(os.path.join(TEST_DIRECTORY, 'test_inputs', 'test2d_render.pickle'), 'rb') as f:
        inp = pickle.load(f)
    result = lab.render_2d(inp)
    expected = [[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
                [' ', ' ', ' ', ' ', ' ', '1', '1', '1'],
                [' ', ' ', ' ', ' ', '1', '2', '_', '_'],
                ['1', '2', '1', '2', '2', '_', '_', '_'],
                ['_', '_', '_', '_', '_', '_', '_', '_'],
                ['_', '_', '_', '_', '_', '_', '_', '_'],
                ['_', '_', '_', '_', '_', '_', '_', '_'],
                ['_', '_', '_', '_', '_', '_', '_', '_'],
                ['_', '_', '_', '_', '_', '_', '_', '_'],
                ['_', '_', '_', '_', '_', '_', '_', '_']]
    assert result == expected
Exemplo n.º 5
0
def ui_render_2d(d):
    g = d['game']
    x = d['xray']
    b = g['board']
    m = g['mask']
    r = d['our_renderer']
    if r:
        return [[
            '_' if (not x) and
            (not m[r][c]) else ' ' if b[r][c] == 0 else str(b[r][c])
            for c in range(d['num_cols'])
        ] for r in range(d['num_rows'])]
    else:
        try:
            game = d['game']
            r = lab.render_2d(game, x)
        except:
            r = [['ERROR' for i in range(d['num_cols'])]
                 for j in range(d['num_rows'])]
        return r