def testFillWithBacktrack(self, mock_choose):
        """ Force a backtrack.

        This scenario will get to the following grid and then be forced to
        backtrack, because the gaps are size 1 and 3: odd.
        x 3 x x
          -
        0 0 x 2
        -     -
        0 0|1 0
        """
        mock_choose.side_effect = [[Domino(0, 0)], [Domino(0, 1)],
                                   [Domino(0, 2)], [Domino(0, 3)],
                                   [Domino(0, 3)], [Domino(0, 3)],
                                   [Domino(0, 3)], [Domino(0, 4)],
                                   [Domino(0, 5)]]
        dummy_random = DummyRandom(randints={(0, 3): [1, 0, 1,
                                                      1]})  # directions
        board = Board(4, 3, max_pips=6)
        expected_display = """\
0|4 0|5

0 0|3 2
-     -
0 0|1 0
"""

        board.fill(dummy_random)
        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
    def testAddCell(self):
        board = Board(4, 3)

        board.add(Cell(4), 1, 2)
        cell = board[1][2]

        self.assertEqual(4, cell.pips)
    def testAddDomino(self):
        board = Board(4, 3)
        board.add(Domino(5, 6), 1, 2)

        pips = board[1][2].pips

        self.assertEqual(5, pips)
    def testAddDomino(self):
        board = Board(4, 3)
        board.add(Domino(5, 6), 1, 2)

        pips = board[1][2].pips

        self.assertEqual(5, pips)
示例#5
0
    def testFillWithBacktrack(self, mock_choose):
        """ Force a backtrack.

        This scenario will get to the following grid and then be forced to
        backtrack, because the gaps are size 1 and 3: odd.
        x 3 x x
          -
        0 0 x 2
        -     -
        0 0|1 0
        """
        mock_choose.side_effect = [[Domino(0, 0)],
                                   [Domino(0, 1)],
                                   [Domino(0, 2)],
                                   [Domino(0, 3)],
                                   [Domino(0, 3)],
                                   [Domino(0, 3)],
                                   [Domino(0, 3)],
                                   [Domino(0, 4)],
                                   [Domino(0, 5)]]
        dummy_random = DummyRandom(
            randints={(0, 3): [1, 0, 1, 1]})  # directions
        board = Board(4, 3, max_pips=6)
        expected_display = """\
0|4 0|5

0 0|3 2
-     -
0 0|1 0
"""

        board.fill(dummy_random)
        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
    def testFillWithBacktrack(self):
        """ Force a backtrack.

        This scenario will get to the following grid and then be forced to
        backtrack.
        x 3 4 x
          - -
        0 0 0 2
        -     -
        0 0|1 0
        """
        dummy_random = DummyRandom(
            randints={(0, 4): [1, 0, 1, 1]},  # directions
            choiceDominoes=[Domino(0, 0),
                            Domino(0, 1),
                            Domino(0, 2),
                            Domino(0, 3),
                            Domino(0, 4),
                            Domino(0, 5),
                            Domino(0, 4),
                            Domino(0, 5)])
        board = Board(4, 3, max_pips=6)
        expected_display = """\
0|4 0|5

0 0|3 2
-     -
0 0|1 0
"""

        board.fill(dummy_random)
        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
    def testAddCell(self):
        board = Board(4, 3)

        board.add(Cell(4), 1, 2)
        cell = board[1][2]

        self.assertEqual(4, cell.pips)
    def testRemove(self):
        board = Board(3, 4)
        domino1 = Domino(1, 5)
        board.add(domino1, 0, 0)

        board.remove(domino1)

        self.assertEqual([], board.dominoes)
    def testRemoveAndRotate(self):
        board = Board(3, 4)
        domino1 = Domino(1, 5)
        board.add(domino1, 0, 0)

        board.remove(domino1)
        domino1.rotate(270)

        self.assertEqual(270, domino1.degrees)
    def testFlip(self):
        board = Board(3, 2, max_pips=6)
        domino1 = Domino(1, 5)
        expected_display = """\
x x x

5|1 x
"""

        board.add(domino1, 0, 0)
        domino1.flip()

        self.assertMultiLineEqual(expected_display, board.display())
