structurewriter_tests.cpp 934 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <QtTest/QtTest>

#include <algorithm>

#include "cellulut_tests.hpp"

#include "structure.hpp"
#include "structurewriter.hpp"
#include "structurereader.hpp"

void CellulutTests::test_rle_structurewriter()
{
    // TODO : écrire ces tests
}

void CellulutTests::test_json_structurewriter()
{
    std::vector<std::pair<Coord, unsigned>> coords;
    coords.push_back({{1, 2}, 3});
    coords.push_back({{-1, 2}, 1});

22
    try
23
    {
24
25
        JSONStructureWriter writer;
        auto out = writer.save_structure(Structure{coords.begin(), coords.end()});
26
27
28
29
30
31
32
33

        //printf("%s\n", out.c_str());

        JSONStructureReader reader(out);
        Structure struct_out = reader.read_structure();

        QVERIFY(std::is_permutation(struct_out.begin(), struct_out.end(), coords.begin()));
    }
34
35
36
37
38
    catch (const std::exception& ex)
    {
        fprintf(stderr, "Error is %s\n", ex.what());
        QFAIL("Exception thrown");
    }
39
}