OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
Plot_unit_tests.hpp
1/*
2 * Plot_unit_tests.hpp
3 *
4 * Created on: Jan 9, 2016
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_DATA_SRC_PLOT_PLOT_UNIT_TESTS_HPP_
9#define OPENFPM_DATA_SRC_PLOT_PLOT_UNIT_TESTS_HPP_
10
11#include "GoogleChart.hpp"
12#include "Plot/util.hpp"
13
14BOOST_AUTO_TEST_SUITE( plot_unit_test )
15
16
17BOOST_AUTO_TEST_CASE( google_chart_bar_string )
18{
19 Vcluster<> & v_cl = create_vcluster();
20
21 if (v_cl.getProcessUnitID() != 0)
22 return;
23
24#ifdef OPENFPM_PDATA
25
26 std::string c2 = std::string("openfpm_io/test_data/gc_out_sc_test.html");
27
28#else
29
30 std::string c2 = std::string("test_data/gc_out_sc_test.html");
31
32#endif
33
35
39
40 x.add("colum1");
41 x.add("colum2");
42 x.add("colum3");
43 x.add("colum4");
44 x.add("colum5");
45 x.add("colum6");
46
47 // Each colum can have multiple data set (in this case 4 dataset)
48 // Each dataset can have a name
49 yn.add("dataset1");
50 yn.add("dataset2");
51 yn.add("dataset3");
52 yn.add("dataset4");
53
54 // Each colums can have multiple data-set
55 y.add({2,3,5,6});
56 y.add({5,6,1,6});
57 y.add({2,1,6,9});
58 y.add({1,6,3,2});
59 y.add({3,3,0,6});
60 y.add({2,1,4,6});
61
62 // Google charts options
63 GCoptions options;
64
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");
69 options.barWD = true;
70
71 // it say that the colum4 must me represented with a line
72 options.stypeext = std::string("{3: {type: 'line'}}");
73
74 GoogleChart cg;
75 cg.AddHistGraph(x,y,yn,options);
76 cg.write("gc_out_sc.html");
77
79
80 bool test = compare("gc_out_sc.html",c2);
81 BOOST_REQUIRE_EQUAL(true,test);
82}
83
84
85BOOST_AUTO_TEST_CASE( google_chart )
86{
87 Vcluster<> & v_cl = create_vcluster();
88
89 if (v_cl.getProcessUnitID() != 0)
90 return;
91
92#ifdef OPENFPM_PDATA
93
94 std::string c2 = std::string("openfpm_io/test_data/gc_out_test.html");
95
96#else
97
98 std::string c2 = std::string("test_data/gc_out_test.html");
99
100#endif
101
103
107
108 x.add("colum1");
109 x.add("colum2");
110 x.add("colum3");
111 x.add("colum4");
112 x.add("colum5");
113 x.add("colum6");
114
115 // Each colum can have multiple data set (in this case 4 dataset)
116 // Each dataset can have a name
117 yn.add("dataset1");
118 yn.add("dataset2");
119 yn.add("dataset3");
120 yn.add("dataset4");
121
122 // Each colums can have multiple data-set
123 y.add({2,3,5,6});
124 y.add({5,6,1,6});
125 y.add({2,1,6,9});
126 y.add({1,6,3,2});
127 y.add({3,3,0,6});
128 y.add({2,1,4,6});
129
130 // Google charts options
131 GCoptions options;
132
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");
137
138 // it say that the colum4 must me represented with a line
139 options.stypeext = std::string("{3: {type: 'line'}}");
140
141 GoogleChart cg;
142 cg.AddHistGraph(x,y,yn,options);
143 cg.write("gc_out.html");
144
146
147 bool test = compare("gc_out.html",c2);
148 BOOST_REQUIRE_EQUAL(true,test);
149}
150
151BOOST_AUTO_TEST_CASE( google_chart2 )
152{
153 Vcluster<> & v_cl = create_vcluster();
154
155 if (v_cl.getProcessUnitID() != 0)
156 return;
157
158#ifdef OPENFPM_PDATA
159
160 std::string c2 = std::string("openfpm_io/test_data/gc_out2_test.html");
161
162#else
163
164 std::string c2 = std::string("test_data/gc_out2_test.html");
165
166#endif
167
171
172 x.add("colum1");
173 x.add("colum2");
174 x.add("colum3");
175 x.add("colum4");
176 x.add("colum5");
177 x.add("colum6");
178
179 // Each colum can have multiple data set (in this case 4 dataset)
180 // Each dataset can have a name
181 yn.add("dataset1");
182 yn.add("dataset2");
183 yn.add("dataset3");
184 yn.add("dataset4");
185
186 // Each colums can have multiple data-set
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});
193
194 // Google charts options
195 GCoptions options;
196
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");
201
202 GoogleChart cg;
203 cg.AddHistGraph(x,y,yn,options);
204 cg.write("gc_out2.html");
205
206 bool test = compare("gc_out2.html",c2);
207 BOOST_REQUIRE_EQUAL(true,test);
208}
209
210BOOST_AUTO_TEST_CASE( google_chart3 )
211{
212 Vcluster<> & v_cl = create_vcluster();
213
214 if (v_cl.getProcessUnitID() != 0)
215 return;
216
217#ifdef OPENFPM_PDATA
218
219 std::string c2 = std::string("openfpm_io/test_data/gc_out3_test.html");
220
221#else
222
223 std::string c2 = std::string("test_data/gc_out3_test.html");
224
225#endif
226
230
231 x.add("colum1");
232 x.add("colum2");
233 x.add("colum3");
234 x.add("colum4");
235 x.add("colum5");
236 x.add("colum6");
237
238 // Each colum can have multiple data set (in this case 4 dataset)
239 // Each dataset can have a name
240 yn.add("dataset1");
241 yn.add("dataset2");
242 yn.add("dataset3");
243 yn.add("dataset4");
244
245 // Each colums can have multiple data-set
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});
252
253 // Google charts options
254 GCoptions options;
255
256 options.title = std::string("Example");
257 options.yAxis = std::string("Y Axis");
258 options.xAxis = std::string("X Axis");
259
260 GoogleChart cg;
261 cg.AddHistGraph(x,y,yn,options);
262 cg.write("gc_out3.html");
263
264 bool test = compare("gc_out3.html",c2);
265 BOOST_REQUIRE_EQUAL(true,test);
266}
267
268BOOST_AUTO_TEST_CASE( google_chart4 )
269{
270 Vcluster<> & v_cl = create_vcluster();
271
272 if (v_cl.getProcessUnitID() != 0)
273 return;
274
275#ifdef OPENFPM_PDATA
276
277 std::string c2 = std::string("openfpm_io/test_data/gc_out4_test.html");
278
279#else
280
281 std::string c2 = std::string("test_data/gc_out4_test.html");
282
283#endif
284
288
289 x.add("colum1");
290 x.add("colum2");
291 x.add("colum3");
292 x.add("colum4");
293 x.add("colum5");
294 x.add("colum6");
295
296 // Each colum can have multiple data set (in this case 4 dataset)
297 // Each dataset can have a name
298 yn.add("dataset1");
299 yn.add("dataset2");
300 yn.add("dataset3");
301 yn.add("dataset4");
302
303 // Each colums can have multiple data-set
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});
310
311 GoogleChart cg;
312 cg.AddHistGraph(x,y,yn);
313 cg.write("gc_out4.html");
314
315 bool test = compare("gc_out4.html",c2);
316 BOOST_REQUIRE_EQUAL(true,test);
317}
318
319BOOST_AUTO_TEST_CASE( google_chart5 )
320{
321 Vcluster<> & v_cl = create_vcluster();
322
323 if (v_cl.getProcessUnitID() != 0)
324 return;
325
326#ifdef OPENFPM_PDATA
327
328 std::string c2 = std::string("openfpm_io/test_data/gc_out5_test.html");
329
330#else
331
332 std::string c2 = std::string("test_data/gc_out5_test.html");
333
334#endif
335
338
339 x.add("colum1");
340 x.add("colum2");
341 x.add("colum3");
342 x.add("colum4");
343 x.add("colum5");
344 x.add("colum6");
345
346 // Each colums can have multiple data-set
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});
353
354 GoogleChart cg;
355 cg.AddHistGraph(x,y);
356 cg.write("gc_out5.html");
357
358 bool test = compare("gc_out5.html",c2);
359 BOOST_REQUIRE_EQUAL(true,test);
360}
361
362BOOST_AUTO_TEST_CASE( google_chart6 )
363{
364 Vcluster<> & v_cl = create_vcluster();
365
366 if (v_cl.getProcessUnitID() != 0)
367 return;
368
369#ifdef OPENFPM_PDATA
370
371 std::string c2 = std::string("openfpm_io/test_data/gc_out6_test.html");
372
373#else
374
375 std::string c2 = std::string("test_data/gc_out6_test.html");
376
377#endif
378
380
381 // Each colums can have multiple data-set
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});
388
389 GoogleChart cg;
390 cg.AddHistGraph(y);
391 cg.write("gc_out6.html");
392
393 bool test = compare("gc_out6.html",c2);
394 BOOST_REQUIRE_EQUAL(true,test);
395}
396
397BOOST_AUTO_TEST_CASE( google_chart_with_inject_HTML )
398{
399 Vcluster<> & v_cl = create_vcluster();
400
401 if (v_cl.getProcessUnitID() != 0)
402 return;
403
404#ifdef OPENFPM_PDATA
405
406 std::string c2 = std::string("openfpm_io/test_data/gc_out7_test.html");
407
408#else
409
410 std::string c2 = std::string("test_data/gc_out7_test.html");
411
412#endif
413
415
419
420 x.add("colum1");
421 x.add("colum2");
422 x.add("colum3");
423 x.add("colum4");
424 x.add("colum5");
425 x.add("colum6");
426
427 // Each colum can have multiple data set (in this case 4 dataset)
428 // Each dataset can have a name
429 yn.add("dataset1");
430 yn.add("dataset2");
431 yn.add("dataset3");
432 yn.add("dataset4");
433
434 // Each colums can have multiple data-set
435 y.add({2,3,5,6});
436 y.add({5,6,1,6});
437 y.add({2,1,6,9});
438 y.add({1,6,3,2});
439 y.add({3,3,0,6});
440 y.add({2,1,4,6});
441
442 // Google charts options
443 GCoptions options;
444
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");
449
450 // it say that the colum4 must me represented with a line
451 options.stypeext = std::string("{3: {type: 'line'}}");
452
453 GoogleChart cg;
454 //
455 cg.addHTML("<h2>Before first graph</h2>");
456 cg.AddHistGraph(x,y,yn,options);
457 cg.addHTML("<h2>Before second graph</h2>");
458 cg.AddHistGraph(x,y,yn,options);
459 cg.addHTML("<h2>Before third graph</h2>");
460 cg.AddHistGraph(x,y,yn,options);
461 cg.addHTML("<h2>At the end</h2>");
462 cg.write("gc_out7.html");
463
465
466 bool test = compare("gc_out7.html",c2);
467 BOOST_REQUIRE_EQUAL(true,test);
468}
469
470BOOST_AUTO_TEST_CASE( google_chart_number )
471{
472 Vcluster<> & v_cl = create_vcluster();
473
474 if (v_cl.getProcessUnitID() != 0)
475 return;
476
477#ifdef OPENFPM_PDATA
478
479 std::string c2 = std::string("openfpm_io/test_data/gc_num_plot_test.html");
480
481#else
482
483 std::string c2 = std::string("test_data/gc_num_plot_test.html");
484
485#endif
486
488
492
493 x.add(0.1);
494 x.add(0.2);
495 x.add(0.3);
496 x.add(0.4);
497 x.add(0.5);
498 x.add(0.6);
499
500 // Each colum can have multiple data set (in this case 4 dataset)
501 // Each dataset can have a name
502 yn.add("dataset1");
503 yn.add("dataset2");
504 yn.add("dataset3");
505 yn.add("dataset4");
506
507 // Each colums can have multiple data-set
508 y.add({2,3,5,6});
509 y.add({5,6,1,6});
510 y.add({2,1,6,9});
511 y.add({1,6,3,2});
512 y.add({3,3,0,6});
513 y.add({2,1,4,6});
514
515 // Google charts options
516 GCoptions options;
517
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");
522
523 GoogleChart cg;
524 //
525 cg.AddLinesGraph(x,y,yn,options);
526 cg.write("gc_num_plot.html");
527
529
530 bool test = compare("gc_num_plot.html",c2);
531 BOOST_REQUIRE_EQUAL(true,test);
532}
533
534BOOST_AUTO_TEST_CASE( google_chart_number_lines_different_x )
535{
536 Vcluster<> & v_cl = create_vcluster();
537
538 if (v_cl.getProcessUnitID() != 0)
539 return;
540
541#ifdef OPENFPM_PDATA
542
543 std::string c2 = std::string("openfpm_io/test_data/gc_num_ydif_plot_test.html");
544
545#else
546
547 std::string c2 = std::string("test_data/gc_num_ydif_plot_test.html");
548
549#endif
550
552
560
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);
567
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);
572
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);
583
584 // Each colum can have multiple data set (in this case 4 dataset)
585 // Each dataset can have a name
586 yn.add("dataset1");
587 yn.add("dataset2");
588 yn.add("dataset3");
589
590
591 // Google charts options
592 GCoptions options;
593
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");
598
599 GoogleChart cg;
600
601 cg.AddLines(yn,options,x1,y1,x2,y2,x3,y3);
602 cg.write("gc_num_ydif_plot.html");
603
605
606 bool test = compare("gc_num_ydif_plot.html",c2);
607 BOOST_REQUIRE_EQUAL(true,test);
608}
609
610BOOST_AUTO_TEST_CASE( google_chart_linear_plot )
611{
612 Vcluster<> & v_cl = create_vcluster();
613
614 if (v_cl.getProcessUnitID() != 0)
615 return;
616
617#ifdef OPENFPM_PDATA
618
619 std::string c2 = std::string("openfpm_io/test_data/gc_plot_out_test.html");
620
621#else
622
623 std::string c2 = std::string("test_data/gc_plot_out_test.html");
624
625#endif
626
628
632
633 x.add("colum1");
634 x.add("colum2");
635 x.add("colum3");
636 x.add("colum4");
637 x.add("colum5");
638 x.add("colum6");
639
640 // Here we specify how many lines we have
641 // first Line
642 yn.add("line1");
643
644 // second line + 2 intervals (Error bands)
645 yn.add("line2");
646 yn.add("interval");
647 yn.add("interval");
648 yn.add("interval");
649 yn.add("interval");
650
651 // third line + 1 interval (Error bands)
652 yn.add("line3");
653 yn.add("interval");
654 yn.add("interval");
655
656 // Each line can have multiple intervals or error bars
657 // The first number specify the bottom line
658 // The last three numbers specify the top line + error band (min, max)
659 // The middle 5 line specify the middle lines + one external error band + one internal error band
660
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});
667
668 // Google charts options
669 GCoptions options;
670
671 options.title = std::string("Example");
672 options.yAxis = std::string("Y Axis");
673 options.xAxis = std::string("X Axis");
674 options.lineWidth = 1.0;
675 options.intervalext = std::string("{'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } }");
676
677 GoogleChart cg;
678 cg.AddLinesGraph(x,y,yn,options);
679 cg.write("gc_plot_out.html");
680
682
683 bool test = compare("gc_plot_out.html",c2);
684 BOOST_REQUIRE_EQUAL(true,test);
685}
686
687BOOST_AUTO_TEST_CASE( google_chart_linear_plot2 )
688{
689 Vcluster<> & v_cl = create_vcluster();
690
691 if (v_cl.getProcessUnitID() != 0)
692 return;
693
694#ifdef OPENFPM_PDATA
695
696 std::string c2 = std::string("openfpm_io/test_data/gc_plot2_out_test.html");
697
698#else
699
700 std::string c2 = std::string("test_data/gc_plot2_out_test.html");
701
702#endif
703
705
708
709 x.add("colum1");
710 x.add("colum2");
711 x.add("colum3");
712 x.add("colum4");
713 x.add("colum5");
714 x.add("colum6");
715
716 // Each line can have multiple intervals or error bars
717 // The first number specify the bottom line
718 // The last three numbers specify the top line + error band (min, max)
719 // The middle 5 line specify the middle lines + one external error band + one internal error band
720
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});
727
728 // Google charts options
729 GCoptions options;
730
731 options.title = std::string("Example");
732 options.yAxis = std::string("Y Axis");
733 options.xAxis = std::string("X Axis");
734 options.lineWidth = 1.0;
735
736 GoogleChart cg;
737 cg.AddLinesGraph(x,y,options);
738 cg.write("gc_plot2_out.html");
739
741
742 bool test = compare("gc_plot2_out.html",c2);
743 BOOST_REQUIRE_EQUAL(true,test);
744}
745
747
748double f(double x)
749{
750 return x*x;
751}
752
754
755BOOST_AUTO_TEST_CASE( plot_util )
756{
757 Vcluster<> & v_cl = create_vcluster();
758
759 if (v_cl.getProcessUnitID() != 0)
760 return;
761
763
765
766 Fill1D(0.0,2.0,5,x);
767
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);
773
775
776 x.clear();
777
779
780 Fill1D(0.0,2.0,5,x,f);
781
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);
787
789}
790
791BOOST_AUTO_TEST_SUITE_END()
792
793#endif /* OPENFPM_DATA_SRC_PLOT_PLOT_UNIT_TESTS_HPP_ */
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.
Definition VCluster.hpp:59
Implementation of 1-D std::vector like structure.
Google chart options.
std::string stypeext
std::string intervalext
std::string xAxis
X axis name.
size_t lineWidth
Width of the line.
std::string title
Title of the chart.
bool barWD
barWD
std::string stype
std::string yAxis
Y axis name.