示例#11
0
    def testFlip(self):
        board = Board(3, 2, max_pips=6)
        domino1 = Domino(1, 5)
        expected_display = """\
x x x

5|1 x
"""

        board.add(domino1, 0, 0)
        domino1.flip()

        self.assertMultiLineEqual(expected_display, board.display())
    def testFillWithRandomDomino(self, mock_choose):
        mock_choose.side_effect = [[Domino(0, 5)], [Domino(0, 2)]]
        dummy_random = DummyRandom(randints={(0, 3): [1, 1]})  # directions
        board = Board(2, 2, max_pips=6)
        expected_display = """\
5 2
- -
0 0
"""

        board.fill(dummy_random)
        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
示例#13
0
    def testDisplay(self):
        board = Board(4, 3)
        board.add(Domino(5, 6), 1, 2)
        expected_display = """\
x 5|6 x

x x x x

x x x x
"""

        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
    def testDisplay(self):
        board = Board(4, 3)
        board.add(Domino(5, 6), 1, 2)
        expected_display = """\
x 5|6 x

x x x x

x x x x
"""

        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
    def testFillWithNoMatchesNext(self, mock_choose):
        mock_choose.side_effect = [[Domino(0, 5)],
                                   [Domino(0, 0), Domino(0, 1)]]
        dummy_random = DummyRandom(randints={(0, 3): [1, 1]})  # directions
        board = Board(2, 2, max_pips=6)
        expected_display = """\
5 0
- -
0 1
"""

        board.fill(dummy_random, matches_allowed=False)
        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
示例#16
0
    def testFillWithNoMatchesNext(self, mock_choose):
        mock_choose.side_effect = [[Domino(0, 5)],
                                   [Domino(0, 0), Domino(0, 1)]]
        dummy_random = DummyRandom(randints={(0, 3): [1, 1]})  # directions
        board = Board(2, 2, max_pips=6)
        expected_display = """\
5 0
- -
0 1
"""

        board.fill(dummy_random, matches_allowed=False)
        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
示例#17
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)
示例#18
0
    def testFillWithRandomDomino(self):
        dummy_random = DummyRandom(randints={(0, 4): [1, 1]},  # directions
                                   choiceDominoes=[Domino(0, 5),
                                                   Domino(0, 2)])
        board = Board(2, 2, max_pips=6)
        expected_display = """\
5 2
- -
0 0
"""

        board.fill(dummy_random)
        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
    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)
示例#20
0
    def testFillWithRandomDomino(self, mock_choose):
        mock_choose.side_effect = [[Domino(0, 5)],
                                   [Domino(0, 2)]]
        dummy_random = DummyRandom(randints={(0, 3): [1, 1]})  # directions
        board = Board(2, 2, max_pips=6)
        expected_display = """\
5 2
- -
0 0
"""

        board.fill(dummy_random)
        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
示例#21
0
    def testRotateAndAdd(self):
        board = Board(4, 3)
        domino1 = Domino(5, 6)
        domino1.rotate(-90)
        board.add(domino1, 1, 2)
        expected_display = """\
x 5 x x
  -
x 6 x x

x x x x
"""

        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
    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)
示例#23
0
    def testFillWithFlip(self):
        dummy_random = DummyRandom(randints={(0, 4): [1, 1],   # directions
                                             (0, 1): [1, 0]},  # flips
                                   choiceDominoes=[Domino(0, 0),
                                                   Domino(0, 1)])
        board = Board(2, 2, max_pips=6)
        expected_display = """\
0 0
- -
0 1
"""

        board.fill(dummy_random)
        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
示例#24
0
    def testMoveLeft(self):
        board = Board(4, 3)
        domino1 = Domino(5, 6)
        board.add(domino1, 1, 2)
        domino1.move(-1, 0)
        expected_display = """\
5|6 x x

x x x x

x x x x
"""

        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
示例#25
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)
    def testRotateAndAdd(self):
        board = Board(4, 3)
        domino1 = Domino(5, 6)
        domino1.rotate(-90)
        board.add(domino1, 1, 2)
        expected_display = """\
x 5 x x
  -
x 6 x x

x x x x
"""

        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
    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)
    def testMoveLeft(self):
        board = Board(4, 3)
        domino1 = Domino(5, 6)
        board.add(domino1, 1, 2)
        domino1.move(-1, 0)
        expected_display = """\
5|6 x x

x x x x

x x x x
"""

        display = board.display()

        self.assertMultiLineEqual(expected_display, display)
    def testHasNoMatch(self):
        state = """\
1 0
- -
0 2
"""
        board = Board.create(state)

        self.assertFalse(board.hasMatch())
