Lumiera  0.pre.03
»edit your freedom«
gnuplot-gen-test.cpp
Go to the documentation of this file.
1 /*
2  GnuplotGen(Test) - verify the minimalistic text substitution engine
3 
4  Copyright (C)
5  2024, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
20 #include "lib/test/run.hpp"
21 #include "lib/gnuplot-gen.hpp"
22 #include "lib/iter-explorer.hpp"
23 #include "lib/format-cout.hpp"
24 #include "lib/util.hpp"
25 
26 using lib::stat::CSVData;
27 using util::contains;
28 
29 namespace lib {
30 namespace test{
31 
32 
33 
34  /***************************************************************************/
41  class GnuplotGen_test : public Test
42  {
43 
44  virtual void
45  run (Arg)
46  {
47  simpeUsage();
50  }
51 
52 
54  void
56  {
57  string gnuplot = gnuplot_gen::dataPlot(
58  CSVData{{"step","fib"}
59  ,{{0,1}
60  ,{1,1}
61  ,{2,2}
62  ,{3,3}
63  ,{4,5}
64  ,{5,8}
65  ,{6,13}
66  ,{7,21.55}
67  }});
68 // cout << gnuplot <<endl;
69  //Hint: gnuplot -p <scriptfile>
70 
71  CHECK (contains (gnuplot, "set datafile separator \",;\""));
72  CHECK (contains (gnuplot, "\"step\",\"fib\""));
73  CHECK (contains (gnuplot, "7,21.55"));
74  CHECK (contains (gnuplot, "set key autotitle columnheader"));
75  CHECK (contains (gnuplot, "plot for [i=2:*] $RunData using 1:i with points"));
76  }
77 
78 
79 
85  void
87  {
88  string gnuplot = gnuplot_gen::scatterRegression(
89  CSVData{{"step","fib"}
90  ,{{0,1}
91  ,{1,1}
92  ,{2,2}
93  ,{3,3}
94  ,{4,5}
95  ,{5,8}
96  ,{6,13}
97  ,{7,21.55}
98  }});
99 // cout << gnuplot <<endl;
100 
101  CHECK (contains (gnuplot, "\"step\",\"fib\""));
102  CHECK (contains (gnuplot, "7,21.55"));
103  CHECK (contains (gnuplot, "regLine(x) = STATS_slope * x + STATS_intercept"));
104  CHECK (contains (gnuplot, "plot $RunData using 1:2 with points"));
105 
106 
107  gnuplot = gnuplot_gen::scatterRegression(
108  CSVData{{"step","fib","one","two","three"}
109  ,{{0,1 , 1.0, 170,200}
110  ,{1,1 , 0.1, 160,210}
111  ,{2,2 , 1.1, 150,220}
112  ,{3,3 , 0.0, "" ,230}
113  ,{4,5 , 1.1, 130,240}
114  ,{5,8 , 1.2, 120,250}
115  ,{6,13, 1.3, 110 }
116  ,{7,21, 1.4, 100 }
117  }});
118 // cout << gnuplot <<endl;
119 
120  // more than one data row given => using multiplot layout
121  CHECK (contains (gnuplot, "set multiplot"));
122  CHECK (contains (gnuplot, "\"step\",\"fib\",\"one\",\"two\",\"three\""));
123  CHECK (contains (gnuplot, "0,1,1,170,200"));
124  }
125 
126 
136  void
138  {
139  string csv =
140  CSVData{{"abscissa","points","e1","e2","e3"}
141  ,{{1,1 , 1.1,"" ,210}
142  ,{2,2 , 1.2,150,220}
143  ,{3,5 , 5.5,140}
144  }};
145  using namespace gnuplot_gen;
146  string gnuplot = scatterRegression(
147  ParamRecord()
148  .set(KEY_CSVData , csv)
149  .set(KEY_RegrSocket, 3)
150  .set(KEY_RegrSlope, -1.5)
151  .set(KEY_Xtics , 2)
152  .set(KEY_Xrange , "-1:5.5")
153  .set(KEY_Yrange , "0:6")
154  .set(KEY_Y2range, "1.1:1.5")
155  .set(KEY_Y3range, "100:*")
156  .set(KEY_Xlabel , "common axis")
157  .set(KEY_Ylabel , "measurement")
158  .set(KEY_Y2label, "auxiliary-1")
159  .set(KEY_Y3label, "auxiliary-2")
160  .set(KEY_TermSize, "500,800")
161  );
162 // cout << gnuplot <<endl;
163 
164  CHECK (contains (gnuplot, "set term wxt size 500,800"));
165  CHECK (contains (gnuplot, "\"abscissa\",\"points\",\"e1\",\"e2\",\"e3\""));
166  CHECK (contains (gnuplot, "regLine(x) = -1.5 * x + 3"));
167  CHECK (contains (gnuplot, "set xlabel 'common axis'"));
168  CHECK (contains (gnuplot, "set ylabel 'measurement'"));
169  CHECK (contains (gnuplot, "set xrange [-1:5.5]"));
170  CHECK (contains (gnuplot, "set yrange [0:6]"));
171  CHECK (contains (gnuplot, "set yrange [1.1:1.5]"));
172  CHECK (contains (gnuplot, "set ylabel 'auxiliary-1'"));
173  CHECK (contains (gnuplot, "set y2range [100:*]"));
174  CHECK (contains (gnuplot, "set y2label 'auxiliary-2'"));
175  }
176  };
177 
178  LAUNCHER (GnuplotGen_test, "unit common");
179 
180 
181 }} // namespace lib::test
Automatically use custom string conversion in C++ stream output.
Wrapper to simplify notation in tests.
Definition: csv.hpp:140
Definition: run.hpp:40
Preconfigured setup for data visualisation with Gnuplot.
Implementation namespace for support and library code.
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Building tree expanding and backtracking evaluations within hierarchical scopes.
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container
Definition: util.hpp:255