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