Пример #1
0
 def test_calculate_score_triple_word(self):
     game = Game()
     score = game.calculate_score([
         (0, Board.MIDDLE[1], self.A),
         (0, Board.MIDDLE[1] + 1, self.A),
     ])
     self.assertEqual(score, 6)
Пример #2
0
 def test_calculate_score_triple_letter(self):
     game = Game()
     score = game.calculate_score([
         (Board.MIDDLE[0] - 2, Board.MIDDLE[1] + 1, self.A),
         (Board.MIDDLE[0] - 2, Board.MIDDLE[1] + 2, self.A),
     ])
     self.assertEqual(score, 4)
Пример #3
0
 def test_calculate_score_double_letter(self):
     game = Game()
     score = game.calculate_score([
         (Board.MIDDLE[0] - 1, Board.MIDDLE[1], self.A),
         (Board.MIDDLE[0] - 1, Board.MIDDLE[1] + 1, self.A),
     ])
     self.assertEqual(score, 3)
Пример #4
0
 def test_is_valid_invalid_orientation(self):
     game = Game()
     is_valid = game.is_valid_play([
         Board.MIDDLE, (Board.MIDDLE[0], Board.MIDDLE[1] + 1),
         (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 1)
     ], Orientation.NONE)
     self.assertEqual(is_valid, ValidationReason.INVALID_ORIENTATION)
Пример #5
0
 def test_is_valid_vertical_true(self):
     game = Game()
     is_valid = game.is_valid_play([
         Board.MIDDLE, (Board.MIDDLE[0] + 1, Board.MIDDLE[1]),
         (Board.MIDDLE[0] + 2, Board.MIDDLE[1])
     ], Orientation.VERTICAL)
     self.assertEqual(is_valid, ValidationReason.VALID)
Пример #6
0
 def test_is_valid_not_adjacent(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     game.board.is_empty = False
     is_valid = game.is_valid_play([(Board.MIDDLE[0] + 5, Board.MIDDLE[1])],
                                   Orientation.HORIZONTAL)
     self.assertEqual(is_valid, ValidationReason.NOT_ADJACENT)
Пример #7
0
 def test_is_valid_first_play_not_on_middle(self):
     game = Game()
     is_valid = game.is_valid_play([(Board.MIDDLE[0], Board.MIDDLE[1] + 1),
                                    (Board.MIDDLE[0], Board.MIDDLE[1] + 2)],
                                   Orientation.HORIZONTAL)
     self.assertEqual(is_valid,
                      ValidationReason.FIRST_PLAY_NOT_ON_MIDDLE_CELL)
Пример #8
0
 def test_is_adjacent_above_below(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     game.board[Board.MIDDLE[0] + 2][Board.MIDDLE[1]] = self.B
     direction = game.is_adjacent((Board.MIDDLE[0] + 1, Board.MIDDLE[1]))
     self.assertEqual(direction,
                      AdjacentDirection.ABOVE | AdjacentDirection.BELOW)
Пример #9
0
 def test_is_valid_noncontiguous_horizontal(self):
     game = Game()
     is_valid = game.is_valid_play([
         Board.MIDDLE, (Board.MIDDLE[0], Board.MIDDLE[1] + 1),
         (Board.MIDDLE[0], Board.MIDDLE[1] + 3)
     ], Orientation.HORIZONTAL)
     self.assertEqual(is_valid, ValidationReason.NOT_CONTIGUOUS)
Пример #10
0
 def test_is_adjacent_left_right(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] + 2] = self.B
     direction = game.is_adjacent((Board.MIDDLE[0], Board.MIDDLE[1] + 1))
     self.assertEqual(direction,
                      AdjacentDirection.LEFT | AdjacentDirection.RIGHT)
Пример #11
0
 def test_is_valid_noncontiguous_vertical(self):
     game = Game()
     is_valid = game.is_valid_play([
         Board.MIDDLE, (Board.MIDDLE[0] + 1, Board.MIDDLE[1]),
         (Board.MIDDLE[0] + 3, Board.MIDDLE[1])
     ], Orientation.VERTICAL)
     self.assertEqual(is_valid, ValidationReason.NOT_CONTIGUOUS)
Пример #12
0
 def test_is_valid_horizontal_true(self):
     game = Game()
     is_valid = game.is_valid_play([
         Board.MIDDLE, (Board.MIDDLE[0], Board.MIDDLE[1] + 1),
         (Board.MIDDLE[0], Board.MIDDLE[1] + 2)
     ], Orientation.HORIZONTAL)
     self.assertEqual(is_valid, ValidationReason.VALID)
Пример #13
0
 def test_is_adjacent_below_right(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     game.board[Board.MIDDLE[0] - 1][Board.MIDDLE[1] + 1] = self.B
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] + 1] = self.C
     direction = game.is_adjacent((Board.MIDDLE[0] - 1, Board.MIDDLE[1]))
     self.assertEqual(direction,
                      AdjacentDirection.BELOW | AdjacentDirection.RIGHT)
