9 #include <boost/test/unit_test.hpp>
21 #include <nlohmann/json.hpp>
25 BOOST_AUTO_TEST_SUITE(AlgebraJsonConversion)
33 nlohmann::json identityOut;
34 to_json(identityOut, reference);
35 out.open(
"Transform3_Identity.json");
36 out << identityOut.dump(2);
39 auto in = std::ifstream(
"Transform3_Identity.json",
41 BOOST_CHECK(
in.good());
42 nlohmann::json identityIn;
49 BOOST_CHECK(test.isApprox(reference));
52 reference.pretranslate(
Vector3(1., 2., 3.));
54 nlohmann::json translationOut;
55 to_json(translationOut, reference);
56 out.open(
"Transform3_Translation.json");
57 out << translationOut.dump(2);
60 in = std::ifstream(
"Transform3_Translation.json",
62 BOOST_CHECK(
in.good());
63 nlohmann::json translationIn;
67 test = Transform3::Identity();
70 BOOST_CHECK(test.isApprox(reference));
73 reference = Eigen::AngleAxis(0.12334,
Vector3(1., 2., 3).normalized());
74 reference.pretranslate(
Vector3(1., 2., 3.));
76 nlohmann::json fullOut;
78 out.open(
"Transform3_Full.json");
79 out << fullOut.dump(2);
82 in = std::ifstream(
"Transform3_Full.json",
84 BOOST_CHECK(
in.good());
85 nlohmann::json fullIn;
89 test = Transform3::Identity();
92 BOOST_CHECK(test.isApprox(reference));
101 nlohmann::json nulledOut =
103 BOOST_CHECK(nulledOut[
"translation"] ==
nullptr);
104 BOOST_CHECK(nulledOut[
"rotation"] ==
nullptr);
108 nlohmann::json writtenOut =
110 BOOST_CHECK(writtenOut[
"translation"] !=
nullptr);
111 BOOST_CHECK(writtenOut[
"rotation"] !=
nullptr);
116 Transform3 reference = Transform3::Identity();
117 reference.pretranslate(
Vector3(1., 2., 3.));
118 reference.rotate(Eigen::AngleAxis(0.12334,
Vector3(1., 2., 3).normalized()));
120 std::vector<ActsScalar> referenceT = {1., 2., 3.};
121 std::vector<ActsScalar> referenceR = {0.992946, -0.0975562, 0.0673888,
122 0.0997267, 0.994574, -0.0296247,
123 -0.0641331, 0.0361362, 0.997287};
127 nlohmann::json standardOut =
130 BOOST_CHECK(standardOut[
"translation"].
get<std::vector<ActsScalar>>() ==
133 std::vector<ActsScalar> readR =
134 standardOut[
"rotation"].get<std::vector<ActsScalar>>();
141 nlohmann::json transposeOut =
144 BOOST_CHECK(transposeOut[
"translation"].
get<std::vector<ActsScalar>>() ==
148 std::vector<size_t> transposedIndices = {0, 3, 6, 1, 4, 7, 2, 5, 8};
149 readR = transposeOut[
"rotation"].get<std::vector<ActsScalar>>();
155 BOOST_AUTO_TEST_SUITE_END()