コード例 #1
0
def test_find_down_match_at():
    board_s = dedent("""\
                     | Y | Y | G |   |
                     | Y | R | G |   |
                     | Y | R | G |   |
                     | Y | R |   |   |
                     """)
    board = parse_board(board_s, FOUR_SIDE_PARSER)

    expected = [
        [down_match(4), None, down_match(3), None],
        [down_match(3), down_match(3), None, None],
        [None, None, None, None],
        [None, None, None, None],
    ]
    for row in range(board.side):
        for col in range(board.side):
            yield (_verify_find_single_match, board, row, col,
                   expected[row][col], find_down_match_at)
コード例 #2
0
ファイル: test_match.py プロジェクト: tomheon/hazardchamber
def test_find_down_match_at():
    board_s = dedent("""\
                     | Y | Y | G |   |
                     | Y | R | G |   |
                     | Y | R | G |   |
                     | Y | R |   |   |
                     """)
    board = parse_board(board_s, FOUR_SIDE_PARSER)

    expected = [
        [down_match(4), None, down_match(3), None],
        [down_match(3), down_match(3), None, None],
        [None, None, None, None],
        [None, None, None, None],
        ]
    for row in range(board.side):
        for col in range(board.side):
            yield (_verify_find_single_match,
                   board, row, col, expected[row][col],
                   find_down_match_at)
コード例 #3
0
ファイル: test_match.py プロジェクト: tomheon/hazardchamber
def test_contains_match():
    cases = [
        (right_match(4)(0, 0), right_match(3)(0, 0), True),
        (right_match(4)(0, 0), right_match(3)(0, 1), True),
        (right_match(3)(0, 1), right_match(3)(0, 1), True),
        (right_match(3)(0, 1), right_match(3)(1, 0), False),
        (right_match(3)(0, 1), down_match(3)(0, 1), False),
        ]

    for m1, m2, contains in cases:
        yield _verify_contains_match, m1, m2, contains
コード例 #4
0
def test_contains_match():
    cases = [
        (right_match(4)(0, 0), right_match(3)(0, 0), True),
        (right_match(4)(0, 0), right_match(3)(0, 1), True),
        (right_match(3)(0, 1), right_match(3)(0, 1), True),
        (right_match(3)(0, 1), right_match(3)(1, 0), False),
        (right_match(3)(0, 1), down_match(3)(0, 1), False),
    ]

    for m1, m2, contains in cases:
        yield _verify_contains_match, m1, m2, contains
コード例 #5
0
def test_find_matches_at():
    board_s = dedent("""\
                     | Y | Y | Y |   |
                     | Y | Y |   |   |
                     | Y | Y |   |   |
                     | Y | R | R | R |
                     """)
    board = parse_board(board_s, FOUR_SIDE_PARSER)

    expected = [
        [[down_match(4), right_match(3)], [down_match(3)], [left_match(3)],
         []],
        [[down_match(3)], [], [], []],
        [[up_match(3)], [up_match(3)], [], []],
        [[up_match(4)], [right_match(3)], [], [left_match(3)]],
    ]
    for row in range(board.side):
        for col in range(board.side):
            yield (_verify_find_single_match, board, row, col,
                   expected[row][col], find_matches_at)
コード例 #6
0
ファイル: test_match.py プロジェクト: tomheon/hazardchamber
def test_find_matches_at():
    board_s = dedent("""\
                     | Y | Y | Y |   |
                     | Y | Y |   |   |
                     | Y | Y |   |   |
                     | Y | R | R | R |
                     """)
    board = parse_board(board_s, FOUR_SIDE_PARSER)

    expected = [
        [[down_match(4), right_match(3)],
         [down_match(3)], [left_match(3)], []],
        [[down_match(3)], [], [], []],
        [[up_match(3)], [up_match(3)], [], []],
        [[up_match(4)], [right_match(3)], [], [left_match(3)]],
        ]
    for row in range(board.side):
        for col in range(board.side):
            yield (_verify_find_single_match,
                   board, row, col, expected[row][col],
                   find_matches_at)
