test_generator.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 "../generator.h"
00023 #include "../solver.h"
00024 
00025 using namespace Sudoku;
00026 
00027 class Test_Generator : public CxxTest::TestSuite
00028 {
00029 public:
00030   void test_GenerateSymmetricSudoku()
00031   {
00032     // Generate a random Sudoku with 36 symmetric givens.
00033     Puzzle puzzle;
00034     Generator generator(puzzle, 36);
00035     generator.find_next_solution();
00036     TS_ASSERT(generator.solution_is_valid());
00037 
00038     // Solve the generated Sudoku.
00039     Solver solver(puzzle);
00040     solver.find_next_solution();
00041     TS_ASSERT(solver.solution_is_valid());
00042     solver.find_next_solution();
00043     bool only_one_solution = !solver.solution_is_valid();
00044     TS_ASSERT(only_one_solution);
00045   }
00046 
00047   void test_GenerateNonSymmetricSudoku()
00048   {
00049     // Generate a random Sudoku with 26 non-symmetric givens.
00050     Puzzle puzzle;
00051     Generator generator(puzzle, 26, false);
00052     generator.find_next_solution();
00053     TS_ASSERT(generator.solution_is_valid());
00054 
00055     // Solve the generated Sudoku.
00056     Solver solver(puzzle);
00057     solver.find_next_solution();
00058     TS_ASSERT(solver.solution_is_valid());
00059     solver.find_next_solution();
00060     bool only_one_solution = !solver.solution_is_valid();
00061     TS_ASSERT(only_one_solution);
00062   }
00063 };
Generated on Mon Apr 5 17:01:07 2010 for VDR plugin 'Sudoku' by  doxygen 1.6.3