def test_repeated_sequence2(self): with capture_output() as out: is_valid = knight.check_valid_sequence(self.board, [2, 4, 2, 2], print_status=True) output = out.getvalue().strip() out.close() self.assertFalse(is_valid) self.assertEqual(output, 'No repeats allowed.\nSequence is not valid.')
def test_bad_sequence(self): with capture_output() as out: is_valid = knight.check_valid_sequence(self.board, [-2, -2], print_status=True) output = out.getvalue().strip() out.close() self.assertFalse(is_valid) self.assertEqual(output, 'Sequence is not valid.')
def test_printing(self): with capture_output() as out: is_valid = knight.check_valid_sequence(self.board, self.moves, print_status=True) output = out.getvalue().strip() out.close() self.assertTrue(is_valid) self.assertEqual(output, 'Sequence is valid and finished the puzzle.')
def test_good_but_incomplete_sequence(self): with capture_output() as out: is_valid = knight.check_valid_sequence(self.board, self.moves[:-1], print_status=True) output = out.getvalue().strip() out.close() self.assertTrue(is_valid) self.assertEqual(output, 'Sequence is valid, but did not finish the puzzle.')
setup_dir(folder) # create profiler profile = pprofile.Profile() # Small board if do_board in {'small', 'both'}: print('\nSolve the smaller board for the minimum length solution.') # enable/disable profiler while running solver profile.enable() moves3 = knight.solve_min_puzzle(board1) profile.disable() # print solution print(moves3) is_valid3 = knight.check_valid_sequence(board1, moves3, print_status=True) if is_valid3: knight.print_sequence(board1, moves3) # Large board if do_board in {'large', 'both'}: print('\nSolve the larger board for the minimum length solution.') board2[0, 0] = knight.Piece.start #board2[-1, -1] = knight.Piece.final # doesn't use transport board2[11, -1] = knight.Piece.final # uses transport # enable/disable profiler while running solver profile.enable() moves4 = knight.solve_min_puzzle(board2) profile.disable()
def test_good_but_extra_sequence(self): self.moves.append(2) with self.assertRaises(ValueError): knight.check_valid_sequence(self.board, self.moves, print_status=False)
def test_repeated_sequence3(self): is_valid = knight.check_valid_sequence(self.board, [2, 4, 2, 2], allow_repeats=True) self.assertTrue(is_valid)
def test_repeated_sequence1(self): is_valid = knight.check_valid_sequence(self.board, [2, 4, 2, 2]) self.assertFalse(is_valid)
def test_no_final(self): self.board[2, 4] = knight.Piece.water with self.assertRaises(ValueError): knight.check_valid_sequence(self.board, self.moves, print_status=False)
def test_normal(self): is_valid = knight.check_valid_sequence(self.board, self.moves, print_status=False) self.assertTrue(is_valid)