Line data Source code
1 : #include "doctest/doctest.h"
2 : #include "DataContainerFormatter.hpp"
3 : #include "VolumeDescriptor.h"
4 :
5 : using namespace elsa;
6 : using namespace doctest;
7 :
8 : TEST_SUITE_BEGIN("core");
9 :
10 3 : TEST_CASE("DataContainerFormatter: default config")
11 : {
12 : using data_t = float;
13 :
14 6 : std::stringstream buffer;
15 6 : DataContainerFormatter<data_t> formatter;
16 :
17 4 : GIVEN("A 1D DataContainer with arbitrary values")
18 : {
19 2 : IndexVector_t numCoeff(1);
20 1 : numCoeff << 10;
21 :
22 3 : DataContainer<data_t> dc(VolumeDescriptor{numCoeff});
23 1 : dc = 1;
24 :
25 2 : THEN("Formatting writes correctly to the stream")
26 : {
27 1 : formatter.format(buffer, dc);
28 :
29 2 : auto resultString = buffer.str();
30 1 : REQUIRE_EQ(resultString,
31 : "DataContainer<dims=1, shape=(10)>\n[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]");
32 : }
33 : }
34 :
35 4 : GIVEN("A larger 1D DataContainer with arbitrary values")
36 : {
37 2 : IndexVector_t numCoeff(1);
38 1 : numCoeff << 15;
39 :
40 3 : DataContainer<data_t> dc(VolumeDescriptor{numCoeff});
41 1 : dc = 1;
42 :
43 2 : THEN("Formatting writes abbreviated to the stream")
44 : {
45 1 : formatter.format(buffer, dc);
46 :
47 2 : auto resultString = buffer.str();
48 1 : REQUIRE_EQ(
49 : resultString,
50 : "DataContainer<dims=1, shape=(15)>\n[1, 1, 1, 1, 1, 1, ..., 1, 1, 1, 1, 1, 1]");
51 : }
52 : }
53 :
54 4 : GIVEN("A 2D DataContainer with arbitrary values")
55 : {
56 2 : IndexVector_t numCoeff(2);
57 1 : numCoeff << 5, 3;
58 :
59 3 : DataContainer<data_t> dc(VolumeDescriptor{numCoeff});
60 1 : dc = 1;
61 :
62 2 : THEN("Formatting writes correctly to the stream")
63 : {
64 1 : formatter.format(buffer, dc);
65 :
66 2 : auto resultString = buffer.str();
67 1 : REQUIRE_EQ(resultString,
68 : R"(DataContainer<dims=2, shape=(5 3)>
69 : [[1, 1, 1],
70 : [1, 1, 1],
71 : [1, 1, 1],
72 : [1, 1, 1],
73 : [1, 1, 1]])");
74 : }
75 : }
76 3 : }
77 :
78 : TEST_SUITE_END();
|