Esempio n. 1
0
class TestNextTile(ut.TestCase):
    def setUp(self):
        self.board = BoardModel(15)

    def test_horizontal_first(self):
        self.assertEqual((0, 1),
                         self.board.next_tile(0, 0, Direction.HORIZONTAL))

    def test_horizontal_one_but_last(self):
        self.assertEqual((14, 14),
                         self.board.next_tile(14, 13, Direction.HORIZONTAL))

    def test_vertical_first(self):
        self.assertEqual((1, 0), self.board.next_tile(0, 0,
                                                      Direction.VERTICAL))

    def test_vertical_one_but_last(self):
        self.assertEqual((14, 14),
                         self.board.next_tile(13, 14, Direction.VERTICAL))

    def test_diagonal_a_first(self):
        self.assertEqual((1, 0),
                         self.board.next_tile(0, 1, Direction.DIAGONAL_A))

    def test_diagonal_a_one_but_last(self):
        self.assertEqual((14, 13),
                         self.board.next_tile(13, 14, Direction.DIAGONAL_A))

    def test_diagonal_a_center(self):
        self.assertEqual((14, 0),
                         self.board.next_tile(13, 1, Direction.DIAGONAL_A))

    def test_diagonal_b_first(self):
        self.assertEqual((14, 1),
                         self.board.next_tile(13, 0, Direction.DIAGONAL_B))

    def test_diagonal_b_one_but_last(self):
        self.assertEqual((1, 14),
                         self.board.next_tile(0, 13, Direction.DIAGONAL_B))

    def test_diagonal_b_center(self):
        self.assertEqual((14, 14),
                         self.board.next_tile(13, 13, Direction.DIAGONAL_B))
Esempio n. 2
0
class TestPlace(ut.TestCase):
    def setUp(self):
        self.board = BoardModel(15)

    def test_circle(self):
        self.board.place(0, 0, TileModel.Symbols.CIRCLE)
        self.assertEqual(TileModel.Symbols.CIRCLE,
                         self.board[0][0].symbol.get())

    def test_cross(self):
        self.board.place(1, 0, TileModel.Symbols.CROSS)
        self.assertEqual(TileModel.Symbols.CROSS,
                         self.board[1][0].symbol.get())

    def test_invalid(self):
        self.board.place(0, 0, TileModel.Symbols.CIRCLE)
        self.board.place(0, 0, TileModel.Symbols.CROSS)
        self.assertEqual(TileModel.Symbols.CIRCLE,
                         self.board[0][0].symbol.get())
Esempio n. 3
0
class TestAllEmpty(unittest.TestCase):
    def setUp(self) -> None:
        self.board = BoardModel(3)

    def test_empty(self):
        expected = [
            (0, 0),
            (0, 1),
            (0, 2),
            (1, 0),
            (1, 1),
            (1, 2),
            (2, 0),
            (2, 1),
            (2, 2),
        ]

        res = [(a.x, a.y) for a in all_empty_tiles(self.board)]
        self.assertEqual(res, expected)

    def test_full(self):
        # Fill all positions
        for i in range(3):
            for j in range(3):
                self.board.place(i, j, TileModel.Symbols.CIRCLE)

        expected = []

        res = [(a.x, a.y) for a in all_empty_tiles(self.board)]
        self.assertEqual(res, expected)

    def test_half_full(self):  # I'm an optimist ;)
        self.board.place(0, 0, TileModel.Symbols.CIRCLE)
        self.board.place(2, 0, TileModel.Symbols.CIRCLE)
        self.board.place(2, 2, TileModel.Symbols.CIRCLE)
        self.board.place(1, 2, TileModel.Symbols.CROSS)
        self.board.place(1, 1, TileModel.Symbols.CROSS)

        expected = [(0, 1), (0, 2), (1, 0), (2, 1)]

        res = [(a.x, a.y) for a in all_empty_tiles(self.board)]
        self.assertEqual(expected, res)
Esempio n. 4
0
 def setUp(self) -> None:
     self.board = BoardModel(3)
Esempio n. 5
0
 def setUp(self):
     self.board = BoardModel(15)
Esempio n. 6
0
 def setUp(self) -> None:
     self.board = BoardModel(15)
     self.rater = SimpleRater()
Esempio n. 7
0
class TestSimpleRater(unittest.TestCase):
    def setUp(self) -> None:
        self.board = BoardModel(15)
        self.rater = SimpleRater()

    def test_empty(self):
        rating = self.rater.rate(self.board)
        self.assertEqual(rating, 0)

    def test_couples(self):
        self.board.place(0, 0, TileModel.Symbols.CROSS)
        self.board.place(1, 0, TileModel.Symbols.CROSS)
        self.board.place(3, 0, TileModel.Symbols.CROSS)
        self.board.place(4, 0, TileModel.Symbols.CROSS)
        self.board.place(6, 0, TileModel.Symbols.CIRCLE)
        self.board.place(7, 0, TileModel.Symbols.CIRCLE)

        rating = self.rater.rate(self.board)

        self.assertEqual(rating, 5)  # Replace with a constant?

    def test_win(self):
        self.board.place(0, 0, TileModel.Symbols.CROSS)
        self.board.place(0, 1, TileModel.Symbols.CROSS)
        self.board.place(0, 2, TileModel.Symbols.CROSS)
        self.board.place(0, 3, TileModel.Symbols.CROSS)
        self.board.place(0, 4, TileModel.Symbols.CROSS)

        rating = self.rater.rate(self.board)
        self.assertEqual(rating, 99999)  # Replace with a constant?