history_test.cpp 1.46 KB
Newer Older
Eugene Pin's avatar
Eugene Pin committed
1
2
3
4
#include <QtTest/QtTest>
#include <algorithm>
#include "cellulut_tests.hpp"

5
#include "history.hpp"
Eugene Pin's avatar
Eugene Pin committed
6
7
8

void CellulutTests::test_history()
{
9
10
11
12
13
14
15
    History historyTest(2);
    QVERIFY(historyTest.get_nbMax() == 2);
    QVERIFY(historyTest.isEmpty() == true);

    Grid gridTest1(10,10);
    Grid gridTest2(10,10);
    Grid gridTest3(10,10);
16
17
18
19
20
21
    Coord pos1 {2 ,2};
    Coord pos2 {3 ,3};
    Coord pos3 {4 ,4};
    gridTest1.set_cell(pos1,2);
    gridTest2.set_cell(pos2,3);
    gridTest3.set_cell(pos3,4);
22
23
24
25
26
27
28
29

    // Push de 2 grilles
    historyTest.pushGrid(gridTest1);
    historyTest.pushGrid(gridTest2);
    QVERIFY(historyTest.isEmpty() == false);

    // On pop la première grille puis la deuxième
    Grid popGrid = historyTest.popGrid();
30
    QCOMPARE(popGrid.get_state(pos2), 3u);
31
    Grid topGrid = historyTest.topGrid();
32
    QVERIFY(topGrid.get_state(pos1) == 2);
33
34

    popGrid = historyTest.popGrid();
35
    QCOMPARE(popGrid.get_state(pos1), 2u);
36
37
38
39
40
41
42
43
    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();
44
    QCOMPARE(popGrid.get_state(pos3), 4u);
45
    topGrid = historyTest.topGrid();
46
    QVERIFY(topGrid.get_state(pos2) == 3);
47
48

    popGrid = historyTest.popGrid();
49
    QCOMPARE(popGrid.get_state(pos2), 3u);
50
    QVERIFY(historyTest.isEmpty() == true);
Eugene Pin's avatar
Eugene Pin committed
51
}