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"
14BOOST_AUTO_TEST_SUITE( plot_unit_test )
17BOOST_AUTO_TEST_CASE( google_chart_bar_string )
26 std::string c2 = std::string(
"openfpm_io/test_data/gc_out_sc_test.html");
30 std::string c2 = std::string(
"test_data/gc_out_sc_test.html");
65 options.
title = std::string(
"Example");
66 options.
yAxis = std::string(
"Y Axis");
67 options.
xAxis = std::string(
"X Axis");
68 options.
stype = std::string(
"bars");
72 options.
stypeext = std::string(
"{3: {type: 'line'}}");
76 cg.
write(
"gc_out_sc.html");
80 bool test = compare(
"gc_out_sc.html",c2);
81 BOOST_REQUIRE_EQUAL(
true,test);
85BOOST_AUTO_TEST_CASE( google_chart )
94 std::string c2 = std::string(
"openfpm_io/test_data/gc_out_test.html");
98 std::string c2 = std::string(
"test_data/gc_out_test.html");
133 options.
title = std::string(
"Example");
134 options.
yAxis = std::string(
"Y Axis");
135 options.
xAxis = std::string(
"X Axis");
136 options.
stype = std::string(
"bars");
139 options.
stypeext = std::string(
"{3: {type: 'line'}}");
143 cg.
write(
"gc_out.html");
147 bool test = compare(
"gc_out.html",c2);
148 BOOST_REQUIRE_EQUAL(
true,test);
151BOOST_AUTO_TEST_CASE( google_chart2 )
160 std::string c2 = std::string(
"openfpm_io/test_data/gc_out2_test.html");
164 std::string c2 = std::string(
"test_data/gc_out2_test.html");
187 y.add({2.2,1.3,4.5,0.6});
188 y.add({5.0,6.1,1.3,2.6});
189 y.add({2.1,1.0,6.1,9.3});
190 y.add({1.1,6.1,3.0,2.0});
191 y.add({3.3,0.3,0.0,6.2});
192 y.add({2.0,1.1,4.0,6.1});
197 options.
title = std::string(
"Example");
198 options.
yAxis = std::string(
"Y Axis");
199 options.
xAxis = std::string(
"X Axis");
200 options.
stype = std::string(
"bars");
204 cg.
write(
"gc_out2.html");
206 bool test = compare(
"gc_out2.html",c2);
207 BOOST_REQUIRE_EQUAL(
true,test);
210BOOST_AUTO_TEST_CASE( google_chart3 )
219 std::string c2 = std::string(
"openfpm_io/test_data/gc_out3_test.html");
223 std::string c2 = std::string(
"test_data/gc_out3_test.html");
246 y.add({2.2,1.3,4.5,0.6});
247 y.add({5.0,6.1,1.3,2.6});
248 y.add({2.1,1.0,6.1,9.3});
249 y.add({1.1,6.1,3.0,2.0});
250 y.add({3.3,0.3,0.0,6.2});
251 y.add({2.0,1.1,4.0,6.1});
256 options.
title = std::string(
"Example");
257 options.
yAxis = std::string(
"Y Axis");
258 options.
xAxis = std::string(
"X Axis");
262 cg.
write(
"gc_out3.html");
264 bool test = compare(
"gc_out3.html",c2);
265 BOOST_REQUIRE_EQUAL(
true,test);
268BOOST_AUTO_TEST_CASE( google_chart4 )
277 std::string c2 = std::string(
"openfpm_io/test_data/gc_out4_test.html");
281 std::string c2 = std::string(
"test_data/gc_out4_test.html");
304 y.add({2.2,1.3,4.5,0.6});
305 y.add({5.0,6.1,1.3,2.6});
306 y.add({2.1,1.0,6.1,9.3});
307 y.add({1.1,6.1,3.0,2.0});
308 y.add({3.3,0.3,0.0,6.2});
309 y.add({2.0,1.1,4.0,6.1});
313 cg.
write(
"gc_out4.html");
315 bool test = compare(
"gc_out4.html",c2);
316 BOOST_REQUIRE_EQUAL(
true,test);
319BOOST_AUTO_TEST_CASE( google_chart5 )
328 std::string c2 = std::string(
"openfpm_io/test_data/gc_out5_test.html");
332 std::string c2 = std::string(
"test_data/gc_out5_test.html");
347 y.add({2.2,1.3,4.5,0.6});
348 y.add({5.0,6.1,1.3,2.6});
349 y.add({2.1,1.0,6.1,9.3});
350 y.add({1.1,6.1,3.0,2.0});
351 y.add({3.3,0.3,0.0,6.2});
352 y.add({2.0,1.1,4.0,6.1});
356 cg.
write(
"gc_out5.html");
358 bool test = compare(
"gc_out5.html",c2);
359 BOOST_REQUIRE_EQUAL(
true,test);
362BOOST_AUTO_TEST_CASE( google_chart6 )
371 std::string c2 = std::string(
"openfpm_io/test_data/gc_out6_test.html");
375 std::string c2 = std::string(
"test_data/gc_out6_test.html");
382 y.add({2.2,1.3,4.5,0.6});
383 y.add({5.0,6.1,1.3,2.6});
384 y.add({2.1,1.0,6.1,9.3});
385 y.add({1.1,6.1,3.0,2.0});
386 y.add({3.3,0.3,0.0,6.2});
387 y.add({2.0,1.1,4.0,6.1});
391 cg.
write(
"gc_out6.html");
393 bool test = compare(
"gc_out6.html",c2);
394 BOOST_REQUIRE_EQUAL(
true,test);
397BOOST_AUTO_TEST_CASE( google_chart_with_inject_HTML )
406 std::string c2 = std::string(
"openfpm_io/test_data/gc_out7_test.html");
410 std::string c2 = std::string(
"test_data/gc_out7_test.html");
445 options.
title = std::string(
"Example");
446 options.
yAxis = std::string(
"Y Axis");
447 options.
xAxis = std::string(
"X Axis");
448 options.
stype = std::string(
"bars");
451 options.
stypeext = std::string(
"{3: {type: 'line'}}");
455 cg.
addHTML(
"<h2>Before first graph</h2>");
457 cg.
addHTML(
"<h2>Before second graph</h2>");
459 cg.
addHTML(
"<h2>Before third graph</h2>");
461 cg.
addHTML(
"<h2>At the end</h2>");
462 cg.
write(
"gc_out7.html");
466 bool test = compare(
"gc_out7.html",c2);
467 BOOST_REQUIRE_EQUAL(
true,test);
470BOOST_AUTO_TEST_CASE( google_chart_number )
479 std::string c2 = std::string(
"openfpm_io/test_data/gc_num_plot_test.html");
483 std::string c2 = std::string(
"test_data/gc_num_plot_test.html");
518 options.
title = std::string(
"Example");
519 options.
yAxis = std::string(
"Y Axis");
520 options.
xAxis = std::string(
"X Axis");
521 options.
stype = std::string(
"line");
526 cg.
write(
"gc_num_plot.html");
530 bool test = compare(
"gc_num_plot.html",c2);
531 BOOST_REQUIRE_EQUAL(
true,test);
534BOOST_AUTO_TEST_CASE( google_chart_number_lines_different_x )
543 std::string c2 = std::string(
"openfpm_io/test_data/gc_num_ydif_plot_test.html");
547 std::string c2 = std::string(
"test_data/gc_num_ydif_plot_test.html");
561 x1.add(0.1); y1.add(4.5);
562 x1.add(0.2); y1.add(3.0);
563 x1.add(0.3); y1.add(5.5);
564 x1.add(0.4); y1.add(3.3);
565 x1.add(0.5); y1.add(1.0);
566 x1.add(0.6); y1.add(7.0);
568 x2.add(0.15); y2.add(1.5);
569 x2.add(0.2); y2.add(4.5);
570 x2.add(0.35); y2.add(2.5);
571 x2.add(0.45); y2.add(6.5);
573 x3.add(0.1); y3.add(3.5);
574 x3.add(0.2); y3.add(6.5);
575 x3.add(0.63); y3.add(1.5);
576 x3.add(0.37); y3.add(1.5);
577 x3.add(0.7); y3.add(3.5);
578 x3.add(0.82); y3.add(2.5);
579 x3.add(0.4); y3.add(2.5);
580 x3.add(1.0); y3.add(1.5);
581 x3.add(0.5); y3.add(7.5);
582 x3.add(0.91); y3.add(5.5);
594 options.
title = std::string(
"Example");
595 options.
yAxis = std::string(
"Y Axis");
596 options.
xAxis = std::string(
"X Axis");
597 options.
stype = std::string(
"line");
601 cg.
AddLines(yn,options,x1,y1,x2,y2,x3,y3);
602 cg.
write(
"gc_num_ydif_plot.html");
606 bool test = compare(
"gc_num_ydif_plot.html",c2);
607 BOOST_REQUIRE_EQUAL(
true,test);
610BOOST_AUTO_TEST_CASE( google_chart_linear_plot )
619 std::string c2 = std::string(
"openfpm_io/test_data/gc_plot_out_test.html");
623 std::string c2 = std::string(
"test_data/gc_plot_out_test.html");
661 y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
662 y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
663 y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
664 y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
665 y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
666 y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
671 options.
title = std::string(
"Example");
672 options.
yAxis = std::string(
"Y Axis");
673 options.
xAxis = std::string(
"X Axis");
675 options.
intervalext = std::string(
"{'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } }");
679 cg.
write(
"gc_plot_out.html");
683 bool test = compare(
"gc_plot_out.html",c2);
684 BOOST_REQUIRE_EQUAL(
true,test);
687BOOST_AUTO_TEST_CASE( google_chart_linear_plot2 )
696 std::string c2 = std::string(
"openfpm_io/test_data/gc_plot2_out_test.html");
700 std::string c2 = std::string(
"test_data/gc_plot2_out_test.html");
721 y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
722 y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
723 y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
724 y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
725 y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
726 y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
731 options.
title = std::string(
"Example");
732 options.
yAxis = std::string(
"Y Axis");
733 options.
xAxis = std::string(
"X Axis");
738 cg.
write(
"gc_plot2_out.html");
742 bool test = compare(
"gc_plot2_out.html",c2);
743 BOOST_REQUIRE_EQUAL(
true,test);
755BOOST_AUTO_TEST_CASE( plot_util )
768 BOOST_REQUIRE_EQUAL(x.get(0),0.0);
769 BOOST_REQUIRE_EQUAL(x.get(1),0.5);
770 BOOST_REQUIRE_EQUAL(x.get(2),1.0);
771 BOOST_REQUIRE_EQUAL(x.get(3),1.5);
772 BOOST_REQUIRE_EQUAL(x.get(4),2.0);
780 Fill1D(0.0,2.0,5,x,f);
782 BOOST_REQUIRE_EQUAL(x.get(0),0.0);
783 BOOST_REQUIRE_EQUAL(x.get(1),0.25);
784 BOOST_REQUIRE_EQUAL(x.get(2),1.0);
785 BOOST_REQUIRE_EQUAL(x.get(3),2.25);
786 BOOST_REQUIRE_EQUAL(x.get(4),4.0);
791BOOST_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.
Implementation of 1-D std::vector like structure.
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.