test_history.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 "../history.h"
00023 #include "../puzzle.h"
00024 
00025 using namespace Sudoku;
00026 
00027 class Test_History : public CxxTest::TestSuite
00028 {
00029 public:
00030   void test_HistoryEmpty()
00031   {
00032     History history;
00033     TS_ASSERT(!history.movesExecuted());
00034     TS_ASSERT(!history.movesToExecute());
00035     history.backward();
00036     TS_ASSERT(!history.movesExecuted());
00037     TS_ASSERT(!history.movesToExecute());
00038     history.forward();
00039     TS_ASSERT(!history.movesExecuted());
00040     TS_ASSERT(!history.movesToExecute());
00041     history.reset();
00042     TS_ASSERT(!history.movesExecuted());
00043     TS_ASSERT(!history.movesToExecute());
00044   }
00045 
00046   void test_HistoryNull()
00047   {
00048     History history;
00049     TS_ASSERT_EQUALS(history.current(), (Move*)0);
00050     history.add(0);
00051     TS_ASSERT(!history.movesExecuted());
00052     TS_ASSERT(!history.movesToExecute());
00053   }
00054 
00055   void test_HistoryAdd()
00056   {
00057     History history;
00058     PuzzleGame puzzle;
00059 
00060     SetMove* move1 = new SetMove(puzzle, 1);
00061     history.add(move1);
00062     TS_ASSERT_EQUALS(history.current(), move1);
00063     TS_ASSERT(history.movesExecuted());
00064     TS_ASSERT(!history.movesToExecute());
00065 
00066     SetMove* move2 = new SetMove(puzzle, 2);
00067     history.add(move2);
00068     TS_ASSERT_EQUALS(history.current(), move2);
00069     TS_ASSERT(history.movesExecuted());
00070     TS_ASSERT(!history.movesToExecute());
00071 
00072     history.backward();
00073     TS_ASSERT_EQUALS(history.current(), move1);
00074     TS_ASSERT(history.movesExecuted());
00075     TS_ASSERT(history.movesToExecute());
00076 
00077     history.forward();
00078     TS_ASSERT_EQUALS(history.current(), move2);
00079     TS_ASSERT(history.movesExecuted());
00080     TS_ASSERT(!history.movesToExecute());
00081 
00082     history.backward();
00083     TS_ASSERT_EQUALS(history.current(), move1);
00084     TS_ASSERT(history.movesExecuted());
00085     TS_ASSERT(history.movesToExecute());
00086 
00087     SetMove* move3 = new SetMove(puzzle, 3);
00088     history.add(move3);
00089     TS_ASSERT_EQUALS(history.current(), move3);
00090     TS_ASSERT(history.movesExecuted());
00091     TS_ASSERT(!history.movesToExecute());
00092 
00093     history.backward();
00094     TS_ASSERT_EQUALS(history.current(), move1);
00095     TS_ASSERT(history.movesExecuted());
00096     TS_ASSERT(history.movesToExecute());
00097 
00098     history.backward();
00099     TS_ASSERT_EQUALS(history.current(), (Move*)0);
00100     TS_ASSERT(!history.movesExecuted());
00101     TS_ASSERT(history.movesToExecute());
00102   }
00103 
00104   void test_SetMove()
00105   {
00106     PuzzleGame puzzle;
00107     SetMove move = SetMove(puzzle, 9);
00108     Pos pos = puzzle.get_pos();
00109     TS_ASSERT_EQUALS(puzzle.get(pos), 0u);
00110     move.execute();
00111     TS_ASSERT_EQUALS(puzzle.get(pos), 9u);
00112     move.takeBack();
00113     TS_ASSERT_EQUALS(puzzle.get(pos), 0u);
00114   }
00115 };
Generated on Mon Apr 5 17:01:07 2010 for VDR plugin 'Sudoku' by  doxygen 1.6.3