def test_copy(self): puzzle = hw3.create_tile_puzzle(3,3) puzzle2 = puzzle.copy() self.assertTrue(puzzle.get_board() == puzzle2.get_board()) puzzle = hw3.create_tile_puzzle(3,3) puzzle2 = puzzle.copy() puzzle.perform_move("left") self.assertFalse(puzzle.get_board() == puzzle2.get_board())
def test_create_tile_puzzle(self): puzzle = hw3.create_tile_puzzle(3,3) self.assertEquals(puzzle.get_board(), [[1, 2, 3], [4, 5, 6], [7, 8, 0]]) puzzle = hw3.create_tile_puzzle(2,4) self.assertEquals(puzzle.get_board(), [[1, 2, 3, 4], [5, 6, 7, 0]]) puzzle = hw3.create_tile_puzzle(4,0) self.assertEquals(puzzle.get_board(), [[], [], [], []])
def test_perform_move(self): puzzle = hw3.create_tile_puzzle(3,3) self.assertTrue(puzzle.perform_move("up")) self.assertEquals(puzzle.get_board(), [[1, 2, 3], [4, 5, 0], [7, 8, 6]]) puzzle = hw3.TilePuzzle([[0, 2, 3], [4, 5, 6], [7, 8, 1]]) self.assertFalse(puzzle.perform_move("up")) self.assertEquals(puzzle.get_board(), [[0, 2, 3], [4, 5, 6], [7, 8, 1]]) self.assertTrue(puzzle.perform_move("right")) self.assertEquals(puzzle.get_board(), [[2, 0, 3], [4, 5, 6], [7, 8, 1]]) puzzle = hw3.create_tile_puzzle(3,3) self.assertFalse(puzzle.perform_move("right")) self.assertEquals(puzzle.get_board(), [[1, 2, 3], [4, 5, 6], [7, 8, 0]]) puzzle = hw3.TilePuzzle([[0, 2, 3], [4, 5, 6], [7, 8, 1]]) puzzle = hw3.create_tile_puzzle(3,3) self.assertFalse(puzzle.perform_move("down")) self.assertEquals(puzzle.get_board(), [[1, 2, 3], [4, 5, 6], [7, 8, 0]]) self.assertTrue(puzzle.perform_move("left")) self.assertEquals(puzzle.get_board(), [[1, 2, 3], [4, 5, 6], [7, 0, 8]])
def __init__(self, master, rows, cols): Tkinter.Frame.__init__(self, master) self.rows = rows self.cols = cols self.puzzle = homework3.create_tile_puzzle(rows, cols) self.board = Board(self, self.puzzle, rows, cols) self.board.pack(side=Tkinter.LEFT, padx=1, pady=1) menu = Tkinter.Frame(self) Tkinter.Label(menu, text="Manipulate the empty tile\nusing the arrow keys.").pack( padx=1, pady=1) Tkinter.Button(menu, text="Scramble", command=self.scramble_click).pack( fill=Tkinter.X, padx=1, pady=1) Tkinter.Button(menu, text="Solve Using IDDFS", command=self.solve_iddfs_click).pack(fill=Tkinter.X, padx=1, pady=1) Tkinter.Button(menu, text="Solve Using A*", command=self.solve_a_star_click).pack(fill=Tkinter.X, padx=1, pady=1) menu.pack(side=Tkinter.RIGHT)
def test_a_star3(self): p = hw.create_tile_puzzle(9, 1) p.perform_move('up') self.assertEqual(list(p.find_solution_a_star()), ['down'])
def test_successors(self): p = hw.create_tile_puzzle(3, 3) for move, new_p in p.successors(): print move, new_p.get_board()
def test_copy2(self): p = hw.create_tile_puzzle(3, 3) p2 = p.copy() p.perform_move("left") self.assertEqual(p.get_board() == p2.get_board(), False)
def test_copy(self): p = hw.create_tile_puzzle(3, 3) p2 = p.copy() self.assertEqual(p.get_board() == p2.get_board(), True)
def test_perform_move2(self): p = hw.create_tile_puzzle(3, 3) self.assertEqual(p.perform_move("down"), False) self.assertEqual(p.get_board(), [[1, 2, 3], [4, 5, 6], [7, 8, 0]])
def test_perform_move(self): p = hw.create_tile_puzzle(3, 3) self.assertEqual(p.perform_move("up"), True) self.assertEqual(p.get_board(), [[1, 2, 3], [4, 5, 0], [7, 8, 6]])
def test_create2(self): p = hw.create_tile_puzzle(2, 4) self.assertEqual(p.get_board(), [[1, 2, 3, 4], [5, 6, 7, 0]])
def test_create(self): p = hw.create_tile_puzzle(3, 3) self.assertEqual(p.get_board(), [[1, 2, 3], [4, 5, 6], [7, 8, 0]])