Exemplo n.º 1
0
    def testEqualWithGap(self):
        state = """\
0|4 0|5

0 x x 2
-     -
0 0|1 0
"""
        board1 = Board.create(state)
        board2 = Board.create(state)

        eq_result = (board1 == board2)
        neq_result = (board1 != board2)
        self.assertTrue(eq_result)
        self.assertFalse(neq_result)
Exemplo n.º 2
0
    def testEqualWithGap(self):
        state = """\
0|4 0|5

0 x x 2
-     -
0 0|1 0
"""
        board1 = Board.create(state)
        board2 = Board.create(state)

        eq_result = (board1 == board2)
        neq_result = (board1 != board2)
        self.assertTrue(eq_result)
        self.assertFalse(neq_result)
Exemplo n.º 3
0
    def testCreateWithSpaces(self):
        board = Board.create("""\
            4
            -
3|1   4|6 4 1
          -
  2 4     4 2|5
  - -
  3 2   4|0 5
            -
  5 0|0 1|1 4
  -
  6 5|5 3|3 6|3
""")
        expected_display = """\
x x x x x x 4 x
            -
3|1 x 4|6 4 1 x
          -
x 2 4 x x 4 2|5
  - -
x 3 2 x 4|0 5 x
            -
x 5 0|0 1|1 4 x
  -
x 6 5|5 3|3 6|3
"""

        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
Exemplo n.º 4
0
    def testDisconnectedBeforeCapture(self):
        """ Board must be connected after move and after capture.

        Here, move 62L is disconnected after the move, but connected after
        the capture removes most of the dominoes. Test that the move is still
        not allowed.
        """
        board = Board.create("""\
x x x x 5
        -
x x 6|2 3

6|6 2|4 x
""")
        graph = CaptureBoardGraph()
        expected_states = set("""\
x x x x 5
        -
x x 6|2 3

6|6 2|4 x
""".split('---\n'))

        states = graph.walk(board)

        self.assertEqual(expected_states, states)
Exemplo n.º 5
0
    def testDisconnectedBeforeCapture(self):
        """ Board must be connected after move and after capture.

        Here, move 62L is disconnected after the move, but connected after
        the capture removes most of the dominoes. Test that the move is still
        not allowed.
        """
        board = Board.create("""\
x x x x 5
        -
x x 6|2 3

6|6 2|4 x
""")
        graph = CaptureBoardGraph()
        expected_states = set("""\
x x x x 5
        -
x x 6|2 3

6|6 2|4 x
""".split('---\n'))

        states = graph.walk(board)

        self.assertEqual(expected_states, states)
Exemplo n.º 6
0
    def testHasMatch(self):
        state = """\
1 2
- -
0 0
"""
        board = Board.create(state)

        self.assertTrue(board.hasMatch())
Exemplo n.º 7
0
    def testHasNoMatch(self):
        state = """\
1 0
- -
0 2
"""
        board = Board.create(state)

        self.assertFalse(board.hasMatch())
Exemplo n.º 8
0
    def testHasMatch(self):
        state = """\
1 2
- -
0 0
"""
        board = Board.create(state)

        self.assertTrue(board.hasMatch())
Exemplo n.º 9
0
    def testIsConnected(self):
        state = """\
1 0|2 x x
-
0 0|4 0|3
"""
        board = Board.create(state)

        self.assertTrue(board.isConnected())
Exemplo n.º 10
0
    def testIsNotConnected(self):
        state = """\
1 0|2 x x
-
0 x x 0|3
"""
        board = Board.create(state)

        self.assertFalse(board.isConnected())
Exemplo n.º 11
0
    def testHasNoLoner(self):
        state = """\
1 0 x 1|3
- -
0 2 x 0|3
"""
        board = Board.create(state)

        self.assertFalse(board.hasLoner())
Exemplo n.º 12
0
    def testIsConnected(self):
        state = """\
1 0|2 x x
-
0 0|4 0|3
"""
        board = Board.create(state)

        self.assertTrue(board.isConnected())
Exemplo n.º 13
0
    def testIsNotConnected(self):
        state = """\
1 0|2 x x
-
0 x x 0|3
"""
        board = Board.create(state)

        self.assertFalse(board.isConnected())
Exemplo n.º 14
0
    def testHasLoner(self):
        state = """\
1 0 x 1|2
- -
0 2 x 0|3
"""
        board = Board.create(state)

        self.assertTrue(board.hasLoner())
Exemplo n.º 15
0
    def testHasNoMatch(self):
        state = """\
1 0
- -
0 2
"""
        board = Board.create(state)

        self.assertFalse(board.hasMatch())
Exemplo n.º 16
0
    def testHasNoLoner(self):
        state = """\
1 0 x 1|3
- -
0 2 x 0|3
"""
        board = Board.create(state)

        self.assertFalse(board.hasLoner())
Exemplo n.º 17
0
    def testHasLoner(self):
        state = """\
1 0 x 1|2
- -
0 2 x 0|3
"""
        board = Board.create(state)

        self.assertTrue(board.hasLoner())
Exemplo n.º 18
0
    def testHasNoMatch(self):
        state = """\
1 0
- -
0 2
"""
        board = Board.create(state)
        domino = board[1][1].domino

        self.assertFalse(domino.hasMatch())
Exemplo n.º 19
0
    def testCreateRightEdge(self):
        state = """\
x 0|2

0|1 x
"""

        board = Board.create(state)

        self.assertMultiLineEqual(state, board.display())
Exemplo n.º 20
0
    def testCreateVertical(self):
        state = """\
1 0|2
-
0 x x
"""

        board = Board.create(state)

        self.assertMultiLineEqual(state, board.display())
Exemplo n.º 21
0
    def testDifferentAlignment(self):
        state1 = """\
0|4 0|5

0 0|3 2
-     -
0 0|1 0
"""
        state2 = """\
0|4 0|5

0 0 3 2
- - - -
0 0 1 0
"""
        board1 = Board.create(state1)
        board2 = Board.create(state2)

        self.assertNotEqual(board1, board2)
Exemplo n.º 22
0
    def testHasMatch(self):
        state = """\
1 2
- -
0 0
"""
        board = Board.create(state)
        domino = board[1][1].domino

        self.assertTrue(domino.hasMatch())
Exemplo n.º 23
0
    def testCreateRightEdge(self):
        state = """\
x 0|2

0|1 x
"""

        board = Board.create(state)

        self.assertMultiLineEqual(state, board.display())
Exemplo n.º 24
0
    def testCreateVertical(self):
        state = """\
1 0|2
-
0 x x
"""

        board = Board.create(state)

        self.assertMultiLineEqual(state, board.display())
Exemplo n.º 25
0
    def testDifferentAlignment(self):
        state1 = """\
0|4 0|5

0 0|3 2
-     -
0 0|1 0
"""
        state2 = """\
0|4 0|5

0 0 3 2
- - - -
0 0 1 0
"""
        board1 = Board.create(state1)
        board2 = Board.create(state2)

        self.assertNotEqual(board1, board2)
Exemplo n.º 26
0
    def testHasMatch(self):
        state = """\
1 2
- -
0 0
"""
        board = Board.create(state)
        domino = board[1][1].domino

        self.assertTrue(domino.hasMatch())
Exemplo n.º 27
0
    def testNoSolution(self):
        graph = CaptureBoardGraph()
        board = Board.create("""\
6|2 3
    -
2|4 5
""")
        graph.walk(board)

        self.assertRaises(NetworkXNoPath, graph.get_solution)
Exemplo n.º 28
0
    def testHasNoMatch(self):
        state = """\
1 0
- -
0 2
"""
        board = Board.create(state)
        domino = board[1][1].domino

        self.assertFalse(domino.hasMatch())
Exemplo n.º 29
0
    def testFindNoMatch(self):
        state = """\
1 0
- -
0 2
"""
        board = Board.create(state)
        matches = board.findMatches()
        expected_matches = []

        self.assertEqual(expected_matches, matches)
Exemplo n.º 30
0
    def testCreate(self):
        state = """\
0|2 x

0|1 x
"""

        board = Board.create(state)
        display = board.display()

        self.assertMultiLineEqual(state, display)
Exemplo n.º 31
0
    def testFindNoMatch(self):
        state = """\
1 0
- -
0 2
"""
        board = Board.create(state)
        matches = board.findMatches()
        expected_matches = []

        self.assertEqual(expected_matches, matches)
Exemplo n.º 32
0
    def testCreate(self):
        state = """\
0|2 x

0|1 x
"""

        board = Board.create(state)
        display = board.display()

        self.assertMultiLineEqual(state, display)
Exemplo n.º 33
0
    def testHasEvenGapsTwoUnevenGaps(self):
        state = """\
4|5 x 0
      -
1 2 6 5
- - -
0 3 1 x
"""
        board = Board.create(state)
        has_even_gaps = board.hasEvenGaps()

        self.assertFalse(has_even_gaps)
Exemplo n.º 34
0
    def testFindMatch(self):
        state = """\
1 2
- -
0 0
"""
        board = Board.create(state)
        matches = board.findMatches()
        coordinates = [(cell.x, cell.y) for cell in matches]
        expected_coordinates = [(0, 0), (1, 0)]

        self.assertEqual(expected_coordinates, coordinates)
