Commit 83a5a7ba authored by Eugene Pin's avatar Eugene Pin
Browse files

Add test for grid & history ==> issue #28

parent 867ab833
Pipeline #77934 passed with stages
in 16 seconds
......@@ -12,14 +12,15 @@ private slots:
void test_structure();
void test_factory();
void test_coord();
void test_history();
void test_grid();
void test_rle_structurereader();
void test_json_structurereader();
void test_arbitrary_neighborhood_rule();
void test_history();
void test_grid();
};
#endif // CELLULUT_TESTS_HPP
......@@ -5,10 +5,25 @@
void CellulutTests::test_grid()
{
/*
Grid grid(2,2);
Grid grid(7,12);
// Test méthode "Set cell" et "Get state"
grid.set_cell(4,4,2);
grid.set_cell(1,1,10);
grid.set_cell(1,2,1);
unsigned int state = grid.get_state(4, 4);
QVERIFY(state == 2);
*/
QVERIFY(grid.get_state(1, 1) == 10);
QVERIFY(grid.get_state(1, 2) == 1);
// Test operator=
Grid grid2(5,6);
QVERIFY(grid2.get_rows() == 5);
QVERIFY(grid2.get_col() == 6);
grid2 = grid;
QVERIFY(grid2.get_rows() == 7);
QVERIFY(grid2.get_col() == 12);
QVERIFY(grid2.get_state(4,4) == 2);
QVERIFY(grid2.get_state(1, 1) == 10);
QVERIFY(grid2.get_state(1, 2) == 1);
}
......@@ -6,7 +6,46 @@
void CellulutTests::test_history()
{
/*
History history(5);
*/
History historyTest(2);
QVERIFY(historyTest.get_nbMax() == 2);
QVERIFY(historyTest.isEmpty() == true);
Grid gridTest1(10,10);
Grid gridTest2(10,10);
Grid gridTest3(10,10);
gridTest1.set_cell(2,2,2);
gridTest2.set_cell(3,3,3);
gridTest3.set_cell(4,4,4);
// Push de 2 grilles
historyTest.pushGrid(gridTest1);
historyTest.pushGrid(gridTest2);
QVERIFY(historyTest.isEmpty() == false);
// Remarque : pour push grid, ne serait-il pas mieux d'utiliser des pointeurs sur une grille ? Dans ce cas, on fait
// une copie d'une grille. On a donc deux grilles identiques en mémoire : une dans la pile et une autre qu'on utilera plus
// On pop la première grille puis la deuxième
Grid popGrid = historyTest.popGrid();
QCOMPARE(popGrid.get_state(3,3), 3);
Grid topGrid = historyTest.topGrid();
QVERIFY(topGrid.get_state(2,2) == 2);
popGrid = historyTest.popGrid();
QCOMPARE(popGrid.get_state(2,2), 2);
QVERIFY(historyTest.isEmpty() == true);
// Push de trois grille (taille max de la pile de l'history = 2)
historyTest.pushGrid(gridTest1);
historyTest.pushGrid(gridTest2);
historyTest.pushGrid(gridTest3); // La première grille est supprimée
popGrid = historyTest.popGrid();
QCOMPARE(popGrid.get_state(4,4), 4);
topGrid = historyTest.topGrid();
QVERIFY(topGrid.get_state(3,3) == 3);
popGrid = historyTest.popGrid();
QCOMPARE(popGrid.get_state(3,3), 3);
QVERIFY(historyTest.isEmpty() == true);
}
......@@ -18,6 +18,8 @@ SOURCES += \
../src/structurereader.cpp \
../src/neighborhood.cpp \
../src/arbitraryneighborhoodrule.cpp \
../src/history.cpp \
../src/grid.cpp \
arbitraryneighborhoodrule_test.cpp \
coord_tests.cpp \
factory_tests.cpp \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment