diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -7,6 +7,12 @@ LINK_LIBRARIES Qt5::Test NAME_PREFIX "kpat-" ) +ecm_add_test( + freecell_solver.cpp + TEST_NAME FcSolveTest + LINK_LIBRARIES Qt5::Test + NAME_PREFIX "kpat-" +) ecm_add_test( "../dealer.cpp" "../dealerinfo.cpp" diff --git a/autotests/freecell_solver.cpp b/autotests/freecell_solver.cpp new file mode 100644 --- /dev/null +++ b/autotests/freecell_solver.cpp @@ -0,0 +1,45 @@ +/* Copyright (c) 2019 Shlomi Fish + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ +#include +#include + +class TestSolver: public QObject +{ + Q_OBJECT +private slots: + void runSolver(); +}; + +void TestSolver::runSolver() +{ + QProcess kpat; + const char *const deal = "830910836"; + kpat.start("../kpat", QStringList() << "--start" << deal << "--end" << deal << "--solve" << "3"); + QCOMPARE(kpat.waitForFinished(), true); + QCOMPARE(kpat.exitStatus(), QProcess::NormalExit); + QCOMPARE(kpat.exitCode(), 0); +} + +QTEST_MAIN(TestSolver) +#include "freecell_solver.moc" diff --git a/patsolve/abstract_fc_solve_solver.cpp b/patsolve/abstract_fc_solve_solver.cpp --- a/patsolve/abstract_fc_solve_solver.cpp +++ b/patsolve/abstract_fc_solve_solver.cpp @@ -126,6 +126,11 @@ } } } + const long reached_iters = freecell_solver_user_get_num_times_long(solver_instance); + Q_ASSERT(reached_iters <= MAX_ITERS_LIMIT); +#if 0 + fprintf(stderr, "iters = %ld\n", reached_iters); +#endif switch (solver_ret) { diff --git a/patsolve/freecellsolver.cpp b/patsolve/freecellsolver.cpp --- a/patsolve/freecellsolver.cpp +++ b/patsolve/freecellsolver.cpp @@ -288,7 +288,11 @@ static const char * freecell_solver_cmd_line_args[CMD_LINE_ARGS_NUM] = { +#if 0 "--load-config", "video-editing" +#else + "--load-config", "slick-rock" +#endif }; int FreecellSolver::get_cmd_line_arg_count()