structure_test.cpp 1.54 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#include <QtTest/QtTest>

#include <algorithm>

#include "cellulut_tests.hpp"

#include "structure.hpp"

void CellulutTests::test_structure()
{
11
    std::vector<std::pair<Coord, unsigned>> coords;
12
    std::vector<std::pair<Coord, unsigned>> normalized_coords;
13
    std::vector<std::pair<Coord, unsigned>> empty;
14
15
    coords.push_back({{1, 3}, 3}); normalized_coords.push_back({{2, 1}, 3});
    coords.push_back({{-1, 2}, 1}); normalized_coords.push_back({{0, 0}, 1});
16
17
18
19
20
21
22

    {
        Structure s1(coords.begin(), coords.end());
        Structure s2;
        s2.load(coords.begin(), coords.end());
        QCOMPARE(s1.size(), coords.size());
        QCOMPARE(s2.size(), coords.size());
23

24
25
        QVERIFY(std::is_permutation(normalized_coords.begin(), normalized_coords.end(), s1.begin()));
        QVERIFY(std::is_permutation(normalized_coords.begin(), normalized_coords.end(), s2.begin()));
26

27
28
        QCOMPARE(s1.width(), 3u);
        QCOMPARE(s1.height(), 2u);
29

30
31
        s1.load(empty.begin(), empty.end());
        QVERIFY(s1.size() == 0);
32
    }
33

34
    std::vector<std::pair<Coord, unsigned>> coords_with_zero;
35
    coords_with_zero = coords;
36
    coords_with_zero.push_back({{-2, 2}, 0});
37
38
39

    {
        Structure s1(coords_with_zero.begin(), coords_with_zero.end());
40
41
        QCOMPARE(s1.size(), coords.size()); // 2 cellules non nulles, on ignore les cellules à zéro qui sont toujours implicites
        QVERIFY(std::is_permutation(normalized_coords.begin(), normalized_coords.end(), s1.begin()));
42

43
44
        QCOMPARE(s1.width(), 3u);
        QCOMPARE(s1.height(), 2u);
45
46
47
    }
}