8 #ifndef OPENFPM_DATA_SRC_PLOT_PLOT_UNIT_TESTS_HPP_
9 #define OPENFPM_DATA_SRC_PLOT_PLOT_UNIT_TESTS_HPP_
11 #include "GoogleChart.hpp"
12 #include "Plot/util.hpp"
14 BOOST_AUTO_TEST_SUITE( plot_unit_test )
17 BOOST_AUTO_TEST_CASE( google_chart_bar_string )
24 std::string c2 = std::string(
"test_data/gc_out_sc_test.html");
57 options.
title = std::string(
"Example");
58 options.
yAxis = std::string(
"Y Axis");
59 options.
xAxis = std::string(
"X Axis");
60 options.
stype = std::string(
"bars");
64 options.
stypeext = std::string(
"{3: {type: 'line'}}");
68 cg.
write(
"gc_out_sc.html");
72 bool test = compare(
"gc_out_sc.html",c2);
73 BOOST_REQUIRE_EQUAL(
true,test);
77 BOOST_AUTO_TEST_CASE( google_chart )
84 std::string c2 = std::string(
"test_data/gc_out_test.html");
117 options.
title = std::string(
"Example");
118 options.
yAxis = std::string(
"Y Axis");
119 options.
xAxis = std::string(
"X Axis");
120 options.
stype = std::string(
"bars");
123 options.
stypeext = std::string(
"{3: {type: 'line'}}");
127 cg.
write(
"gc_out.html");
131 bool test = compare(
"gc_out.html",c2);
132 BOOST_REQUIRE_EQUAL(
true,test);
135 BOOST_AUTO_TEST_CASE( google_chart2 )
142 std::string c2 = std::string(
"test_data/gc_out2_test.html");
163 y.add({2.2,1.3,4.5,0.6});
164 y.add({5.0,6.1,1.3,2.6});
165 y.add({2.1,1.0,6.1,9.3});
166 y.add({1.1,6.1,3.0,2.0});
167 y.add({3.3,0.3,0.0,6.2});
168 y.add({2.0,1.1,4.0,6.1});
173 options.
title = std::string(
"Example");
174 options.
yAxis = std::string(
"Y Axis");
175 options.
xAxis = std::string(
"X Axis");
176 options.
stype = std::string(
"bars");
180 cg.
write(
"gc_out2.html");
182 bool test = compare(
"gc_out2.html",c2);
183 BOOST_REQUIRE_EQUAL(
true,test);
186 BOOST_AUTO_TEST_CASE( google_chart3 )
193 std::string c2 = std::string(
"test_data/gc_out3_test.html");
214 y.add({2.2,1.3,4.5,0.6});
215 y.add({5.0,6.1,1.3,2.6});
216 y.add({2.1,1.0,6.1,9.3});
217 y.add({1.1,6.1,3.0,2.0});
218 y.add({3.3,0.3,0.0,6.2});
219 y.add({2.0,1.1,4.0,6.1});
224 options.
title = std::string(
"Example");
225 options.
yAxis = std::string(
"Y Axis");
226 options.
xAxis = std::string(
"X Axis");
230 cg.
write(
"gc_out3.html");
232 bool test = compare(
"gc_out3.html",c2);
233 BOOST_REQUIRE_EQUAL(
true,test);
236 BOOST_AUTO_TEST_CASE( google_chart4 )
243 std::string c2 = std::string(
"test_data/gc_out4_test.html");
264 y.add({2.2,1.3,4.5,0.6});
265 y.add({5.0,6.1,1.3,2.6});
266 y.add({2.1,1.0,6.1,9.3});
267 y.add({1.1,6.1,3.0,2.0});
268 y.add({3.3,0.3,0.0,6.2});
269 y.add({2.0,1.1,4.0,6.1});
273 cg.
write(
"gc_out4.html");
275 bool test = compare(
"gc_out4.html",c2);
276 BOOST_REQUIRE_EQUAL(
true,test);
279 BOOST_AUTO_TEST_CASE( google_chart5 )
286 std::string c2 = std::string(
"test_data/gc_out5_test.html");
299 y.add({2.2,1.3,4.5,0.6});
300 y.add({5.0,6.1,1.3,2.6});
301 y.add({2.1,1.0,6.1,9.3});
302 y.add({1.1,6.1,3.0,2.0});
303 y.add({3.3,0.3,0.0,6.2});
304 y.add({2.0,1.1,4.0,6.1});
308 cg.
write(
"gc_out5.html");
310 bool test = compare(
"gc_out5.html",c2);
311 BOOST_REQUIRE_EQUAL(
true,test);
314 BOOST_AUTO_TEST_CASE( google_chart6 )
321 std::string c2 = std::string(
"test_data/gc_out6_test.html");
326 y.add({2.2,1.3,4.5,0.6});
327 y.add({5.0,6.1,1.3,2.6});
328 y.add({2.1,1.0,6.1,9.3});
329 y.add({1.1,6.1,3.0,2.0});
330 y.add({3.3,0.3,0.0,6.2});
331 y.add({2.0,1.1,4.0,6.1});
335 cg.
write(
"gc_out6.html");
337 bool test = compare(
"gc_out6.html",c2);
338 BOOST_REQUIRE_EQUAL(
true,test);
341 BOOST_AUTO_TEST_CASE( google_chart_with_inject_HTML )
348 std::string c2 = std::string(
"test_data/gc_out7_test.html");
381 options.
title = std::string(
"Example");
382 options.
yAxis = std::string(
"Y Axis");
383 options.
xAxis = std::string(
"X Axis");
384 options.
stype = std::string(
"bars");
387 options.
stypeext = std::string(
"{3: {type: 'line'}}");
391 cg.
addHTML(
"<h2>Before first graph</h2>");
393 cg.
addHTML(
"<h2>Before second graph</h2>");
395 cg.
addHTML(
"<h2>Before third graph</h2>");
397 cg.
addHTML(
"<h2>At the end</h2>");
398 cg.
write(
"gc_out7.html");
402 bool test = compare(
"gc_out7.html",c2);
403 BOOST_REQUIRE_EQUAL(
true,test);
406 BOOST_AUTO_TEST_CASE( google_chart_number )
413 std::string c2 = std::string(
"test_data/gc_num_plot_test.html");
446 options.
title = std::string(
"Example");
447 options.
yAxis = std::string(
"Y Axis");
448 options.
xAxis = std::string(
"X Axis");
449 options.
stype = std::string(
"line");
454 cg.
write(
"gc_num_plot.html");
458 bool test = compare(
"gc_num_plot.html",c2);
459 BOOST_REQUIRE_EQUAL(
true,test);
462 BOOST_AUTO_TEST_CASE( google_chart_number_lines_different_x )
469 std::string c2 = std::string(
"test_data/gc_num_ydif_plot_test.html");
481 x1.add(0.1); y1.add(4.5);
482 x1.add(0.2); y1.add(3.0);
483 x1.add(0.3); y1.add(5.5);
484 x1.add(0.4); y1.add(3.3);
485 x1.add(0.5); y1.add(1.0);
486 x1.add(0.6); y1.add(7.0);
488 x2.add(0.15); y2.add(1.5);
489 x2.add(0.2); y2.add(4.5);
490 x2.add(0.35); y2.add(2.5);
491 x2.add(0.45); y2.add(6.5);
493 x3.add(0.1); y3.add(3.5);
494 x3.add(0.2); y3.add(6.5);
495 x3.add(0.63); y3.add(1.5);
496 x3.add(0.37); y3.add(1.5);
497 x3.add(0.7); y3.add(3.5);
498 x3.add(0.82); y3.add(2.5);
499 x3.add(0.4); y3.add(2.5);
500 x3.add(1.0); y3.add(1.5);
501 x3.add(0.5); y3.add(7.5);
502 x3.add(0.91); y3.add(5.5);
514 options.
title = std::string(
"Example");
515 options.
yAxis = std::string(
"Y Axis");
516 options.
xAxis = std::string(
"X Axis");
517 options.
stype = std::string(
"line");
521 cg.
AddLines(yn,options,x1,y1,x2,y2,x3,y3);
522 cg.
write(
"gc_num_ydif_plot.html");
526 bool test = compare(
"gc_num_ydif_plot.html",c2);
527 BOOST_REQUIRE_EQUAL(
true,test);
530 BOOST_AUTO_TEST_CASE( google_chart_linear_plot )
537 std::string c2 = std::string(
"test_data/gc_plot_out_test.html");
573 y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
574 y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
575 y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
576 y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
577 y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
578 y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
583 options.
title = std::string(
"Example");
584 options.
yAxis = std::string(
"Y Axis");
585 options.
xAxis = std::string(
"X Axis");
587 options.
intervalext = std::string(
"{'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } }");
591 cg.
write(
"gc_plot_out.html");
595 bool test = compare(
"gc_plot_out.html",c2);
596 BOOST_REQUIRE_EQUAL(
true,test);
599 BOOST_AUTO_TEST_CASE( google_chart_linear_plot2 )
606 std::string c2 = std::string(
"test_data/gc_plot2_out_test.html");
625 y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
626 y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
627 y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
628 y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
629 y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
630 y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
635 options.
title = std::string(
"Example");
636 options.
yAxis = std::string(
"Y Axis");
637 options.
xAxis = std::string(
"X Axis");
642 cg.
write(
"gc_plot2_out.html");
646 bool test = compare(
"gc_plot2_out.html",c2);
647 BOOST_REQUIRE_EQUAL(
true,test);
659 BOOST_AUTO_TEST_CASE( plot_util )
672 BOOST_REQUIRE_EQUAL(x.get(0),0.0);
673 BOOST_REQUIRE_EQUAL(x.get(1),0.5);
674 BOOST_REQUIRE_EQUAL(x.get(2),1.0);
675 BOOST_REQUIRE_EQUAL(x.get(3),1.5);
676 BOOST_REQUIRE_EQUAL(x.get(4),2.0);
684 Fill1D(0.0,2.0,5,x,f);
686 BOOST_REQUIRE_EQUAL(x.get(0),0.0);
687 BOOST_REQUIRE_EQUAL(x.get(1),0.25);
688 BOOST_REQUIRE_EQUAL(x.get(2),1.0);
689 BOOST_REQUIRE_EQUAL(x.get(3),2.25);
690 BOOST_REQUIRE_EQUAL(x.get(4),4.0);
695 BOOST_AUTO_TEST_SUITE_END()
Small class to produce graph with Google chart in HTML.
void write(std::string file)
It write the graphs on file in html format using Google charts.
void AddLines(const openfpm::vector< std::string > &yn, const GCoptions &opt, X ... xy)
Add lines graph.
void AddLinesGraph(openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
Add a simple lines graph.
void AddHistGraph(openfpm::vector< Y > &y)
Add an histogram graph.
void addHTML(const std::string &html)
Add HTML text.
size_t getProcessUnitID()
Get the process unit id.
Implementation of VCluster class.
std::string xAxis
X axis name.
size_t lineWidth
Width of the line.
std::string title
Title of the chart.
std::string yAxis
Y axis name.