Exemplo n.º 35
0
    def testWalkNoSplit(self):
        board = Board.create("""\
x 3|2 3|1 x
""")
        graph = BoardGraph()
        expected_states = set("""\
3|2 3|1
""".split('---\n'))

        states = graph.walk(board)

        self.assertEqual(expected_states, states)
Exemplo n.º 36
0
    def testHasEvenGapsTwoUnevenGaps(self):
        state = """\
4|5 x 0
      -
1 2 6 5
- - -
0 3 1 x
"""
        board = Board.create(state)
        has_even_gaps = board.hasEvenGaps()

        self.assertFalse(has_even_gaps)
Exemplo n.º 37
0
    def testFindMatch(self):
        state = """\
1 2
- -
0 0
"""
        board = Board.create(state)
        matches = board.findMatches()
        coordinates = [(cell.x, cell.y) for cell in matches]
        expected_coordinates = [(0, 0), (1, 0)]

        self.assertEqual(expected_coordinates, coordinates)
Exemplo n.º 38
0
    def testFindNeighbours(self):
        board = Board.create("""\
x 3|2

1|0 x
""")
        cell = board[1][0]
        expected_neighbours = {board[1][1]}

        neighbours = set(cell.find_neighbours())

        self.assertEqual(expected_neighbours, neighbours)
Exemplo n.º 39
0
    def testHasEvenGapsOneEvenGap(self):
        state = """\
4|5 6 0
    - -
1 2 1 5
- -
0 3 x x
"""
        board = Board.create(state)
        has_even_gaps = board.hasEvenGaps()

        self.assertTrue(has_even_gaps)
Exemplo n.º 40
0
    def testWalkNoSplit(self):
        board = Board.create("""\
x 3|2 3|1 x
""")
        graph = BoardGraph()
        expected_states = set("""\
3|2 3|1
""".split('---\n'))

        states = graph.walk(board)

        self.assertEqual(expected_states, states)
Exemplo n.º 41
0
    def testSolution(self):
        graph = CaptureBoardGraph()
        expected_solution = ['34u', '24r']
        board = Board.create("""\
6|2 3
    -
2|4 4
""")
        graph.walk(board)
        solution = graph.get_solution()

        self.assertEqual(expected_solution, solution)
Exemplo n.º 42
0
    def testFindNeighbours(self):
        board = Board.create("""\
x 3|2

1|0 x
""")
        cell = board[1][0]
        expected_neighbours = set([board[1][1]])

        neighbours = set(cell.findNeighbours())

        self.assertEqual(expected_neighbours, neighbours)
Exemplo n.º 43
0
    def testHasEvenGapsOneEvenGap(self):
        state = """\
4|5 6 0
    - -
1 2 1 5
- -
0 3 x x
"""
        board = Board.create(state)
        has_even_gaps = board.hasEvenGaps()

        self.assertTrue(has_even_gaps)
Exemplo n.º 44
0
    def testPartialSolution(self):
        graph = CaptureBoardGraph()
        expected_solution = ['62l']
        board = Board.create("""\
6|2 3
    -
2|4 5
""")
        graph.walk(board)

        solution = graph.get_solution(partial=True)

        self.assertEqual(expected_solution, solution)
Exemplo n.º 45
0
    def testBadMove(self):
        start_state = """\
0|2 x

0|1 x
"""
        board = Board.create(start_state)
        domino1 = board[0][0].domino

        with self.assertRaises(BoardError):
            domino1.move(-1, 0)

        self.assertMultiLineEqual(start_state, board.display())
Exemplo n.º 46
0
    def testPartialSolution(self):
        graph = CaptureBoardGraph()
        expected_solution = ['62l']
        board = Board.create("""\
6|2 3
    -
2|4 5
""")
        graph.walk(board)

        solution = graph.get_solution(return_partial=True)

        self.assertEqual(expected_solution, solution)
Exemplo n.º 47
0
    def testFindNeighbours(self):
        state = """\
1 0|2 x x
-
0 0|4 0|3
"""
        board = Board.create(state)
        domino1 = board[1][1].domino
        expected_neighbours = {board[0][1].domino, board[1][0].domino}

        neighbours = domino1.find_neighbours()

        self.assertEqual(expected_neighbours, neighbours)
Exemplo n.º 48
0
    def testFindNeighbours(self):
        state = """\
1 0|2 x x
-
0 0|4 0|3
"""
        board = Board.create(state)
        domino1 = board[1][1].domino
        expected_neighbours = set([board[0][1].domino, board[1][0].domino])

        neighbours = domino1.findNeighbours()

        self.assertEqual(expected_neighbours, neighbours)
