9 #include <boost/test/unit_test.hpp>
29 #include <nlohmann/json.hpp>
33 BOOST_AUTO_TEST_SUITE(VolumeBoundsJsonConversion)
36 std::ofstream
out(
"CuboidVolumeBounds.json");
38 auto cuboidRef = std::make_shared<const CuboidVolumeBounds>(2., 4., 6.);
40 out << cuboidOut.dump(2);
44 auto in = std::ifstream(
"CuboidVolumeBounds.json",
46 BOOST_CHECK(
in.good());
47 nlohmann::json cuboidIn;
52 VolumeBoundsJsonConverter::fromJson<CuboidVolumeBounds>(cuboidIn);
53 BOOST_CHECK(cuboidRef->values() == cuboidTest->values());
57 std::ofstream
out(
"CylinderVolumeBounds.json");
60 std::make_shared<const CylinderVolumeBounds>(10., 20., 30., M_PI / 4, 0);
62 out << cylinderOut.dump(2);
66 auto in = std::ifstream(
"CylinderVolumeBounds.json",
68 BOOST_CHECK(
in.good());
69 nlohmann::json cylinderIn;
74 VolumeBoundsJsonConverter::fromJson<CylinderVolumeBounds>(cylinderIn);
75 BOOST_CHECK(cylinderRef->values() == cylinderTest->values());
79 std::ofstream
out(
"ConeVolumeBounds.json");
81 auto coneRef = std::make_shared<const ConeVolumeBounds>(0., 0., 0.45, 0.050,
84 out << coneOut.dump(2);
88 auto in = std::ifstream(
"ConeVolumeBounds.json",
90 BOOST_CHECK(
in.good());
91 nlohmann::json coneIn;
95 auto coneTest = VolumeBoundsJsonConverter::fromJson<ConeVolumeBounds>(coneIn);
96 BOOST_CHECK(coneRef->values() == coneTest->values());
100 std::ofstream
out(
"CutoutCylinderVolumeBounds.json");
102 auto cutoutCylinderRef =
103 std::make_shared<const CutoutCylinderVolumeBounds>(5, 10, 15, 30, 25);
104 nlohmann::json cutoutCylinderOut =
106 out << cutoutCylinderOut.dump(2);
110 auto in = std::ifstream(
"CutoutCylinderVolumeBounds.json",
112 BOOST_CHECK(
in.good());
113 nlohmann::json cutoutCylinderIn;
114 in >> cutoutCylinderIn;
117 auto cutoutCylinderTest =
118 VolumeBoundsJsonConverter::fromJson<CutoutCylinderVolumeBounds>(
120 BOOST_CHECK(cutoutCylinderRef->values() == cutoutCylinderTest->values());
124 std::ofstream
out(
"GenericCuboidVolumeBounds.json");
126 vertices = {{{0, 0, 0},
135 auto genericCuboidRef =
136 std::make_shared<const GenericCuboidVolumeBounds>(
vertices);
137 nlohmann::json genericCuboidOut =
139 out << genericCuboidOut.dump(2);
143 auto in = std::ifstream(
"GenericCuboidVolumeBounds.json",
145 BOOST_CHECK(
in.good());
146 nlohmann::json genericCuboidIn;
147 in >> genericCuboidIn;
151 BOOST_CHECK(genericCuboidRef->values() == genericCuboidTest->values());
155 std::ofstream
out(
"TrapezoidVolumeBounds.json");
158 std::make_shared<const TrapezoidVolumeBounds>(2., 4., 6., 8.);
159 nlohmann::json trapezoidOut =
161 out << trapezoidOut.dump(2);
165 auto in = std::ifstream(
"TrapezoidVolumeBounds.json",
167 BOOST_CHECK(
in.good());
168 nlohmann::json trapezoidIn;
173 VolumeBoundsJsonConverter::fromJson<TrapezoidVolumeBounds>(trapezoidIn);
174 BOOST_CHECK(trapezoidRef->values() == trapezoidTest->values());
176 BOOST_AUTO_TEST_SUITE_END()