Пример #14
0
 def test_is_valid_prefix_suffix_horizontal(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     game.board.is_empty = False
     is_valid = game.is_valid_play([(Board.MIDDLE[0], Board.MIDDLE[1] - 1),
                                    (Board.MIDDLE[0], Board.MIDDLE[1] + 1)],
                                   Orientation.HORIZONTAL)
     self.assertEqual(is_valid, ValidationReason.VALID)
Пример #15
0
 def test_is_valid_prefix_suffix_vertical(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     game.board.is_empty = False
     is_valid = game.is_valid_play([(Board.MIDDLE[0] - 1, Board.MIDDLE[1]),
                                    (Board.MIDDLE[0] + 1, Board.MIDDLE[1])],
                                   Orientation.VERTICAL)
     self.assertEqual(is_valid, ValidationReason.VALID)
Пример #16
0
 def test_is_adjacent_above_left(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     game.board[Board.MIDDLE[0] + 1][Board.MIDDLE[1]] = self.B
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] + 1] = self.C
     direction = game.is_adjacent(
         (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 1))
     self.assertEqual(direction,
                      AdjacentDirection.ABOVE | AdjacentDirection.LEFT)
Пример #17
0
 def test_get_contiguous_right(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] + 1] = self.R
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] + 2] = self.R
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] + 3] = self.R
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] + 5] = self.R
     word = game.get_contiguous_cells(Board.MIDDLE, AdjacentDirection.RIGHT)
     self.assertListEqual(word,
                          [(Board.MIDDLE[0], Board.MIDDLE[1] + 1, self.R),
                           (Board.MIDDLE[0], Board.MIDDLE[1] + 2, self.R),
                           (Board.MIDDLE[0], Board.MIDDLE[1] + 3, self.R)])
Пример #18
0
 def test_get_contiguous_left(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] - 1] = self.L
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] - 2] = self.L
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] - 3] = self.L
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] - 5] = self.L
     word = game.get_contiguous_cells(Board.MIDDLE, AdjacentDirection.LEFT)
     self.assertListEqual(word,
                          [(Board.MIDDLE[0], Board.MIDDLE[1] - 3, self.L),
                           (Board.MIDDLE[0], Board.MIDDLE[1] - 2, self.L),
                           (Board.MIDDLE[0], Board.MIDDLE[1] - 1, self.L)])
Пример #19
0
 def test_get_contiguous_below(self):
     game = Game()
     game.board[Board.MIDDLE[0] + 1][Board.MIDDLE[1]] = self.B
     game.board[Board.MIDDLE[0] + 2][Board.MIDDLE[1]] = self.B
     game.board[Board.MIDDLE[0] + 3][Board.MIDDLE[1]] = self.B
     game.board[Board.MIDDLE[0] + 5][Board.MIDDLE[1]] = self.B
     word = game.get_contiguous_cells(Board.MIDDLE, AdjacentDirection.BELOW)
     self.assertListEqual(word,
                          [(Board.MIDDLE[0] + 1, Board.MIDDLE[1], self.B),
                           (Board.MIDDLE[0] + 2, Board.MIDDLE[1], self.B),
                           (Board.MIDDLE[0] + 3, Board.MIDDLE[1], self.B)])
Пример #20
0
 def test_get_contiguous_above(self):
     game = Game()
     game.board[Board.MIDDLE[0] - 1][Board.MIDDLE[1]] = self.A
     game.board[Board.MIDDLE[0] - 2][Board.MIDDLE[1]] = self.A
     game.board[Board.MIDDLE[0] - 3][Board.MIDDLE[1]] = self.A
     game.board[Board.MIDDLE[0] - 5][Board.MIDDLE[1]] = self.A
     word = game.get_contiguous_cells(Board.MIDDLE, AdjacentDirection.ABOVE)
     self.assertListEqual(word,
                          [(Board.MIDDLE[0] - 3, Board.MIDDLE[1], self.A),
                           (Board.MIDDLE[0] - 2, Board.MIDDLE[1], self.A),
                           (Board.MIDDLE[0] - 1, Board.MIDDLE[1], self.A)])
