arbitraryneighborhoodrule_test.cpp 999 Bytes
Newer Older
1
2
3
#include "cellulut_tests.hpp"

#include "arbitraryneighborhoodrule.hpp"
4
#include "propertyvisitors.hpp"
5

6
void CellulutTests::test_arbitrary_neighborhood_rule()
7
8
9
10
11
12
13
14
15
{
    std::vector<Coord> coords =
        {
            {1, 2},
            {-1, 2},
            {0, 3},
            {2, 4},
            };

16
17
    QJsonObject obj;
    QJsonArray json_array;
18
    for (auto coord : coords)
19
20
21
22
23
24
    {
        QJsonArray entry;
        entry.push_back(coord.x);
        entry.push_back(coord.y);
        json_array.push_back(entry);
    }
25
    obj["neighbors"] = json_array;
26
27
28
29
30
31
32

    ArbitraryNeighborhoodRule rule;
    {
        PropertyLoaderVisitor visit(obj);
        for (auto& prop : rule.get_properties())
            prop->accept(visit);
    }
33

34
    QCOMPARE(rule.getFormats().size(), 1u);
35
36
37
38
39
40
    QCOMPARE(rule.getFormats()[0].positions.size(), coords.size());

    auto list = rule.getFormats()[0].positions;

    QVERIFY(std::is_permutation(coords.begin(), coords.end(), rule.getFormats()[0].positions.begin()));
}