test_history.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 };