Пример #21
0
 def test_calculate_score_bingo(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     score = game.calculate_score([
         (Board.MIDDLE[0] + 1, Board.MIDDLE[1], self.A),
         (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 1, self.A),
         (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 2, self.A),
         (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 3, self.A),
         (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 4, self.A),
         (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 5, self.A),
         (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 6, self.A)
     ])
     self.assertEqual(score, 59)
Пример #22
0
 def test_find_words_extend_right(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] - 1] = self.L
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] - 2] = self.L
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] - 3] = self.L
     game.board.is_empty = False
     words = game.find_words(
         Orientation.HORIZONTAL,
         [(Board.MIDDLE[0], Board.MIDDLE[0], self.A),
          (Board.MIDDLE[0], Board.MIDDLE[0] + 1, self.A)])
     self.assertListEqual(
         words, [[(Board.MIDDLE[0], Board.MIDDLE[1] - 3, self.L),
                  (Board.MIDDLE[0], Board.MIDDLE[1] - 2, self.L),
                  (Board.MIDDLE[0], Board.MIDDLE[1] - 1, self.L),
                  (Board.MIDDLE[0], Board.MIDDLE[1], self.A),
                  (Board.MIDDLE[0], Board.MIDDLE[1] + 1, self.A)]])
Пример #23
0
 def test_find_words_extend_below(self):
     game = Game()
     game.board[Board.MIDDLE[0] - 1][Board.MIDDLE[1]] = self.A
     game.board[Board.MIDDLE[0] - 2][Board.MIDDLE[1]] = self.A
     game.board[Board.MIDDLE[0] - 3][Board.MIDDLE[1]] = self.A
     game.board.is_empty = False
     words = game.find_words(
         Orientation.VERTICAL,
         [(Board.MIDDLE[0], Board.MIDDLE[1], self.A),
          (Board.MIDDLE[1] + 1, Board.MIDDLE[1], self.A)])
     self.assertListEqual(
         words, [[(Board.MIDDLE[0] - 3, Board.MIDDLE[1], self.A),
                  (Board.MIDDLE[0] - 2, Board.MIDDLE[1], self.A),
                  (Board.MIDDLE[0] - 1, Board.MIDDLE[1], self.A),
                  (Board.MIDDLE[0], Board.MIDDLE[1], self.A),
                  (Board.MIDDLE[0] + 1, Board.MIDDLE[1], self.A)]])
Пример #24
0
 def test_find_words_vertical_parallel(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.B
     game.board[Board.MIDDLE[0] + 1][Board.MIDDLE[1]] = self.B
     game.board.is_empty = False
     words = game.find_words(
         Orientation.VERTICAL,
         [(Board.MIDDLE[0], Board.MIDDLE[1] + 1, self.A),
          (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 1, self.A)])
     self.assertListEqual(
         words, [[(Board.MIDDLE[0], Board.MIDDLE[1] + 1, self.A),
                  (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 1, self.A)],
                 [(Board.MIDDLE[0], Board.MIDDLE[1], self.B),
                  (Board.MIDDLE[0], Board.MIDDLE[1] + 1, self.A)],
                 [(Board.MIDDLE[0] + 1, Board.MIDDLE[1], self.B),
                  (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 1, self.A)]])
Пример #25
0
 def test_find_words_horizontal_parallel(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.R
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] + 1] = self.R
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1] + 2] = self.R
     game.board.is_empty = False
     words = game.find_words(
         Orientation.HORIZONTAL,
         [(Board.MIDDLE[0] + 1, Board.MIDDLE[1], self.A),
          (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 1, self.A)])
     self.assertListEqual(
         words, [[(Board.MIDDLE[0] + 1, Board.MIDDLE[1], self.A),
                  (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 1, self.A)],
                 [(Board.MIDDLE[0], Board.MIDDLE[1], self.R),
                  (Board.MIDDLE[0] + 1, Board.MIDDLE[1], self.A)],
                 [(Board.MIDDLE[0], Board.MIDDLE[1] + 1, self.R),
                  (Board.MIDDLE[0] + 1, Board.MIDDLE[1] + 1, self.A)]])
Пример #26
0
 def test_is_valid_cell_full(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     game.board.is_empty = False
     is_valid = game.is_valid_play([Board.MIDDLE], Orientation.HORIZONTAL)
     self.assertEqual(is_valid, ValidationReason.CELL_ALREADY_FULL)
Пример #27
0
 def test_is_valid_first_play_too_short(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     is_valid = game.is_valid_play([Board.MIDDLE], Orientation.HORIZONTAL)
     self.assertEqual(is_valid, ValidationReason.FIRST_PLAY_TOO_FEW_TILES)
Пример #28
0
 def test_get_contiguous_none(self):
     game = Game()
     word = game.get_contiguous_cells(Board.MIDDLE, AdjacentDirection.LEFT)
     self.assertListEqual(word, [])
Пример #29
0
 def test_calculate_score_simple(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     score = game.calculate_score([(Board.MIDDLE[0], Board.MIDDLE[1] + 1,
                                    self.A)])
     self.assertEqual(score, 1)
Пример #30
0
 def test_is_adjacent_below(self):
     game = Game()
     game.board[Board.MIDDLE[0]][Board.MIDDLE[1]] = self.A
     direction = game.is_adjacent((Board.MIDDLE[0] - 1, Board.MIDDLE[1]))
     self.assertEqual(direction, AdjacentDirection.BELOW)