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 )
55 options.
title = std::string(
"Example");
56 options.
yAxis = std::string(
"Y Axis");
57 options.
xAxis = std::string(
"X Axis");
58 options.
stype = std::string(
"bars");
62 options.
stypeext = std::string(
"{3: {type: 'line'}}");
66 cg.
write(
"gc_out_sc.html");
70 bool test = compare(
"gc_out_sc.html",
"test_data/gc_out_sc_test.html");
71 BOOST_REQUIRE_EQUAL(
true,test);
75 BOOST_AUTO_TEST_CASE( google_chart )
113 options.
title = std::string(
"Example");
114 options.
yAxis = std::string(
"Y Axis");
115 options.
xAxis = std::string(
"X Axis");
116 options.
stype = std::string(
"bars");
119 options.
stypeext = std::string(
"{3: {type: 'line'}}");
123 cg.
write(
"gc_out.html");
127 bool test = compare(
"gc_out.html",
"gc_out_test.html");
128 BOOST_REQUIRE_EQUAL(
true,test);
131 BOOST_AUTO_TEST_CASE( google_chart2 )
133 Vcluster & v_cl = create_vcluster();
157 y.add({2.2,1.3,4.5,0.6});
158 y.add({5.0,6.1,1.3,2.6});
159 y.add({2.1,1.0,6.1,9.3});
160 y.add({1.1,6.1,3.0,2.0});
161 y.add({3.3,0.3,0.0,6.2});
162 y.add({2.0,1.1,4.0,6.1});
167 options.
title = std::string(
"Example");
168 options.
yAxis = std::string(
"Y Axis");
169 options.
xAxis = std::string(
"X Axis");
170 options.
stype = std::string(
"bars");
174 cg.
write(
"gc_out2.html");
176 bool test = compare(
"gc_out2.html",
"gc_out2_test.html");
177 BOOST_REQUIRE_EQUAL(
true,test);
180 BOOST_AUTO_TEST_CASE( google_chart3 )
182 Vcluster & v_cl = create_vcluster();
206 y.add({2.2,1.3,4.5,0.6});
207 y.add({5.0,6.1,1.3,2.6});
208 y.add({2.1,1.0,6.1,9.3});
209 y.add({1.1,6.1,3.0,2.0});
210 y.add({3.3,0.3,0.0,6.2});
211 y.add({2.0,1.1,4.0,6.1});
216 options.
title = std::string(
"Example");
217 options.
yAxis = std::string(
"Y Axis");
218 options.
xAxis = std::string(
"X Axis");
222 cg.
write(
"gc_out3.html");
224 bool test = compare(
"gc_out3.html",
"gc_out3_test.html");
225 BOOST_REQUIRE_EQUAL(
true,test);
228 BOOST_AUTO_TEST_CASE( google_chart4 )
230 Vcluster & v_cl = create_vcluster();
254 y.add({2.2,1.3,4.5,0.6});
255 y.add({5.0,6.1,1.3,2.6});
256 y.add({2.1,1.0,6.1,9.3});
257 y.add({1.1,6.1,3.0,2.0});
258 y.add({3.3,0.3,0.0,6.2});
259 y.add({2.0,1.1,4.0,6.1});
263 cg.
write(
"gc_out4.html");
265 bool test = compare(
"gc_out4.html",
"gc_out4_test.html");
266 BOOST_REQUIRE_EQUAL(
true,test);
269 BOOST_AUTO_TEST_CASE( google_chart5 )
271 Vcluster & v_cl = create_vcluster();
287 y.add({2.2,1.3,4.5,0.6});
288 y.add({5.0,6.1,1.3,2.6});
289 y.add({2.1,1.0,6.1,9.3});
290 y.add({1.1,6.1,3.0,2.0});
291 y.add({3.3,0.3,0.0,6.2});
292 y.add({2.0,1.1,4.0,6.1});
296 cg.
write(
"gc_out5.html");
298 bool test = compare(
"gc_out5.html",
"gc_out5_test.html");
299 BOOST_REQUIRE_EQUAL(
true,test);
302 BOOST_AUTO_TEST_CASE( google_chart6 )
304 Vcluster & v_cl = create_vcluster();
312 y.add({2.2,1.3,4.5,0.6});
313 y.add({5.0,6.1,1.3,2.6});
314 y.add({2.1,1.0,6.1,9.3});
315 y.add({1.1,6.1,3.0,2.0});
316 y.add({3.3,0.3,0.0,6.2});
317 y.add({2.0,1.1,4.0,6.1});
321 cg.
write(
"gc_out6.html");
323 bool test = compare(
"gc_out6.html",
"gc_out6_test.html");
324 BOOST_REQUIRE_EQUAL(
true,test);
327 BOOST_AUTO_TEST_CASE( google_chart_with_inject_HTML )
329 Vcluster & v_cl = create_vcluster();
365 options.
title = std::string(
"Example");
366 options.
yAxis = std::string(
"Y Axis");
367 options.
xAxis = std::string(
"X Axis");
368 options.
stype = std::string(
"bars");
371 options.
stypeext = std::string(
"{3: {type: 'line'}}");
375 cg.
addHTML(
"<h2>Before first graph</h2>");
377 cg.
addHTML(
"<h2>Before second graph</h2>");
379 cg.
addHTML(
"<h2>Before third graph</h2>");
381 cg.
addHTML(
"<h2>At the end</h2>");
382 cg.
write(
"gc_out7.html");
386 bool test = compare(
"gc_out7.html",
"gc_out7_test.html");
387 BOOST_REQUIRE_EQUAL(
true,test);
390 BOOST_AUTO_TEST_CASE( google_chart_linear_plot )
392 Vcluster & v_cl = create_vcluster();
431 y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
432 y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
433 y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
434 y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
435 y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
436 y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
441 options.
title = std::string(
"Example");
442 options.
yAxis = std::string(
"Y Axis");
443 options.
xAxis = std::string(
"X Axis");
445 options.
intervalext = std::string(
"{'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } }");
449 cg.
write(
"gc_plot_out.html");
453 bool test = compare(
"gc_plot_out.html",
"gc_plot_out_test.html");
454 BOOST_REQUIRE_EQUAL(
true,test);
457 BOOST_AUTO_TEST_CASE( google_chart_linear_plot2 )
459 Vcluster & v_cl = create_vcluster();
481 y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
482 y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
483 y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
484 y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
485 y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
486 y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
491 options.
title = std::string(
"Example");
492 options.
yAxis = std::string(
"Y Axis");
493 options.
xAxis = std::string(
"X Axis");
498 cg.
write(
"gc_plot2_out.html");
502 bool test = compare(
"gc_plot2_out.html",
"gc_plot2_out_test.html");
503 BOOST_REQUIRE_EQUAL(
true,test);
515 BOOST_AUTO_TEST_CASE( plot_util )
517 Vcluster & v_cl = create_vcluster();
528 BOOST_REQUIRE_EQUAL(x.get(0),0.0);
529 BOOST_REQUIRE_EQUAL(x.get(1),0.5);
530 BOOST_REQUIRE_EQUAL(x.get(2),1.0);
531 BOOST_REQUIRE_EQUAL(x.get(3),1.5);
532 BOOST_REQUIRE_EQUAL(x.get(4),2.0);
540 Fill1D(0.0,2.0,5,x,f);
542 BOOST_REQUIRE_EQUAL(x.get(0),0.0);
543 BOOST_REQUIRE_EQUAL(x.get(1),0.25);
544 BOOST_REQUIRE_EQUAL(x.get(2),1.0);
545 BOOST_REQUIRE_EQUAL(x.get(3),2.25);
546 BOOST_REQUIRE_EQUAL(x.get(4),4.0);
551 BOOST_AUTO_TEST_SUITE_END()
void addHTML(const std::string &html)
Add HTML text.
void AddLinesGraph(openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
Add a simple lines graph.
size_t getProcessUnitID()
Get the process unit id.
std::string title
Title of the chart.
Implementation of VCluster class.
std::string yAxis
Y axis name.
Small class to produce graph with Google chart in HTML.
size_t lineWidth
Width of the line.
void write(std::string file)
It write the graphs on file in html format using Google charts.
void AddHistGraph(openfpm::vector< Y > &y)
Add an histogram graph.
std::string xAxis
X axis name.