test_solver.h

Go to the documentation of this file.
00001 /*
00002  * Sudoku: A plug-in for the Video Disk Recorder
00003  *
00004  * Copyright (C) 2010, Thomas Günther <tom@toms-cafe.de>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with this program; if not, write to the Free Software Foundation, Inc.,
00018  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00019  */
00020 
00021 #include <cxxtest/TestSuite.h>
00022 #include "../solver.h"
00023 
00024 using namespace Sudoku;
00025 
00026 class Test_Solver : public CxxTest::TestSuite
00027 {
00028 public:
00029   void test_SearchFirstSudoku()
00030   {
00031     Puzzle puzzle;
00032     Solver solver(puzzle);
00033     solver.find_next_solution();
00034     TS_ASSERT(solver.solution_is_valid());
00035     const char dump[] = "_________+"
00036                         "_________+"
00037                         "_________+"
00038                         "_________+"
00039                         "_________+"
00040                         "_________+"
00041                         "_________+"
00042                         "_________+"
00043                         "_________:"
00044                         "123456789+"
00045                         "456789123+"
00046                         "789123456+"
00047                         "231674895+"
00048                         "875912364+"
00049                         "694538217+"
00050                         "317265948+"
00051                         "542897631+"
00052                         "968341572:"
00053                         "_________+"
00054                         "_________+"
00055                         "_________+"
00056                         "_________+"
00057                         "_________+"
00058                         "_________+"
00059                         "_________+"
00060                         "_________+"
00061                         "_________";
00062     TS_ASSERT_SAME_DATA(puzzle.get_dump(), dump, sizeof(dump));
00063     solver.find_next_solution();
00064     bool more_than_one_solution = solver.solution_is_valid();
00065     TS_ASSERT(more_than_one_solution);
00066   }
00067 
00068   void test_SearchRandomSudoku()
00069   {
00070     Puzzle puzzle;
00071     Solver solver(puzzle, true);
00072     solver.find_next_solution();
00073     TS_ASSERT(solver.solution_is_valid());
00074   }
00075 
00076   void test_SolveHardSudoku()
00077   {
00078     // Hardest Sudoku from sudokusolver.co.uk (nologic, score 80197, 77 guesses)
00079     Puzzle puzzle("1____7_9_+"
00080                   "_3__2___8+"
00081                   "__96__5__+"
00082                   "__53__9__+"
00083                   "_1__8___2+"
00084                   "6____4___+"
00085                   "3______1_+"
00086                   "_4______7+"
00087                   "__7___3__");
00088     Solver solver(puzzle);
00089     solver.find_next_solution();
00090     TS_ASSERT(solver.solution_is_valid());
00091     const char dump[] = "1____7_9_+"
00092                         "_3__2___8+"
00093                         "__96__5__+"
00094                         "__53__9__+"
00095                         "_1__8___2+"
00096                         "6____4___+"
00097                         "3______1_+"
00098                         "_4______7+"
00099                         "__7___3__:"
00100                         "162857493+"
00101                         "534129678+"
00102                         "789643521+"
00103                         "475312986+"
00104                         "913586742+"
00105                         "628794135+"
00106                         "356478219+"
00107                         "241935867+"
00108                         "897261354:"
00109                         "_________+"
00110                         "_________+"
00111                         "_________+"
00112                         "_________+"
00113                         "_________+"
00114                         "_________+"
00115                         "_________+"
00116                         "_________+"
00117                         "_________";
00118     TS_ASSERT_SAME_DATA(puzzle.get_dump(), dump, sizeof(dump));
00119     solver.find_next_solution();
00120     bool only_one_solution = !solver.solution_is_valid();
00121     TS_ASSERT(only_one_solution);
00122   }
00123 };
Generated on Mon Apr 5 17:01:07 2010 for VDR plugin 'Sudoku' by  doxygen 1.6.3