Exemplo n.º 49
0
    def testDifferentPips(self):
        state1 = """\
0|4 0|5

0 0|3 2
-     -
0 0|1 0
"""
        state2 = """\
6|4 0|5

0 0|3 2
-     -
0 0|1 0
"""
        board1 = Board.create(state1)
        board2 = Board.create(state2)

        eq_result = (board1 == board2)
        neq_result = (board1 != board2)
        self.assertFalse(eq_result)
        self.assertTrue(neq_result)
Exemplo n.º 50
0
    def test_solution(self):
        board = Board.create("""\
1|2 3
    -
2|4 2
""")
        graph = BlockingBoardGraph()
        expected_solution = ['12l', '12l', '32u']

        graph.walk(board)
        solution = graph.get_solution()

        self.assertEqual(expected_solution, solution)
Exemplo n.º 51
0
    def test_choice_counts(self):
        board = Board.create("""\
1|2 3
    -
2|4 2
""")
        graph = BlockingBoardGraph()
        expected_counts = [1, 2, 2]

        graph.walk(board)
        counts = graph.get_choice_counts()

        self.assertEqual(expected_counts, counts)
Exemplo n.º 52
0
    def testDifferentPips(self):
        state1 = """\
0|4 0|5

0 0|3 2
-     -
0 0|1 0
"""
        state2 = """\
6|4 0|5

0 0|3 2
-     -
0 0|1 0
"""
        board1 = Board.create(state1)
        board2 = Board.create(state2)

        eq_result = (board1 == board2)
        neq_result = (board1 != board2)
        self.assertFalse(eq_result)
        self.assertTrue(neq_result)
Exemplo n.º 53
0
    def testBadMove(self):
        start_state = """\
0|2 x

0|1 x
"""
        board = Board.create(start_state)
        domino1 = board[0][0].domino

        with self.assertRaises(BoardError):
            domino1.move(-1, 0)

        self.assertMultiLineEqual(start_state, board.display())
Exemplo n.º 54
0
    def testSolution(self):
        graph = CaptureBoardGraph()
        expected_solution = ['34u', '24r']
        expected_closest = ''
        board = Board.create("""\
6|2 3
    -
2|4 4
""")
        graph.walk(board)
        solution = graph.get_solution()

        self.assertEqual(expected_solution, solution)
        self.assertEqual(expected_closest, graph.closest)
Exemplo n.º 55
0
    def testExtraDominoes(self):
        state = """\
0|0 x

1|1 x
"""
        max_pips = 2
        expected_extra_dominoes = [Domino(0, 1),
                                   Domino(0, 2),
                                   Domino(1, 2),
                                   Domino(2, 2)]

        board = Board.create(state, max_pips=max_pips)

        self.assertEqual(expected_extra_dominoes, board.extra_dominoes)
Exemplo n.º 56
0
    def testCreateWithOtherMarkers(self):
        state = """\
1 0?2
*
0 x x
"""
        expected_display = """\
1 0|2
-
0 x x
"""

        board = Board.create(state)

        self.assertMultiLineEqual(expected_display, board.display())
Exemplo n.º 57
0
    def testFillFailForMatching(self):
        """ Fail because all of the remaining dominoes have matches.
        """
        random = Random()
        start = """\
0 x x
-
0 1|1
"""
        board = Board.create(start, max_pips=1)

        result = board.fill(random, matches_allowed=False)

        self.assertFalse(result)
        self.assertMultiLineEqual(start, board.display())
Exemplo n.º 58
0
    def testCreateWithOtherMarkers(self):
        state = """\
1 0?2
*
0 x x
"""
        expected_display = """\
1 0|2
-
0 x x
"""

        board = Board.create(state)

        self.assertMultiLineEqual(expected_display, board.display())
Exemplo n.º 59
0
    def testFillFailForMatching(self):
        """ Fail because all of the remaining dominoes have matches.
        """
        random = Random()
        start = """\
0 x x
-
0 1|1
"""
        board = Board.create(start, max_pips=1)

        result = board.fill(random, matches_allowed=False)

        self.assertFalse(result)
        self.assertMultiLineEqual(start, board.display())
Exemplo n.º 60
0
    def testDisplayCropped(self):
        board = Board.create("""\
3 x x x
-
2 0|2 x

x x x x
""")
        expected_display = """\
3 x x
-
2 0|2
"""

        self.assertMultiLineEqual(expected_display,
                                  board.display(cropped=True))