API
userGainCtrl_test.cpp
Go to the documentation of this file.
1 /** \file userGainCtrl_test.cpp
2  * \brief Catch2 tests for the userGainCtrl app.
3  * \author Jared R. Males (jaredmales@gmail.com)
4  *
5  * History:
6  */
7 
8 
9 
10 #include "../../../tests/catch2/catch.hpp"
11 #include "../../../tests/testMacrosINDI.hpp"
12 
13 #include "../userGainCtrl.hpp"
14 
15 using namespace MagAOX::app;
16 
17 namespace SMCTEST
18 {
19 
21 {
22 
23 public:
24  userGainCtrl_test(const std::string device)
25  {
26  m_configName = device;
27 
29  XWCTEST_SETUP_INDI_NEW_PROP(singleModeNo);
30  XWCTEST_SETUP_INDI_NEW_PROP(singleGain);
32 
33  }
34 };
35 
36 SCENARIO( "INDI Callbacks", "[userGainCtrl]" )
37 {
42  XWCTEST_INDI_ARBNEW_CALLBACK( userGainCtrl, newCallBack_blockGains, block00_gain);
43  XWCTEST_INDI_ARBNEW_CALLBACK( userGainCtrl, newCallBack_blockMCs, block70_multcoeff);
44  XWCTEST_INDI_ARBNEW_CALLBACK( userGainCtrl, newCallBack_blockLimits, block32_limit);
45 
46 }
47 
48 SCENARIO( "Calculating Blocks", "[userGainCtrl]" )
49 {
50  GIVEN("No Zernikes")
51  {
52  int rv;
53  std::vector<uint16_t> blocks;
54  std::vector<std::string> names;
55  //A full block means that all the modes in the last block are present
56  WHEN("Full blocks")
57  {
58  rv = blockModes(blocks, names, 24, 0, false);
59 
60  REQUIRE(rv == 0);
61  REQUIRE(blocks.size() == 1);
62  REQUIRE(blocks[0] == 24);
63 
64  rv = blockModes(blocks, names, 80, 0, false);
65 
66  REQUIRE(rv == 0);
67  REQUIRE(blocks.size() == 2);
68  REQUIRE(blocks[0] == 24);
69  REQUIRE(blocks[1] == 56);
70 
71  rv = blockModes(blocks, names, 168, 0, false);
72 
73  REQUIRE(rv == 0);
74  REQUIRE(blocks.size() == 3);
75  REQUIRE(blocks[0] == 24);
76  REQUIRE(blocks[1] == 56);
77  REQUIRE(blocks[2] == 88);
78  }
79 
80  //A partial block means that not all modes in last block are present
81  WHEN("Partial blocks")
82  {
83  rv = blockModes(blocks, names, 25, 0, false);
84 
85  REQUIRE(rv == 0);
86  REQUIRE(blocks.size() == 2);
87  REQUIRE(blocks[0] == 24);
88  REQUIRE(blocks[1] == 1);
89 
90  rv = blockModes(blocks, names, 85, 0, false);
91 
92  REQUIRE(rv == 0);
93  REQUIRE(blocks.size() == 3);
94  REQUIRE(blocks[0] == 24);
95  REQUIRE(blocks[1] == 56);
96  REQUIRE(blocks[2] == 5);
97 
98  rv = blockModes(blocks, names, 287, 0, false);
99 
100  REQUIRE(rv == 0);
101  REQUIRE(blocks.size() == 4);
102  REQUIRE(blocks[0] == 24);
103  REQUIRE(blocks[1] == 56);
104  REQUIRE(blocks[2] == 88);
105  REQUIRE(blocks[3] == 119);
106 
107  }
108 
109  //Test when Zernikes cover various numbers of blocks
110  WHEN("Full blocks, Zernikes in 1 block, no split")
111  {
112  rv = blockModes(blocks, names, 24, 10, false);
113  REQUIRE(rv == 0);
114  REQUIRE(blocks.size() == 4);
115  REQUIRE(blocks[0] == 2);
116  REQUIRE(blocks[1] == 1);
117  REQUIRE(blocks[2] == 7);
118  REQUIRE(blocks[3] == 14);
119 
120 
121  rv = blockModes(blocks, names, 80, 5, false);
122 
123  REQUIRE(rv == 0);
124  REQUIRE(blocks.size() == 5);
125  REQUIRE(blocks[0] == 2);
126  REQUIRE(blocks[1] == 1);
127  REQUIRE(blocks[2] == 2);
128  REQUIRE(blocks[3] == 19);
129  REQUIRE(blocks[4] == 56);
130 
131  rv = blockModes(blocks, names, 168, 23, false);
132 
133  REQUIRE(rv == 0);
134  REQUIRE(blocks.size() == 6);
135  REQUIRE(blocks[0] == 2);
136  REQUIRE(blocks[1] == 1);
137  REQUIRE(blocks[2] == 20);
138  REQUIRE(blocks[3] == 1);
139  REQUIRE(blocks[4] == 56);
140  REQUIRE(blocks[5] == 88);
141 
142  }
143 
144  WHEN("Full blocks, Zernikes in 2 blocks, no split")
145  {
146  rv = blockModes(blocks, names, 24, 25, false);
147 
148  REQUIRE(rv == 0);
149  REQUIRE(blocks.size() == 3);
150  REQUIRE(blocks[0] == 2);
151  REQUIRE(blocks[1] == 1);
152  REQUIRE(blocks[2] == 22);
153 
154  rv = blockModes(blocks, names, 80, 25, false);
155 
156  REQUIRE(rv == 0);
157  REQUIRE(blocks.size() == 4);
158  REQUIRE(blocks[0] == 2);
159  REQUIRE(blocks[1] == 1);
160  REQUIRE(blocks[2] == 22);
161  REQUIRE(blocks[3] == 55);
162 
163  rv = blockModes(blocks, names, 168, 79, false);
164  REQUIRE(rv == 0);
165  REQUIRE(blocks.size() == 5);
166  REQUIRE(blocks[0] == 2);
167  REQUIRE(blocks[1] == 1);
168  REQUIRE(blocks[2] == 76);
169  REQUIRE(blocks[3] == 1);
170  REQUIRE(blocks[4] == 88);
171 
172  }
173 
174  WHEN("Partial blocks, Zernikes in 1 block, no split")
175  {
176  rv = blockModes(blocks, names, 25, 10, false);
177 
178  REQUIRE(rv == 0);
179  REQUIRE(blocks.size() == 5);
180  REQUIRE(blocks[0] == 2);
181  REQUIRE(blocks[1] == 1);
182  REQUIRE(blocks[2] == 7);
183  REQUIRE(blocks[3] == 14);
184  REQUIRE(blocks[4] == 1);
185 
186  rv = blockModes(blocks, names, 85, 5, false);
187 
188  REQUIRE(rv == 0);
189  REQUIRE(blocks.size() == 6);
190  REQUIRE(blocks[0] == 2);
191  REQUIRE(blocks[1] == 1);
192  REQUIRE(blocks[2] == 2);
193  REQUIRE(blocks[3] == 19);
194  REQUIRE(blocks[4] == 56);
195  REQUIRE(blocks[5] == 5);
196 
197  rv = blockModes(blocks, names, 287, 23, false);
198 
199  REQUIRE(rv == 0);
200  REQUIRE(blocks.size() == 7);
201  REQUIRE(blocks[0] == 2);
202  REQUIRE(blocks[1] == 1);
203  REQUIRE(blocks[2] == 20);
204  REQUIRE(blocks[3] == 1);
205  REQUIRE(blocks[4] == 56);
206  REQUIRE(blocks[5] == 88);
207  REQUIRE(blocks[6] == 119);
208 
209  }
210 
211  WHEN("Partial blocks, Zernikes in 2 blocks, no split")
212  {
213  rv = blockModes(blocks, names, 26, 25, false);
214 
215  REQUIRE(rv == 0);
216  REQUIRE(blocks.size() == 4);
217  REQUIRE(blocks[0] == 2);
218  REQUIRE(blocks[1] == 1);
219  REQUIRE(blocks[2] == 22);
220  REQUIRE(blocks[3] == 1);
221 
222  rv = blockModes(blocks, names, 85, 25, false);
223 
224  REQUIRE(rv == 0);
225  REQUIRE(blocks.size() == 5);
226  REQUIRE(blocks[0] == 2);
227  REQUIRE(blocks[1] == 1);
228  REQUIRE(blocks[2] == 22);
229  REQUIRE(blocks[3] == 55);
230  REQUIRE(blocks[4] == 5);
231 
232  rv = blockModes(blocks, names, 287, 79, false);
233 
234  REQUIRE(rv == 0);
235  REQUIRE(blocks.size() == 6);
236  REQUIRE(blocks[0] == 2);
237  REQUIRE(blocks[1] == 1);
238  REQUIRE(blocks[2] == 76);
239  REQUIRE(blocks[3] == 1); //b = 1, 80
240  REQUIRE(blocks[4] == 88); //b = 2, 168
241  REQUIRE(blocks[5] == 119);
242 
243  }
244 
245  WHEN("Full blocks, Zernikes in 1 block, with split")
246  {
247  rv = blockModes(blocks, names, 24, 10, true);
248  REQUIRE(rv == 0);
249  REQUIRE(blocks.size() == 5);
250  REQUIRE(blocks[0] == 1);
251  REQUIRE(blocks[1] == 1);
252  REQUIRE(blocks[2] == 1);
253  REQUIRE(blocks[3] == 7);
254  REQUIRE(blocks[4] == 14);
255 
256 
257  rv = blockModes(blocks, names, 80, 5, true);
258 
259  REQUIRE(rv == 0);
260  REQUIRE(blocks.size() == 6);
261  REQUIRE(blocks[0] == 1);
262  REQUIRE(blocks[1] == 1);
263  REQUIRE(blocks[2] == 1);
264  REQUIRE(blocks[3] == 2);
265  REQUIRE(blocks[4] == 19);
266  REQUIRE(blocks[5] == 56);
267 
268  rv = blockModes(blocks, names, 168, 23, true);
269 
270  REQUIRE(rv == 0);
271  REQUIRE(blocks.size() == 7);
272  REQUIRE(blocks[0] == 1);
273  REQUIRE(blocks[1] == 1);
274  REQUIRE(blocks[2] == 1);
275  REQUIRE(blocks[3] == 20);
276  REQUIRE(blocks[4] == 1);
277  REQUIRE(blocks[5] == 56);
278  REQUIRE(blocks[6] == 88);
279 
280  }
281 
282  WHEN("Full blocks, Zernikes in 2 blocks, with split")
283  {
284  rv = blockModes(blocks, names, 24, 25, true);
285 
286  REQUIRE(rv == 0);
287  REQUIRE(blocks.size() == 4);
288  REQUIRE(blocks[0] == 1);
289  REQUIRE(blocks[1] == 1);
290  REQUIRE(blocks[2] == 1);
291  REQUIRE(blocks[3] == 22);
292 
293  rv = blockModes(blocks, names, 80, 25, true);
294 
295  REQUIRE(rv == 0);
296  REQUIRE(blocks.size() == 5);
297  REQUIRE(blocks[0] == 1);
298  REQUIRE(blocks[1] == 1);
299  REQUIRE(blocks[2] == 1);
300  REQUIRE(blocks[3] == 22);
301  REQUIRE(blocks[4] == 55);
302 
303  rv = blockModes(blocks, names, 168, 79, true);
304  REQUIRE(rv == 0);
305  REQUIRE(blocks.size() == 6);
306  REQUIRE(blocks[0] == 1);
307  REQUIRE(blocks[1] == 1);
308  REQUIRE(blocks[2] == 1);
309  REQUIRE(blocks[3] == 76);
310  REQUIRE(blocks[4] == 1);
311  REQUIRE(blocks[5] == 88);
312 
313  }
314 
315  WHEN("Partial blocks, Zernikes in 1 block, with split")
316  {
317  rv = blockModes(blocks, names, 25, 10, true);
318 
319  REQUIRE(rv == 0);
320  REQUIRE(blocks.size() == 6);
321  REQUIRE(blocks[0] == 1);
322  REQUIRE(blocks[1] == 1);
323  REQUIRE(blocks[2] == 1);
324  REQUIRE(blocks[3] == 7);
325  REQUIRE(blocks[4] == 14);
326  REQUIRE(blocks[5] == 1);
327 
328  rv = blockModes(blocks, names, 85, 5, true);
329 
330  REQUIRE(rv == 0);
331  REQUIRE(blocks.size() == 7);
332  REQUIRE(blocks[0] == 1);
333  REQUIRE(blocks[1] == 1);
334  REQUIRE(blocks[2] == 1);
335  REQUIRE(blocks[3] == 2);
336  REQUIRE(blocks[4] == 19);
337  REQUIRE(blocks[5] == 56);
338  REQUIRE(blocks[6] == 5);
339 
340  rv = blockModes(blocks, names, 287, 23, true);
341 
342  REQUIRE(rv == 0);
343  REQUIRE(blocks.size() == 8);
344  REQUIRE(blocks[0] == 1);
345  REQUIRE(blocks[1] == 1);
346  REQUIRE(blocks[2] == 1);
347  REQUIRE(blocks[3] == 20);
348  REQUIRE(blocks[4] == 1);
349  REQUIRE(blocks[5] == 56);
350  REQUIRE(blocks[6] == 88);
351  REQUIRE(blocks[7] == 119);
352 
353  }
354 
355  WHEN("Partial blocks, Zernikes in 2 blocks, with split")
356  {
357  rv = blockModes(blocks, names, 26, 25, true);
358 
359  REQUIRE(rv == 0);
360  REQUIRE(blocks.size() == 5);
361  REQUIRE(blocks[0] == 1);
362  REQUIRE(blocks[1] == 1);
363  REQUIRE(blocks[2] == 1);
364  REQUIRE(blocks[3] == 22);
365  REQUIRE(blocks[4] == 1);
366 
367  rv = blockModes(blocks, names, 85, 25, true);
368 
369  REQUIRE(rv == 0);
370  REQUIRE(blocks.size() == 6);
371  REQUIRE(blocks[0] == 1);
372  REQUIRE(blocks[1] == 1);
373  REQUIRE(blocks[2] == 1);
374  REQUIRE(blocks[3] == 22);
375  REQUIRE(blocks[4] == 55);
376  REQUIRE(blocks[5] == 5);
377 
378  rv = blockModes(blocks, names, 287, 79, true);
379 
380  REQUIRE(rv == 0);
381  REQUIRE(blocks.size() == 7);
382  REQUIRE(blocks[0] == 1);
383  REQUIRE(blocks[1] == 1);
384  REQUIRE(blocks[2] == 1);
385  REQUIRE(blocks[3] == 76);
386  REQUIRE(blocks[4] == 1); //b = 1, 80
387  REQUIRE(blocks[5] == 88); //b = 2, 168
388  REQUIRE(blocks[6] == 119);
389 
390  }
391 
392  //Test if it all generalizes to even more zernikes
393  WHEN("Partial blocks, Zernikes in 3 blocks, with split")
394  {
395  rv = blockModes(blocks, names, 26, 81, true); //this should give 81 modes and quit
396 
397  REQUIRE(rv == 0);
398  REQUIRE(blocks.size() == 4);
399  REQUIRE(blocks[0] == 1);
400  REQUIRE(blocks[1] == 1);
401  REQUIRE(blocks[2] == 1);
402  REQUIRE(blocks[3] == 78);
403 
404  rv = blockModes(blocks, names, 85, 81, true);
405 
406  REQUIRE(rv == 0);
407  REQUIRE(blocks.size() == 5);
408  REQUIRE(blocks[0] == 1);
409  REQUIRE(blocks[1] == 1);
410  REQUIRE(blocks[2] == 1);
411  REQUIRE(blocks[3] == 78);
412  REQUIRE(blocks[4] == 4);
413 
414  rv = blockModes(blocks, names, 287, 100, true);
415 
416  REQUIRE(rv == 0);
417  REQUIRE(blocks.size() == 6);
418  REQUIRE(blocks[0] == 1);
419  REQUIRE(blocks[1] == 1);
420  REQUIRE(blocks[2] == 1);
421  REQUIRE(blocks[3] == 97);
422  REQUIRE(blocks[4] == 68); //b = 2, 168
423  REQUIRE(blocks[5] == 119);
424 
425  }
426 
427  WHEN("The Full MagAO-X")
428  {
429  rv = blockModes(blocks, names, 2400, 10, true); //this should give 81 modes and quite
430 
431  REQUIRE(rv == 0);
432  REQUIRE(blocks.size() == 16);
433  REQUIRE(blocks[0] == 1);
434  REQUIRE(blocks[1] == 1);
435  REQUIRE(blocks[2] == 1);
436  REQUIRE(blocks[3] == 7);
437  REQUIRE(blocks[4] == 14); //b=0 remainder
438  REQUIRE(blocks[5] == 56); //b=1
439  REQUIRE(blocks[6] == 88);
440  REQUIRE(blocks[7] == 120);
441  REQUIRE(blocks[8] == 152);
442  REQUIRE(blocks[9] == 184);
443  REQUIRE(blocks[10] == 216);
444  REQUIRE(blocks[11] == 248);
445  REQUIRE(blocks[12] == 280);
446  REQUIRE(blocks[13] == 312);
447  REQUIRE(blocks[14] == 344);
448  REQUIRE(blocks[15] == 376);
449  }
450  }
451 }
452 
453 
454 } //namespace userGainCtrl_test
#define GIVEN(desc)
Definition: catch.hpp:17763
#define WHEN(desc)
Definition: catch.hpp:17765
#define REQUIRE(...)
Definition: catch.hpp:17676
userGainCtrl_test(const std::string device)
#define XWCTEST_INDI_NEW_CALLBACK(testclass, propname)
Catch-2 tests for whether a NEW callback properly validates the input property properly.
#define XWCTEST_INDI_ARBNEW_CALLBACK(testclass, callback, propname)
Catch-2 tests for whether an arbitrary callback properly validates the input property properly.
int blockModes(std::vector< uint16_t > &blocks, std::vector< std::string > &names, uint16_t Nmodes, uint16_t Nzern, bool splitTT)
Calculate the number of blocks and the number of modes per block.
SCENARIO("Calculating Blocks", "[userGainCtrl]")
#define XWCTEST_SETUP_INDI_NEW_PROP(propname)