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) Lumiera.org
5  2024, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
29 #include "lib/test/run.hpp"
30 #include "lib/gnuplot-gen.hpp"
31 #include "lib/iter-explorer.hpp"
32 #include "lib/format-cout.hpp"
33 #include "lib/util.hpp"
34 
35 using lib::stat::CSVData;
36 using util::contains;
37 
38 namespace lib {
39 namespace test{
40 
41 
42 
43  /***************************************************************************/
50  class GnuplotGen_test : public Test
51  {
52 
53  virtual void
54  run (Arg)
55  {
56  simpeUsage();
59  }
60 
61 
63  void
65  {
66  string gnuplot = gnuplot_gen::dataPlot(
67  CSVData{{"step","fib"}
68  ,{{0,1}
69  ,{1,1}
70  ,{2,2}
71  ,{3,3}
72  ,{4,5}
73  ,{5,8}
74  ,{6,13}
75  ,{7,21.55}
76  }});
77 // cout << gnuplot <<endl;
78  //Hint: gnuplot -p <scriptfile>
79 
80  CHECK (contains (gnuplot, "set datafile separator \",;\""));
81  CHECK (contains (gnuplot, "\"step\",\"fib\""));
82  CHECK (contains (gnuplot, "7,21.55"));
83  CHECK (contains (gnuplot, "set key autotitle columnheader"));
84  CHECK (contains (gnuplot, "plot for [i=2:*] $RunData using 1:i with points"));
85  }
86 
87 
88 
94  void
96  {
97  string gnuplot = gnuplot_gen::scatterRegression(
98  CSVData{{"step","fib"}
99  ,{{0,1}
100  ,{1,1}
101  ,{2,2}
102  ,{3,3}
103  ,{4,5}
104  ,{5,8}
105  ,{6,13}
106  ,{7,21.55}
107  }});
108 // cout << gnuplot <<endl;
109 
110  CHECK (contains (gnuplot, "\"step\",\"fib\""));
111  CHECK (contains (gnuplot, "7,21.55"));
112  CHECK (contains (gnuplot, "regLine(x) = STATS_slope * x + STATS_intercept"));
113  CHECK (contains (gnuplot, "plot $RunData using 1:2 with points"));
114 
115 
116  gnuplot = gnuplot_gen::scatterRegression(
117  CSVData{{"step","fib","one","two","three"}
118  ,{{0,1 , 1.0, 170,200}
119  ,{1,1 , 0.1, 160,210}
120  ,{2,2 , 1.1, 150,220}
121  ,{3,3 , 0.0, "" ,230}
122  ,{4,5 , 1.1, 130,240}
123  ,{5,8 , 1.2, 120,250}
124  ,{6,13, 1.3, 110 }
125  ,{7,21, 1.4, 100 }
126  }});
127 // cout << gnuplot <<endl;
128 
129  // more than one data row given => using multiplot layout
130  CHECK (contains (gnuplot, "set multiplot"));
131  CHECK (contains (gnuplot, "\"step\",\"fib\",\"one\",\"two\",\"three\""));
132  CHECK (contains (gnuplot, "0,1,1,170,200"));
133  }
134 
135 
145  void
147  {
148  string csv =
149  CSVData{{"abscissa","points","e1","e2","e3"}
150  ,{{1,1 , 1.1,"" ,210}
151  ,{2,2 , 1.2,150,220}
152  ,{3,5 , 5.5,140}
153  }};
154  using namespace gnuplot_gen;
155  string gnuplot = scatterRegression(
156  ParamRecord()
157  .set(KEY_CSVData , csv)
158  .set(KEY_RegrSocket, 3)
159  .set(KEY_RegrSlope, -1.5)
160  .set(KEY_Xtics , 2)
161  .set(KEY_Xrange , "-1:5.5")
162  .set(KEY_Yrange , "0:6")
163  .set(KEY_Y2range, "1.1:1.5")
164  .set(KEY_Y3range, "100:*")
165  .set(KEY_Xlabel , "common axis")
166  .set(KEY_Ylabel , "measurement")
167  .set(KEY_Y2label, "auxiliary-1")
168  .set(KEY_Y3label, "auxiliary-2")
169  .set(KEY_TermSize, "500,800")
170  );
171 // cout << gnuplot <<endl;
172 
173  CHECK (contains (gnuplot, "set term wxt size 500,800"));
174  CHECK (contains (gnuplot, "\"abscissa\",\"points\",\"e1\",\"e2\",\"e3\""));
175  CHECK (contains (gnuplot, "regLine(x) = -1.5 * x + 3"));
176  CHECK (contains (gnuplot, "set xlabel 'common axis'"));
177  CHECK (contains (gnuplot, "set ylabel 'measurement'"));
178  CHECK (contains (gnuplot, "set xrange [-1:5.5]"));
179  CHECK (contains (gnuplot, "set yrange [0:6]"));
180  CHECK (contains (gnuplot, "set yrange [1.1:1.5]"));
181  CHECK (contains (gnuplot, "set ylabel 'auxiliary-1'"));
182  CHECK (contains (gnuplot, "set y2range [100:*]"));
183  CHECK (contains (gnuplot, "set y2label 'auxiliary-2'"));
184  }
185  };
186 
187  LAUNCHER (GnuplotGen_test, "unit common");
188 
189 
190 }} // namespace lib::test
Automatically use custom string conversion in C++ stream output.
Wrapper to simplify notation in tests.
Definition: csv.hpp:149
Definition: run.hpp:49
Preconfigured setup for data visualisation with Gnuplot.
Implementation namespace for support and library code.
Simple 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