29 std::ostringstream ss{};
31 REQUIRE(
a.get<
int>() == 10);
34 REQUIRE(
b.get<
float>() == 10.1f);
37 REQUIRE(
c.get<
double>() == 10.2);
42 REQUIRE(std::string(d.
get<
const char*>()) ==
"foo");
43 REQUIRE(std::string(d.
get<std::string_view>()) ==
"foo");
44 REQUIRE(std::string(d.
get<std::string>()) ==
"foo");
47 REQUIRE(e.
get<
bool>() ==
true);
50 REQUIRE(
f.get<
bool>() ==
false);
52 REQUIRE(ss.str() ==
"1010.110.2foo");
54 std::vector<Variant> vector{1, 1.2, 1.1f,
"foo"};
60 REQUIRE(std::string(sb.
get<
const char*>()) ==
"foo");
61 REQUIRE(std::string(sc.
get<
const char*>()) ==
"foo");
62 REQUIRE(std::string(sd.
get<
const char*>()) ==
"foo");
63 REQUIRE(sa.
get<
const char*>() ==
nullptr);
65 int iarr[] = {1, 2, 3, 4, 5};
66 float farr[] = {0.2, 0.3, 123.123, 123.123, 3.005e-5, 1.1e6};
67 std::vector<double> dvec = {0.1, 0.2, 0.4, 0.9, 1.3, 14.5, 123.234, 1.213e-20};
72 REQUIRE(viarr.
size() == 5);
73 REQUIRE(viarr.
get<
int*>() != iarr);
74 for (
auto i = 0u;
i < viarr.
size(); ++
i) {
75 REQUIRE(iarr[
i] == (viarr.
get<
int*>())[
i]);
78 REQUIRE(vfarr.
size() == 6);
79 REQUIRE(vfarr.
get<
float*>() != farr);
80 for (
auto i = 0u;
i < vfarr.
size(); ++
i) {
81 REQUIRE(farr[
i] == (vfarr.
get<
float*>())[
i]);
84 REQUIRE(vdvec.
size() == dvec.size());
85 REQUIRE(vdvec.
get<
double*>() != dvec.data());
86 for (
auto i = 0u;
i < dvec.size(); ++
i) {
87 REQUIRE(dvec[
i] == (vdvec.
get<
double*>())[
i]);
94 REQUIRE(vfarr.
get<
float*>() ==
nullptr);
96 REQUIRE(fb.
get<
float*>() != farr);
97 for (
auto i = 0u;
i < fb.
size(); ++
i) {
98 REQUIRE(farr[
i] == (fb.
get<
float*>())[
i]);
100 REQUIRE(fc.
get<
float*>() != farr);
101 for (
auto i = 0u;
i < fc.
size(); ++
i) {
102 REQUIRE(farr[
i] == (fc.
get<
float*>())[
i]);
104 REQUIRE(fd.
get<
float*>() != farr);
105 for (
auto i = 0u;
i < fd.
size(); ++
i) {
106 REQUIRE(farr[
i] == (fd.
get<
float*>())[
i]);
109 std::vector<std::string> vstrings{
"s1",
"s2",
"s3"};
110 std::string
strings[] = {
"l1",
"l2",
"l3"};
114 REQUIRE(vstr.
size() == 3);
115 REQUIRE(vvstr.
size() == 3);
116 for (
auto i = 0u;
i < vstr.
size(); ++
i) {
119 for (
auto i = 0u;
i < vvstr.
size(); ++
i) {
120 REQUIRE(vstrings[
i] == (vvstr.
get<std::string*>())[
i]);
126 for (
auto i = 0u;
i < vsm.
size(); ++
i) {
129 for (
auto i = 0u;
i < vscc.
size(); ++
i) {
134 Variant vsma(std::move(vvstr));
136 for (
auto i = 0u;
i < vsma.
size(); ++
i) {
137 REQUIRE(vstrings[
i] == (vsma.
get<std::string*>())[
i]);
139 for (
auto i = 0u;
i < vscca.
size(); ++
i) {
140 REQUIRE(vstrings[
i] == (vscca.
get<std::string*>())[
i]);
143 float m[3][4] = {{0.5, 0.25, 0.125, 0.0625}, {1.0, 2.0, 3.0, 4.0}, {2.0, 0.5, 4.0, 0.25}};
147 for (
auto i = 0u;
i < 3; ++
i) {
148 for (
auto j = 0u;
j < 4; ++
j) {
149 REQUIRE(mmc(
i,
j) == mm(
i,
j));
157 for (
auto i = 0u;
i < 3; ++
i) {
158 for (
auto j = 0u;
j < 4; ++
j) {
159 REQUIRE(mmc2(
i,
j) == mm(
i,
j));
163 for (
auto i = 0u;
i < 3; ++
i) {
164 for (
auto j = 0u;
j < 4; ++
j) {
165 REQUIRE(mmc3(
i,
j) == mm(
i,
j));
168 std::stringstream ssm;
170 REQUIRE(ssm.str() ==
"{\"values\":[[0.5,0.25,0.125,0.0625],[1.0,2.0,3.0,4.0],[2.0,0.5,4.0,0.25]]}");
175 for (
auto i = 0u;
i < 3; ++
i) {
176 for (
auto j = 0u;
j < 4; ++
j) {
177 REQUIRE(laf.get(
i,
j) == lafc.get(
i,
j));
182 Variant vlafm(std::move(vlaf));
185 for (
auto i = 0U;
i < 3; ++
i) {
186 for (
auto j = 0U;
j < 4; ++
j) {
187 REQUIRE(lafc2.get(
i,
j) == mm(
i,
j));
191 for (
auto i = 0U;
i < 3; ++
i) {
192 for (
auto j = 0U;
j < 4; ++
j) {
193 REQUIRE(lafc3.get(
i,
j) == mm(
i,
j));
197 std::vector<Variant> collection;
198 collection.push_back(vlafc);
199 collection.push_back(vlafm);
200 collection.push_back(vlafa);
205 float m[3][4] = {{0.1, 0.2, 0.3, 0.4}, {0.5, 0.6, 0.7, 0.8}, {0.9, 1.0, 1.1, 1.2}};
207 for (
auto i = 0U;
i < 3; ++
i) {
208 for (
auto j = 0U;
j < 4; ++
j) {
209 REQUIRE(mm(
i,
j) ==
m[
i][
j]);
212 std::vector<float>
v = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2};
214 for (
auto i = 0U;
i < 3; ++
i) {
215 for (
auto j = 0U;
j < 4; ++
j) {
216 REQUIRE(mm(
i,
j) ==
v[
i * 4 +
j]);
219 for (
auto i = 0U;
i < 3; ++
i) {
220 auto const& vv = mm[
i];
221 for (
auto j = 0u;
j < 4; ++
j) {
222 REQUIRE(vv[
j] == mm(
i,
j));
225 std::vector<std::string> s = {
"one",
"two",
"three",
"four"};
227 for (
auto i = 0U;
i < 4; ++
i) {
228 REQUIRE(ms(
i, 0) == s[
i]);
234 float m[3][4] = {{0.1, 0.2, 0.3, 0.4}, {0.5, 0.6, 0.7, 0.8}, {0.9, 1.0, 1.1, 1.2}};
235 std::string mS[3][4] = {{
"a",
"b",
"c",
"d"}, {
"e",
"f",
"g",
"h"}, {
"i",
"l",
"m",
"n"}};
236 std::string xl[] = {
"c1",
"c2",
"c3",
"c4"};
237 std::string yl[] = {
"r1",
"r2",
"r3"};
240 for (
auto i = 0u;
i < 3; ++
i) {
241 for (
auto j = 0u;
j < 4; ++
j) {
242 REQUIRE(laf.get(yl[
i].c_str(), xl[
j].c_str()) == laf.get(
i,
j));
243 REQUIRE(laf.get(
i, xl[
j].c_str()) == laf.get(
i,
j));
244 REQUIRE(laf.get(yl[
i].c_str(),
j) == laf.get(
i,
j));
246 REQUIRE(las.get(yl[
i].c_str(), xl[
j].c_str()) == las.get(
i,
j));
247 REQUIRE(las.get(
i, xl[
j].c_str()) == las.get(
i,
j));
248 REQUIRE(las.get(yl[
i].c_str(),
j) == las.get(
i,
j));
268 int iarr[] = {1, 2, 3, 4, 5};
270 std::stringstream os;
273 std::stringstream is;
275 auto v = VariantJSONHelpers::read<VariantType::ArrayInt>(is);
276 for (
auto i = 0u;
i < viarr.
size(); ++
i) {
277 REQUIRE(
v.get<
int*>()[
i] == viarr.
get<
int*>()[
i]);
281 float m[3][4] = {{0.1, 0.2, 0.3, 0.4}, {0.5, 0.6, 0.7, 0.8}, {0.9, 1.0, 1.1, 1.2}};
284 std::stringstream osm;
287 std::stringstream ism;
289 auto vm = VariantJSONHelpers::read<VariantType::Array2DFloat>(ism);
291 for (
auto i = 0u;
i < mm.rows; ++
i) {
292 for (
auto j = 0u;
j < mm.cols; ++
j) {
299 std::stringstream osl;
302 std::stringstream isl;
304 auto vlafc = VariantJSONHelpers::read<VariantType::LabeledArrayFloat>(isl);
312 std::string mS[3][4] = {{
"a",
"b",
"c",
"d"}, {
"e",
"f",
"g",
"h"}, {
"i",
"l",
"m",
"n"}};
315 std::stringstream ossl;
318 std::stringstream issl;
319 issl.str(ossl.str());
320 auto vmsa = VariantJSONHelpers::read<VariantType::LabeledArrayString>(issl);
328 std::vector<std::string> vstrings{
"myoption_one",
"myoption_two"};
330 std::stringstream osal;
333 std::stringstream isal;
334 isal.str(osal.str());
335 auto vvstra = VariantJSONHelpers::read<VariantType::ArrayString>(isal);
337 for (
auto i = 0U;
i < vvstra.size(); ++
i) {
338 REQUIRE(vstrings[
i] == vvstra.get<std::string*>()[
i]);