示例#30
0
    def testHasNoMatch(self):
        state = """\
1 0
- -
0 2
"""
        board = Board.create(state)

        self.assertFalse(board.hasMatch())
示例#31
0
    def testHasMatch(self):
        state = """\
1 2
- -
0 0
"""
        board = Board.create(state)

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

        self.assertTrue(board.isConnected())
示例#33
0
    def testIsNotConnected(self):
        state = """\
1 0|2 x x
-
0 x x 0|3
"""
        board = Board.create(state)

        self.assertFalse(board.isConnected())
示例#34
0
    def testHasNoLoner(self):
        state = """\
1 0 x 1|3
- -
0 2 x 0|3
"""
        board = Board.create(state)

        self.assertFalse(board.hasLoner())
    def testHasNoLoner(self):
        state = """\
1 0 x 1|3
- -
0 2 x 0|3
"""
        board = Board.create(state)

        self.assertFalse(board.hasLoner())
示例#36
0
    def testHasLoner(self):
        state = """\
1 0 x 1|2
- -
0 2 x 0|3
"""
        board = Board.create(state)

        self.assertTrue(board.hasLoner())
    def testHasMatch(self):
        state = """\
1 2
- -
0 0
"""
        board = Board.create(state)

        self.assertTrue(board.hasMatch())
    def testHasLoner(self):
        state = """\
1 0 x 1|2
- -
0 2 x 0|3
"""
        board = Board.create(state)

        self.assertTrue(board.hasLoner())
    def testIsNotConnected(self):
        state = """\
1 0|2 x x
-
0 x x 0|3
"""
        board = Board.create(state)

        self.assertFalse(board.isConnected())
示例#40
0
    def testIsConnected(self):
        state = """\
1 0|2 x x
-
0 0|4 0|3
"""
        board = Board.create(state)

        self.assertTrue(board.isConnected())
示例#41
0
    def testCreateRightEdge(self):
        state = """\
x 0|2

0|1 x
"""

        board = Board.create(state)

        self.assertMultiLineEqual(state, board.display())
示例#42
0
    def testHasNoMatch(self):
        state = """\
1 0
- -
0 2
"""
        board = Board.create(state)
        domino = board[1][1].domino

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

0|1 x
"""

        board = Board.create(state)

        self.assertMultiLineEqual(state, board.display())
示例#44
0
    def testHasMatch(self):
        state = """\
1 2
- -
0 0
"""
        board = Board.create(state)
        domino = board[1][1].domino

        self.assertTrue(domino.hasMatch())
    def testCreateVertical(self):
        state = """\
1 0|2
-
0 x x
"""

        board = Board.create(state)

        self.assertMultiLineEqual(state, board.display())
示例#46
0
    def testCreateVertical(self):
        state = """\
1 0|2
-
0 x x
"""

        board = Board.create(state)

        self.assertMultiLineEqual(state, board.display())
    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)
    def testHasNoMatch(self):
        state = """\
1 0
- -
0 2
"""
        board = Board.create(state)
        domino = board[1][1].domino

        self.assertFalse(domino.hasMatch())
    def testHasMatch(self):
        state = """\
1 2
- -
0 0
"""
        board = Board.create(state)
        domino = board[1][1].domino

        self.assertTrue(domino.hasMatch())
示例#50
0
    def testNoSolution(self):
        graph = CaptureBoardGraph()
        board = Board.create("""\
6|2 3
    -
2|4 5
""")
        graph.walk(board)

        self.assertRaises(NetworkXNoPath, graph.get_solution)
示例#51
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)
示例#52
0
    def testFindNoMatch(self):
        state = """\
1 0
- -
0 2
"""
        board = Board.create(state)
        matches = board.findMatches()
        expected_matches = []

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

0|1 x
"""

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

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

        self.assertEqual(expected_matches, matches)
示例#55
0
    def testCreate(self):
        state = """\
0|2 x

0|1 x
"""

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

        self.assertMultiLineEqual(state, display)
    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)
    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)
    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)
    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)
    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)