def test_count_blocks(self): board = b.FieldState(2, 2, 2) board.board = [[1, 2], [1, 2]] board.count_blocks() excpected = [1, 1] ans = board.rest_block self.assertListEqual(excpected, ans)
def test_steps(self): board = b.FieldState(2, 2, 1) ans = False board.start_game() for x in range(len(board.board)): for y in range(len(board.board[0])): if len(board.logic.find_block(board.board, x, y)) > 1: ans = True break self.assertEqual(True, ans)
def test_delete_full_lines(self): logic = b.Logic(4) for i in range(9): for j in range(9): logic.board[i][j] = 1 logic.delete_lines(logic.find_full_lines()) board = [] for i in range(24): board.append(9 * [0]) self.assertEqual(board, logic.board)
def test_count_possible_score(self): board = b.FieldState(2, 2, 2) board.start_game() board.board = [[1, 2], [1, 2]] p = Thread(target=board.count_possible_score, args=(deepcopy(board.board), 0), daemon=True) p.start() p.join(3) board.stop_calculating = True self.assertNotEquals(0, board.max_score)
def test_shift_left(self): logic = b.Logic(4) new_board = [] for i in range(24): new_board.append([]) for j in range(9): new_board[i] = deepcopy(logic.board[i]) new_board[i].pop(0) new_board[i].append(0) logic.shift_left() self.assertEqual(new_board, logic.board)
def test_shift_down(self): board = b.FieldState(2, 2, 1) board.board = [[1, 2], [1, 2]] board.logic.shift(board.board, board.logic.find_block(board.board, 1, 1)) excpected = [[1], [1]] ans = [] for i in range(len(board.board)): ans.append([]) for j in range(len(board.board[0])): ans[i].append(board.board[i][j]) self.assertListEqual(excpected, ans)
def test_move_zigzag_last_line(self): logic = b.Logic(1, True) for i in range(len(logic.board[-1])): if logic.board[-1][i] != -1: logic.board[-1][i] = 1 board = deepcopy(logic.board) for i in range(len(board[-1])): if board[-1][i] == 1: board[-1][i] = 0 logic.delete_zigzag_lines([-1]) self.assertEqual(board[4:], logic.board[4:])
def test_move(self): logic = b.Logic(4) for i in range(9): logic.move() for i in range(9): self.assertEqual(logic.board[i], [0] * 9) for i in range(14, 20): self.assertEqual(logic.board[i], [0] * 9) _sum = 0 for i in range(9, 14): _sum += sum(logic.board[i]) self.assertEqual(_sum != 0, True)
def test_set_figure(self): logic = b.Logic(4) new_board = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]] for i in range(20): new_board.append([0] * 9) logic.board = deepcopy(new_board) logic.next_figure = SquareFigure() logic.current_figure = SquareFigure() logic.next_color = 1 logic.set_figure() self.assertEqual(new_board, logic.board)
def test_no_steps(self): board = b.FieldState(2, 2, 1) board.board = [[1, 2], [2, 1]] ans = board.no_steps(board.board) self.assertEqual(True, ans)
import sys from Logic import Field from PyQt5.QtWidgets import QWidget, QApplication from Graphics import Scene numV, numP, numW = 10, 8, 6 field = Field(numV, numP, numW) if __name__ == '__main__': app = QApplication([]) scene = Scene(field) sys.exit(app.exec_())
def test_find_full_lines(self): logic = b.Logic(4) for i in range(9): for j in range(9): logic.board[i][j] = 1 self.assertEqual(set(logic.find_full_lines()), set(range(9)))
def test_is_free(self): logic = b.Logic(4) for i in range(20): for j in range(9): logic.board[i][j] = 1 self.assertEqual(logic.is_free(), False)
def test_zigzag(self): logic = b.Logic(1, True) for i in range(4, len(logic.board) - 2): self.assertEqual(logic.board[i][0], logic.board[i + 1][-1])