def test_get_cell_selected(self): tkinter = Tk() canvas = Canvas(tkinter, width=450, height=450) canvas.pack() board = BoardModel(canvas) self.assertEqual((0, 0), board.get_cell_selected_coordinates()) self.assertEqual(True, board.get_board()[0][0].get_is_selected()) self.assertEqual(False, board.get_board()[7][7].get_is_selected())
def test_get_board(self): tkinter = Tk() canvas = Canvas(tkinter, width=450, height=450) canvas.pack() board = BoardModel(canvas) board_model = [] for x in range(board.get_size()): vertical_strip = [] for y in range(board.get_size()): if (x + y) % 2 == 0: vertical_strip.append(Cell(canvas, x * 50 + 50, y * 50 + 50, 50, "grey")) else: vertical_strip.append(Cell(canvas, x * 50 + 50, y * 50 + 50, 50, "white")) board_model.append(vertical_strip) self.assertEqual(board_model, board.get_board())
def test_key_pressed_down(self): tkinter = Tk() canvas = Canvas(tkinter, width=450, height=450) canvas.pack() board_model = BoardModel(canvas) board_model.select_new_cell(6, 6) board_listener = BoardListener(board_model) event = Event() event.keysym = "Down" board_listener.key_pressed(event) self.assertEqual((6, 7), board_model.get_cell_selected_coordinates()) self.assertEqual(True, board_model.get_board()[6][7].get_is_selected()) self.assertEqual(False, board_model.get_board()[6][6].get_is_selected()) board_listener.key_pressed(event) self.assertEqual((6, 7), board_model.get_cell_selected_coordinates()) self.assertEqual(True, board_model.get_board()[6][7].get_is_selected()) self.assertEqual(False, board_model.get_board()[6][6].get_is_selected())
def test_key_pressed_return(self): tkinter = Tk() canvas = Canvas(tkinter, width=450, height=450) canvas.pack() board_model = BoardModel(canvas) board_model.select_new_cell(6, 6) board_listener = BoardListener(board_model) event = Event() event.keysym = "Return" self.assertEqual(None, board_model.get_board()[6][6].get_filled_with()) board_listener.key_pressed(event) self.assertNotEqual(None, board_model.get_board()[6][6].get_filled_with()) self.assertEqual( "black", board_model.get_board()[6][6].get_filled_with().get_color()) board_model.select_new_cell(5, 6) self.assertEqual(None, board_model.get_board()[5][6].get_filled_with()) board_listener.key_pressed(event) self.assertNotEqual(None, board_model.get_board()[5][6].get_filled_with()) self.assertEqual( "white", board_model.get_board()[5][6].get_filled_with().get_color())
def test_get_canvas(self): tkinter = Tk() canvas = Canvas(tkinter, width=450, height=450) canvas.pack() board = BoardModel(canvas) self.assertEqual(canvas, board.get_canvas())
def test_new_turn(self): tkinter = Tk() canvas = Canvas(tkinter, width=450, height=450) canvas.pack() board = BoardModel(canvas) self.assertEqual("black", board.next_to_play()) board.new_turn() self.assertEqual("white", board.next_to_play()) board.new_turn() self.assertEqual("black", board.next_to_play()) board.new_turn() self.assertEqual("white", board.next_to_play())
#!/usr/bin/env python from src.BoardModel import * from src.BoardController import * # run othello program if __name__ == "__main__": root = Tk() world = Canvas(root, width=450, height=450) world.pack() board_model = BoardModel(world) board_model.draw() board_controller = BoardController(board_model) root.bind("<Key>", lambda event: board_controller.key_pressed_wrapper(event)) root.mainloop()