コード例 #7
0
            """),
     FOUR_SIDE_PARSER,
     [((0, 3),
       (1, 3),
       [right_match(3)(0, 1)])]),

    (dedent("""\
            | R | P | P | Y |
            | R | G | R | Y |
            | Y | G | R | G |
            | C | Y | P | G |
            """),
     FOUR_SIDE_PARSER,
     [((2, 0),
       (3, 0),
       [down_match(3)(0, 0)]),
      ((3, 0),
       (3, 1),
       [down_match(3)(1, 1)])]),

    (dedent("""\
            | Y | R | P | Y |
            | R | G | R | Y |
            | Y | G | R | G |
            | G | Y | Y | G |
            """),
     FOUR_SIDE_PARSER,
     [((0, 1),
       (0, 2),
       [down_match(3)(0, 2)]),
      ((0, 1),
コード例 #8
0
from nose.tools import eq_

from criticals import calc_critical_square
from tutils import right_match, down_match

# (match, exp_crit_sq)
CASES = [(right_match(5)(0, 1), (0, 3)), (right_match(6)(0, 1), (0, 3)),
         (down_match(5)(1, 1), (3, 1)), (down_match(6)(1, 1), (3, 1)),
         (down_match(3)(0, 1).combine(right_match(3)(1, 0)), (1, 1)),
         (down_match(3)(0, 1).combine(right_match(3)(0, 0)), (0, 1)),
         (down_match(3)(0, 1).combine(right_match(3)(0, 1)), (0, 1))]


def test_calc_critical_square():
    for match, exp_crit_square in CASES:
        yield _verify_calc_critical_square, match, exp_crit_square


def _verify_calc_critical_square(match, exp_crit_square):
    eq_(exp_crit_square, calc_critical_square(match))
コード例 #9
0
ファイル: test_match.py プロジェクト: tomheon/hazardchamber
def _verify_square_in_match(match, square, includes):
    eq_(includes, square in Match(match))


# (board_s, parser, expected matches)
FIND_MATCHES_CASES = [
    (dedent("""\
            | Y | Y | Y |   |
            | Y | Y |   |   |
            | Y | Y |   |   |
            | Y | R | R | R |
            """),
     FOUR_SIDE_PARSER,
     [right_match(3)(0,
                     0).combine(down_match(4)(0,
                                              0)).combine(down_match(3)(0,
                                                                        1)),
      right_match(3)(3, 1)]),

    (dedent("""\
            | Y | Y | Y | Y |
            | G | G |   |   |
            | Y | Y |   |   |
            | Y | R | R | G |
            """),
     FOUR_SIDE_PARSER,
     [right_match(4)(0, 0)]),

    (dedent("""\
            | Y | Y | Y | G |
            | G | Y |   |   |
コード例 #10
0
from nose.tools import eq_

from criticals import calc_critical_square
from tutils import right_match, down_match

# (match, exp_crit_sq)
CASES = [
    (right_match(5)(0, 1), (0, 3)),
    (right_match(6)(0, 1), (0, 3)),
    (down_match(5)(1, 1), (3, 1)),
    (down_match(6)(1, 1), (3, 1)),
    (down_match(3)(0, 1).combine(right_match(3)(1, 0)),
     (1, 1)),
    (down_match(3)(0, 1).combine(right_match(3)(0, 0)),
     (0, 1)),
    (down_match(3)(0, 1).combine(right_match(3)(0, 1)),
     (0, 1))
    ]


def test_calc_critical_square():
    for match, exp_crit_square in CASES:
        yield _verify_calc_critical_square, match, exp_crit_square


def _verify_calc_critical_square(match, exp_crit_square):
    eq_(exp_crit_square, calc_critical_square(match))
コード例 #11
0
        yield _verify_square_in_match, match, square, includes


def _verify_square_in_match(match, square, includes):
    eq_(includes, square in Match(match))


# (board_s, parser, expected matches)
FIND_MATCHES_CASES = [
    (dedent("""\
            | Y | Y | Y |   |
            | Y | Y |   |   |
            | Y | Y |   |   |
            | Y | R | R | R |
            """), FOUR_SIDE_PARSER, [
        right_match(3)(0, 0).combine(down_match(4)(0, 0)).combine(
            down_match(3)(0, 1)),
        right_match(3)(3, 1)
    ]),
    (dedent("""\
            | Y | Y | Y | Y |
            | G | G |   |   |
            | Y | Y |   |   |
            | Y | R | R | G |
            """), FOUR_SIDE_PARSER, [right_match(4)(0, 0)]),
    (dedent("""\
            | Y | Y | Y | G |
            | G | Y |   |   |
            | Y | Y |   |   |
            | Y | R | R | G |
            """), FOUR_SIDE_PARSER,