/[svn]/linuxsampler/trunk/src/scriptvm/tests/NKSPTest.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/scriptvm/tests/NKSPTest.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3590 - (hide annotations) (download)
Mon Sep 2 09:03:31 2019 UTC (6 months, 3 weeks ago) by schoenebeck
File size: 182731 byte(s)
NKSP: Implemented common real number math functions.

* Added built-in real number functions "round()", "ceil()", "floor()",
  "sqrt()", "log()", "log2()", "log10()", "exp()", "pow()", "sin()",
  "cos()", "tan()", "asin()", "acos()", "atan()".

* Added built-in script real number constant "~NI_MATH_PI".

* Added built-in script real number constant "~NI_MATH_E".

* Added NKSP test cases for built-in functions "round()", "ceil()",
  "floor()", "sqrt()", "log()", "log2()", "log10()", "exp()", "pow()",
  "sin()", "cos()", "tan()", "asin()", "acos()", "atan()".

* Bumped version (2.1.1.svn14).

1 schoenebeck 3551 /*
2     * Copyright (c) 2019 Christian Schoenebeck
3     *
4     * http://www.linuxsampler.org
5     *
6     * This file is part of LinuxSampler and released under the same terms.
7     * See README file for details.
8     */
9    
10     // This file contains automated test cases against the NKSP real-time
11     // instrument script engine.
12    
13     #include "../../common/global.h"
14     #include "../../common/optional.h"
15 schoenebeck 3575 #include "../../common/RTMath.h"
16 schoenebeck 3551 #include "../ScriptVM.h"
17     #include "../common.h"
18     #include <sstream>
19     #include <stdlib.h>
20     #include <time.h>
21     #include <assert.h>
22     #include <functional>
23    
24     #ifndef TEST_ASSERT
25     # define TEST_ASSERT assert
26     #endif
27    
28     using namespace LinuxSampler;
29     using namespace std;
30    
31     struct RunScriptOpt {
32     String code;
33     bool expectParseError;
34 schoenebeck 3581 bool expectParseWarning;
35 schoenebeck 3551 bool expectRuntimeError;
36     bool expectNoExitResult;
37 schoenebeck 3581 bool expectExitResultIsInt;
38     bool expectExitResultIsReal;
39 schoenebeck 3551 bool prohibitExitFunctionArguments;
40 schoenebeck 3575 optional<vmint> expectIntExitResult;
41 schoenebeck 3551 optional<bool> expectBoolExitResult;
42 schoenebeck 3575 optional<vmfloat> expectRealExitResult;
43 schoenebeck 3551 optional<String> expectStringExitResult;
44 schoenebeck 3581 vector<MetricPrefix_t> expectExitResultUnitPrefix;
45     optional<StdUnit_t> expectExitResultUnit;
46     optional<bool> expectExitResultFinal;
47 schoenebeck 3551 };
48    
49     static void runScript(const RunScriptOpt& opt) {
50     ScriptVM vm;
51     vm.setAutoSuspendEnabled(false);
52     if (!opt.prohibitExitFunctionArguments)
53     vm.setExitResultEnabled(true);
54     unique_ptr<VMParserContext> parserCtx(
55     vm.loadScript(opt.code)
56     );
57     vector<ParserIssue> errors = parserCtx->errors();
58 schoenebeck 3581 vector<ParserIssue> warnings = parserCtx->warnings();
59 schoenebeck 3551 if (opt.expectParseError) {
60     TEST_ASSERT(!errors.empty());
61     return;
62     } else {
63     for (ParserIssue& err : errors) {
64     err.dump();
65     }
66     TEST_ASSERT(errors.empty());
67     }
68 schoenebeck 3581 if (opt.expectParseWarning) {
69     TEST_ASSERT(!warnings.empty());
70     } else {
71     for (ParserIssue& wrn : warnings) {
72     wrn.dump();
73     }
74     }
75 schoenebeck 3551 TEST_ASSERT(parserCtx->eventHandler(0));
76     unique_ptr<VMExecContext> execCtx(
77     vm.createExecContext(&*parserCtx)
78     );
79     for (int i = 0; parserCtx->eventHandler(i); ++i) {
80     VMEventHandler* handler = parserCtx->eventHandler(i);
81     VMExecStatus_t result = vm.exec(&*parserCtx, &*execCtx, handler);
82     if (opt.expectRuntimeError) {
83     TEST_ASSERT(result & VM_EXEC_ERROR);
84     } else {
85     TEST_ASSERT(!(result & VM_EXEC_ERROR));
86     }
87     if (opt.expectNoExitResult) {
88     VMExpr* resExpr = execCtx->exitResult();
89     TEST_ASSERT(!resExpr);
90     }
91 schoenebeck 3581 if (opt.expectExitResultIsInt) {
92     VMExpr* resExpr = execCtx->exitResult();
93     TEST_ASSERT(resExpr);
94     TEST_ASSERT(resExpr->exprType() == INT_EXPR);
95     }
96     if (opt.expectExitResultIsReal) {
97     VMExpr* resExpr = execCtx->exitResult();
98     TEST_ASSERT(resExpr);
99     TEST_ASSERT(resExpr->exprType() == REAL_EXPR);
100     }
101 schoenebeck 3551 if (opt.expectIntExitResult) {
102     VMExpr* resExpr = execCtx->exitResult();
103     TEST_ASSERT(resExpr);
104     TEST_ASSERT(resExpr->exprType() == INT_EXPR);
105     TEST_ASSERT(resExpr->asInt()->evalInt() == *opt.expectIntExitResult);
106     }
107 schoenebeck 3575 if (opt.expectRealExitResult) {
108     VMExpr* resExpr = execCtx->exitResult();
109     TEST_ASSERT(resExpr);
110     TEST_ASSERT(resExpr->exprType() == REAL_EXPR);
111     if (sizeof(vmfloat) == sizeof(float)) {
112     TEST_ASSERT(RTMath::fEqual32(resExpr->asReal()->evalReal(), *opt.expectRealExitResult));
113     } else {
114     TEST_ASSERT(RTMath::fEqual64(resExpr->asReal()->evalReal(), *opt.expectRealExitResult));
115     }
116     }
117 schoenebeck 3551 if (opt.expectBoolExitResult) {
118     VMExpr* resExpr = execCtx->exitResult();
119     TEST_ASSERT(resExpr);
120     TEST_ASSERT(resExpr->exprType() == INT_EXPR);
121     TEST_ASSERT(bool(resExpr->asInt()->evalInt()) == *opt.expectBoolExitResult);
122     }
123     if (opt.expectStringExitResult) {
124     VMExpr* resExpr = execCtx->exitResult();
125     TEST_ASSERT(resExpr);
126     TEST_ASSERT(resExpr->exprType() == STRING_EXPR);
127     TEST_ASSERT(resExpr->asString()->evalStr() == *opt.expectStringExitResult);
128     }
129 schoenebeck 3581 if (opt.expectExitResultUnit) {
130     VMExpr* resExpr = execCtx->exitResult();
131     TEST_ASSERT(resExpr);
132 schoenebeck 3582 VMNumberExpr* numberExpr = resExpr->asNumber();
133 schoenebeck 3581 TEST_ASSERT(numberExpr);
134     TEST_ASSERT(numberExpr->unitType() == *opt.expectExitResultUnit);
135     }
136     if (!opt.expectExitResultUnitPrefix.empty()) {
137     VMExpr* resExpr = execCtx->exitResult();
138     TEST_ASSERT(resExpr);
139 schoenebeck 3582 VMNumberExpr* numberExpr = resExpr->asNumber();
140 schoenebeck 3581 TEST_ASSERT(numberExpr);
141     auto prefixes = opt.expectExitResultUnitPrefix;
142     if (*prefixes.rbegin() != VM_NO_PREFIX)
143     prefixes.push_back(VM_NO_PREFIX); // VM_NO_PREFIX termination required by unitFactr() call
144     vmfloat expectedFactor = VMUnit::unitFactor(&prefixes[0]);
145     vmfloat actualFactor = numberExpr->unitFactor();
146     if (sizeof(vmfloat) == sizeof(float)) {
147     TEST_ASSERT(RTMath::fEqual32(expectedFactor, actualFactor));
148     } else {
149     TEST_ASSERT(RTMath::fEqual64(expectedFactor, actualFactor));
150     }
151     }
152     if (opt.expectExitResultFinal) {
153     VMExpr* resExpr = execCtx->exitResult();
154     TEST_ASSERT(resExpr);
155 schoenebeck 3582 VMNumberExpr* numberExpr = resExpr->asNumber();
156 schoenebeck 3581 TEST_ASSERT(numberExpr);
157     TEST_ASSERT(numberExpr->isFinal() == *opt.expectExitResultFinal);
158     }
159 schoenebeck 3551 }
160     }
161    
162     static void testBuiltInExitFunction() {
163     #if !SILENT_TEST
164     std::cout << "UNIT TEST: built-in exit() function\n";
165     #endif
166    
167     runScript({
168     .code = R"NKSP_CODE(
169     on init
170     end on
171     )NKSP_CODE",
172     .expectNoExitResult = true
173     });
174    
175     runScript({
176     .code = R"NKSP_CODE(
177     on init
178     exit
179     end on
180     )NKSP_CODE",
181     .expectNoExitResult = true
182     });
183    
184     runScript({
185     .code = R"NKSP_CODE(
186     on init
187     exit()
188     end on
189     )NKSP_CODE",
190     .expectNoExitResult = true
191     });
192    
193 schoenebeck 3575 // integer tests ...
194    
195 schoenebeck 3551 runScript({
196     .code = R"NKSP_CODE(
197     on init
198     exit(42)
199     end on
200     )NKSP_CODE",
201     .expectIntExitResult = 42
202     });
203    
204     runScript({
205     .code = R"NKSP_CODE(
206     on init
207     declare $foo := 1
208     if ($foo)
209     exit(21)
210     end if
211     end on
212     )NKSP_CODE",
213     .expectIntExitResult = 21
214     });
215    
216     runScript({
217     .code = R"NKSP_CODE(
218     on init
219     declare $foo := 0
220     if ($foo)
221     exit(21)
222     end if
223     exit(99)
224     end on
225     )NKSP_CODE",
226     .expectIntExitResult = 99
227     });
228    
229 schoenebeck 3575 // string tests ...
230    
231 schoenebeck 3551 runScript({
232     .code = R"NKSP_CODE(
233     on init
234     exit("fourtytwo!")
235     end on
236     )NKSP_CODE",
237     .expectStringExitResult = "fourtytwo!"
238     });
239    
240     // in production environment we prohibit the built-in exit() function to
241     // accept any arguments
242     runScript({
243     .code = R"NKSP_CODE(
244     on init
245     exit(42)
246     end on
247     )NKSP_CODE",
248     .expectParseError = true, // see comment above why
249     .prohibitExitFunctionArguments = true // simulate production environment
250     });
251    
252 schoenebeck 3575 // real number tests ...
253    
254     runScript({
255     .code = R"NKSP_CODE(
256     on init
257     exit(3.14)
258     end on
259     )NKSP_CODE",
260     .expectRealExitResult = 3.14
261     });
262    
263     runScript({
264     .code = R"NKSP_CODE(
265     on init
266     declare $foo := 1
267     if ($foo)
268     exit(3.14)
269     end if
270     end on
271     )NKSP_CODE",
272     .expectRealExitResult = 3.14
273     });
274    
275     runScript({
276     .code = R"NKSP_CODE(
277     on init
278     declare $foo := 0
279     if ($foo)
280     exit(3.14)
281     end if
282     exit(6.9)
283     end on
284     )NKSP_CODE",
285     .expectRealExitResult = 6.9
286     });
287    
288 schoenebeck 3586 // int array tests ...
289    
290     runScript({
291     .code = R"NKSP_CODE(
292     on init
293     declare %foo[3]
294     %foo[0] := 21
295     exit(%foo[0])
296     end on
297     )NKSP_CODE",
298     .expectIntExitResult = 21
299     });
300    
301     runScript({
302     .code = R"NKSP_CODE(
303     on init
304     declare %foo[3] := ( 12, 23, 34 )
305     exit(%foo[0])
306     end on
307     )NKSP_CODE",
308     .expectIntExitResult = 12
309     });
310    
311     runScript({
312     .code = R"NKSP_CODE(
313     on init
314     declare %foo[3] := ( 12, 23, 34 )
315     exit(%foo[1])
316     end on
317     )NKSP_CODE",
318     .expectIntExitResult = 23
319     });
320    
321     runScript({
322     .code = R"NKSP_CODE(
323     on init
324     declare %foo[3] := ( 12, 23, 34 )
325     exit(%foo[2])
326     end on
327     )NKSP_CODE",
328     .expectIntExitResult = 34
329     });
330    
331     runScript({ // make sure array is entirely initialized with zeroes
332     .code = R"NKSP_CODE(
333     on init
334     declare $i
335     declare $result
336     declare %foo[100]
337     while ($i < 100)
338     $result := $result .or. %foo[$i]
339     inc($i)
340     end while
341     exit($result)
342     end on
343     )NKSP_CODE",
344     .expectIntExitResult = 0
345     });
346    
347     // real array tests ...
348    
349     runScript({
350     .code = R"NKSP_CODE(
351     on init
352     declare ?foo[3]
353     ?foo[0] := 34.9
354     exit(?foo[0])
355     end on
356     )NKSP_CODE",
357     .expectRealExitResult = 34.9
358     });
359    
360     runScript({
361     .code = R"NKSP_CODE(
362     on init
363     declare ?foo[3] := ( 0.3, 23.5, 900.1 )
364     exit(?foo[0])
365     end on
366     )NKSP_CODE",
367     .expectRealExitResult = 0.3
368     });
369    
370     runScript({
371     .code = R"NKSP_CODE(
372     on init
373     declare ?foo[3] := ( 0.3, 23.5, 900.1 )
374     exit(?foo[1])
375     end on
376     )NKSP_CODE",
377     .expectRealExitResult = 23.5
378     });
379    
380     runScript({
381     .code = R"NKSP_CODE(
382     on init
383     declare ?foo[3] := ( 0.3, 23.5, 900.1 )
384     exit(?foo[2])
385     end on
386     )NKSP_CODE",
387     .expectRealExitResult = 900.1
388     });
389    
390     runScript({ // make sure array is entirely initialized with zeroes
391     .code = R"NKSP_CODE(
392     on init
393     declare $i
394     declare ?foo[100]
395     while ($i < 100)
396     if (?foo[$i] # 0.0)
397     exit(-1) { test failed }
398     end if
399     inc($i)
400     end while
401     exit(0) { test succeeded }
402     end on
403     )NKSP_CODE",
404     .expectIntExitResult = 0
405     });
406    
407 schoenebeck 3581 // std unit tests ...
408    
409     runScript({
410     .code = R"NKSP_CODE(
411     on init
412     exit(42s)
413     end on
414     )NKSP_CODE",
415     .expectIntExitResult = 42,
416     .expectExitResultUnit = VM_SECOND
417     });
418    
419     runScript({
420     .code = R"NKSP_CODE(
421     on init
422     exit(42Hz)
423     end on
424     )NKSP_CODE",
425     .expectIntExitResult = 42,
426     .expectExitResultUnit = VM_HERTZ
427     });
428    
429     runScript({
430     .code = R"NKSP_CODE(
431     on init
432     exit(42B)
433     end on
434     )NKSP_CODE",
435     .expectIntExitResult = 42,
436     .expectExitResultUnit = VM_BEL
437     });
438    
439     runScript({
440     .code = R"NKSP_CODE(
441     on init
442     exit(42us)
443     end on
444     )NKSP_CODE",
445     .expectIntExitResult = 42,
446     .expectExitResultUnitPrefix = { VM_MICRO },
447     .expectExitResultUnit = VM_SECOND
448     });
449    
450     runScript({
451     .code = R"NKSP_CODE(
452     on init
453     exit(42ms)
454     end on
455     )NKSP_CODE",
456     .expectIntExitResult = 42,
457     .expectExitResultUnitPrefix = { VM_MILLI },
458     .expectExitResultUnit = VM_SECOND
459     });
460    
461     runScript({
462     .code = R"NKSP_CODE(
463     on init
464     exit(42cs)
465     end on
466     )NKSP_CODE",
467     .expectIntExitResult = 42,
468     .expectExitResultUnitPrefix = { VM_CENTI },
469     .expectExitResultUnit = VM_SECOND
470     });
471    
472     runScript({
473     .code = R"NKSP_CODE(
474     on init
475     exit(42ds)
476     end on
477     )NKSP_CODE",
478     .expectIntExitResult = 42,
479     .expectExitResultUnitPrefix = { VM_DECI },
480     .expectExitResultUnit = VM_SECOND
481     });
482    
483     runScript({
484     .code = R"NKSP_CODE(
485     on init
486     exit(42das)
487     end on
488     )NKSP_CODE",
489     .expectIntExitResult = 42,
490     .expectExitResultUnitPrefix = { VM_DECA },
491     .expectExitResultUnit = VM_SECOND
492     });
493    
494     runScript({
495     .code = R"NKSP_CODE(
496     on init
497     exit(42hs)
498     end on
499     )NKSP_CODE",
500     .expectIntExitResult = 42,
501     .expectExitResultUnitPrefix = { VM_HECTO },
502     .expectExitResultUnit = VM_SECOND
503     });
504    
505     runScript({
506     .code = R"NKSP_CODE(
507     on init
508     exit(42ks)
509     end on
510     )NKSP_CODE",
511     .expectIntExitResult = 42,
512     .expectExitResultUnitPrefix = { VM_KILO },
513     .expectExitResultUnit = VM_SECOND
514     });
515    
516     runScript({
517     .code = R"NKSP_CODE(
518     on init
519     exit(42s)
520     end on
521     )NKSP_CODE",
522     .expectIntExitResult = 42,
523     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
524     .expectExitResultUnit = VM_SECOND
525     });
526    
527     runScript({
528     .code = R"NKSP_CODE(
529     on init
530     exit(42uHz)
531     end on
532     )NKSP_CODE",
533     .expectIntExitResult = 42,
534     .expectExitResultUnitPrefix = { VM_MICRO },
535     .expectExitResultUnit = VM_HERTZ
536     });
537    
538     runScript({
539     .code = R"NKSP_CODE(
540     on init
541     exit(42mHz)
542     end on
543     )NKSP_CODE",
544     .expectIntExitResult = 42,
545     .expectExitResultUnitPrefix = { VM_MILLI },
546     .expectExitResultUnit = VM_HERTZ
547     });
548    
549     runScript({
550     .code = R"NKSP_CODE(
551     on init
552     exit(42cHz)
553     end on
554     )NKSP_CODE",
555     .expectIntExitResult = 42,
556     .expectExitResultUnitPrefix = { VM_CENTI },
557     .expectExitResultUnit = VM_HERTZ
558     });
559    
560     runScript({
561     .code = R"NKSP_CODE(
562     on init
563     exit(42dHz)
564     end on
565     )NKSP_CODE",
566     .expectIntExitResult = 42,
567     .expectExitResultUnitPrefix = { VM_DECI },
568     .expectExitResultUnit = VM_HERTZ
569     });
570    
571     runScript({
572     .code = R"NKSP_CODE(
573     on init
574     exit(42daHz)
575     end on
576     )NKSP_CODE",
577     .expectIntExitResult = 42,
578     .expectExitResultUnitPrefix = { VM_DECA },
579     .expectExitResultUnit = VM_HERTZ
580     });
581    
582     runScript({
583     .code = R"NKSP_CODE(
584     on init
585     exit(42hHz)
586     end on
587     )NKSP_CODE",
588     .expectIntExitResult = 42,
589     .expectExitResultUnitPrefix = { VM_HECTO },
590     .expectExitResultUnit = VM_HERTZ
591     });
592    
593     runScript({
594     .code = R"NKSP_CODE(
595     on init
596     exit(42kHz)
597     end on
598     )NKSP_CODE",
599     .expectIntExitResult = 42,
600     .expectExitResultUnitPrefix = { VM_KILO },
601     .expectExitResultUnit = VM_HERTZ
602     });
603    
604     runScript({
605     .code = R"NKSP_CODE(
606     on init
607     exit(42Hz)
608     end on
609     )NKSP_CODE",
610     .expectIntExitResult = 42,
611     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
612     .expectExitResultUnit = VM_HERTZ
613     });
614    
615     runScript({
616     .code = R"NKSP_CODE(
617     on init
618     exit(42uB)
619     end on
620     )NKSP_CODE",
621     .expectIntExitResult = 42,
622     .expectExitResultUnitPrefix = { VM_MICRO },
623     .expectExitResultUnit = VM_BEL
624     });
625    
626     runScript({
627     .code = R"NKSP_CODE(
628     on init
629     exit(42mB)
630     end on
631     )NKSP_CODE",
632     .expectIntExitResult = 42,
633     .expectExitResultUnitPrefix = { VM_MILLI },
634     .expectExitResultUnit = VM_BEL
635     });
636    
637     runScript({
638     .code = R"NKSP_CODE(
639     on init
640     exit(42cB)
641     end on
642     )NKSP_CODE",
643     .expectIntExitResult = 42,
644     .expectExitResultUnitPrefix = { VM_CENTI },
645     .expectExitResultUnit = VM_BEL
646     });
647    
648     runScript({
649     .code = R"NKSP_CODE(
650     on init
651     exit(42dB)
652     end on
653     )NKSP_CODE",
654     .expectIntExitResult = 42,
655     .expectExitResultUnitPrefix = { VM_DECI },
656     .expectExitResultUnit = VM_BEL
657     });
658    
659     runScript({
660     .code = R"NKSP_CODE(
661     on init
662     exit(42daB)
663     end on
664     )NKSP_CODE",
665     .expectIntExitResult = 42,
666     .expectExitResultUnitPrefix = { VM_DECA },
667     .expectExitResultUnit = VM_BEL
668     });
669    
670     runScript({
671     .code = R"NKSP_CODE(
672     on init
673     exit(42hB)
674     end on
675     )NKSP_CODE",
676     .expectIntExitResult = 42,
677     .expectExitResultUnitPrefix = { VM_HECTO },
678     .expectExitResultUnit = VM_BEL
679     });
680    
681     runScript({
682     .code = R"NKSP_CODE(
683     on init
684     exit(42kB)
685     end on
686     )NKSP_CODE",
687     .expectIntExitResult = 42,
688     .expectExitResultUnitPrefix = { VM_KILO },
689     .expectExitResultUnit = VM_BEL
690     });
691    
692     runScript({
693     .code = R"NKSP_CODE(
694     on init
695     exit(42B)
696     end on
697     )NKSP_CODE",
698     .expectIntExitResult = 42,
699     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
700     .expectExitResultUnit = VM_BEL
701     });
702    
703     runScript({
704     .code = R"NKSP_CODE(
705     on init
706     exit(42udB)
707     end on
708     )NKSP_CODE",
709     .expectIntExitResult = 42,
710     .expectExitResultUnitPrefix = { VM_MICRO, VM_DECI },
711     .expectExitResultUnit = VM_BEL
712     });
713    
714     runScript({
715     .code = R"NKSP_CODE(
716     on init
717     exit(42mdB)
718     end on
719     )NKSP_CODE",
720     .expectIntExitResult = 42,
721     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
722     .expectExitResultUnit = VM_BEL
723     });
724    
725     runScript({
726     .code = R"NKSP_CODE(
727     on init
728     exit(42cdB)
729     end on
730     )NKSP_CODE",
731     .expectIntExitResult = 42,
732     .expectExitResultUnitPrefix = { VM_CENTI, VM_DECI },
733     .expectExitResultUnit = VM_BEL
734     });
735    
736     runScript({
737     .code = R"NKSP_CODE(
738     on init
739     exit(42ddB)
740     end on
741     )NKSP_CODE",
742     .expectIntExitResult = 42,
743     .expectExitResultUnitPrefix = { VM_DECI, VM_DECI },
744     .expectExitResultUnit = VM_BEL
745     });
746    
747     runScript({
748     .code = R"NKSP_CODE(
749     on init
750     exit(42dadB)
751     end on
752     )NKSP_CODE",
753     .expectIntExitResult = 42,
754     .expectExitResultUnitPrefix = { VM_DECA, VM_DECI },
755     .expectExitResultUnit = VM_BEL
756     });
757    
758     runScript({
759     .code = R"NKSP_CODE(
760     on init
761     exit(42hdB)
762     end on
763     )NKSP_CODE",
764     .expectIntExitResult = 42,
765     .expectExitResultUnitPrefix = { VM_HECTO, VM_DECI },
766     .expectExitResultUnit = VM_BEL
767     });
768    
769     runScript({
770     .code = R"NKSP_CODE(
771     on init
772     exit(42kdB)
773     end on
774     )NKSP_CODE",
775     .expectIntExitResult = 42,
776     .expectExitResultUnitPrefix = { VM_KILO, VM_DECI },
777     .expectExitResultUnit = VM_BEL
778     });
779    
780     runScript({
781     .code = R"NKSP_CODE(
782     on init
783     declare $foo := 42mdB
784     exit($foo)
785     end on
786     )NKSP_CODE",
787     .expectIntExitResult = 42,
788     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
789     .expectExitResultUnit = VM_BEL
790     });
791    
792     runScript({
793     .code = R"NKSP_CODE(
794     on init
795     exit(3.14s)
796     end on
797     )NKSP_CODE",
798     .expectRealExitResult = 3.14,
799     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
800     .expectExitResultUnit = VM_SECOND
801     });
802    
803     runScript({
804     .code = R"NKSP_CODE(
805     on init
806     exit(3.14us)
807     end on
808     )NKSP_CODE",
809     .expectRealExitResult = 3.14,
810     .expectExitResultUnitPrefix = { VM_MICRO },
811     .expectExitResultUnit = VM_SECOND
812     });
813    
814     runScript({
815     .code = R"NKSP_CODE(
816     on init
817     exit(3.14ms)
818     end on
819     )NKSP_CODE",
820     .expectRealExitResult = 3.14,
821     .expectExitResultUnitPrefix = { VM_MILLI },
822     .expectExitResultUnit = VM_SECOND
823     });
824    
825     runScript({
826     .code = R"NKSP_CODE(
827     on init
828     exit(-0.1B)
829     end on
830     )NKSP_CODE",
831     .expectRealExitResult = -0.1,
832     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
833     .expectExitResultUnit = VM_BEL
834     });
835    
836     runScript({
837     .code = R"NKSP_CODE(
838     on init
839     exit(-0.1dB)
840     end on
841     )NKSP_CODE",
842     .expectRealExitResult = -0.1,
843     .expectExitResultUnitPrefix = { VM_DECI },
844     .expectExitResultUnit = VM_BEL
845     });
846    
847     runScript({
848     .code = R"NKSP_CODE(
849     on init
850     exit(-0.1mdB)
851     end on
852     )NKSP_CODE",
853     .expectRealExitResult = -0.1,
854     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
855     .expectExitResultUnit = VM_BEL
856     });
857    
858     runScript({
859     .code = R"NKSP_CODE(
860     on init
861     declare ~foo := -0.1mdB
862     exit(~foo)
863     end on
864     )NKSP_CODE",
865     .expectRealExitResult = -0.1,
866     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
867     .expectExitResultUnit = VM_BEL
868     });
869    
870     runScript({
871     .code = R"NKSP_CODE(
872     on init
873     declare ~foo := 0.0dB
874     ~foo := -0.1mdB
875     exit(~foo)
876     end on
877     )NKSP_CODE",
878     .expectRealExitResult = -0.1,
879     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
880     .expectExitResultUnit = VM_BEL
881     });
882    
883     runScript({
884     .code = R"NKSP_CODE(
885     on init
886     declare ~foo := 0.0dB
887     ~foo := -0.1Hz
888     exit(~foo)
889     end on
890     )NKSP_CODE",
891     .expectParseError = true // assigning different unit type to a variable is not allowed
892     });
893    
894     // 'final' ('!') operator tests ...
895    
896     runScript({
897     .code = R"NKSP_CODE(
898     on init
899     exit(!42)
900     end on
901     )NKSP_CODE",
902     .expectIntExitResult = 42,
903     .expectExitResultFinal = true
904     });
905    
906     runScript({
907     .code = R"NKSP_CODE(
908     on init
909     exit(42)
910     end on
911     )NKSP_CODE",
912     .expectIntExitResult = 42,
913     .expectExitResultFinal = false
914     });
915    
916     runScript({
917     .code = R"NKSP_CODE(
918     on init
919     declare $foo := !42
920     exit($foo)
921     end on
922     )NKSP_CODE",
923     .expectIntExitResult = 42,
924     .expectExitResultFinal = true
925     });
926    
927     runScript({
928     .code = R"NKSP_CODE(
929     on init
930     declare $foo := 42
931     exit($foo)
932     end on
933     )NKSP_CODE",
934     .expectIntExitResult = 42,
935     .expectExitResultFinal = false
936     });
937    
938     runScript({
939     .code = R"NKSP_CODE(
940     on init
941     declare ~foo := !3.14
942     exit(~foo)
943     end on
944     )NKSP_CODE",
945     .expectRealExitResult = 3.14,
946     .expectExitResultFinal = true
947     });
948    
949     runScript({
950     .code = R"NKSP_CODE(
951     on init
952     declare ~foo := 3.14
953     exit(~foo)
954     end on
955     )NKSP_CODE",
956     .expectRealExitResult = 3.14,
957     .expectExitResultFinal = false
958     });
959    
960     runScript({
961     .code = R"NKSP_CODE(
962     on init
963     declare ~foo := !3.14mdB
964     exit(~foo)
965     end on
966     )NKSP_CODE",
967     .expectRealExitResult = 3.14,
968     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
969     .expectExitResultUnit = VM_BEL,
970     .expectExitResultFinal = true
971     });
972    
973     runScript({
974     .code = R"NKSP_CODE(
975     on init
976     declare ~foo := !0.0mdB
977     ~foo := !3.14mdB
978     exit(~foo)
979     end on
980     )NKSP_CODE",
981     .expectRealExitResult = 3.14,
982     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
983     .expectExitResultUnit = VM_BEL,
984     .expectExitResultFinal = true
985     });
986    
987     runScript({
988     .code = R"NKSP_CODE(
989     on init
990     declare ~foo := !0.0mdB
991     ~foo := 3.14mdB
992     exit(~foo)
993     end on
994     )NKSP_CODE",
995     .expectParseError = true // assigning non-final to a final variable not allowed
996     });
997    
998     runScript({
999     .code = R"NKSP_CODE(
1000     on init
1001     declare ~foo := 0.0mdB
1002     ~foo := !3.14mdB
1003     exit(~foo)
1004     end on
1005     )NKSP_CODE",
1006     .expectParseError = true // assigning final to a non-final variable not allowed
1007     });
1008    
1009 schoenebeck 3551 #if !SILENT_TEST
1010     std::cout << std::endl;
1011     #endif
1012     }
1013    
1014     static void testStringConcatOperator() {
1015     #if !SILENT_TEST
1016     std::cout << "UNIT TEST: string concatenation (&) operator\n";
1017     #endif
1018    
1019 schoenebeck 3581 // strings only tests ...
1020    
1021 schoenebeck 3551 runScript({
1022     .code = R"NKSP_CODE(
1023     on init
1024     declare @s := "foo" & " bar"
1025     exit(@s)
1026     end on
1027     )NKSP_CODE",
1028     .expectStringExitResult = "foo bar"
1029     });
1030    
1031 schoenebeck 3581 // integer tests ...
1032    
1033 schoenebeck 3551 runScript({
1034     .code = R"NKSP_CODE(
1035     on init
1036     declare @s := "foo" & " bar" & " " & 123
1037     exit(@s)
1038     end on
1039     )NKSP_CODE",
1040     .expectStringExitResult = "foo bar 123"
1041     });
1042    
1043     runScript({
1044     .code = R"NKSP_CODE(
1045     on init
1046     declare $i := 123
1047     declare @s := "foo" & " bar" & " " & $i
1048     exit(@s)
1049     end on
1050     )NKSP_CODE",
1051     .expectStringExitResult = "foo bar 123"
1052     });
1053    
1054 schoenebeck 3581 // real number tests ...
1055    
1056     runScript({
1057     .code = R"NKSP_CODE(
1058     on init
1059     declare @s := "foo" & " bar" & " " & 1.23
1060     exit(@s)
1061     end on
1062     )NKSP_CODE",
1063     .expectStringExitResult = "foo bar 1.23"
1064     });
1065    
1066     runScript({
1067     .code = R"NKSP_CODE(
1068     on init
1069     declare ~r := 3.14
1070     declare @s := "foo" & " bar" & " " & ~r
1071     exit(@s)
1072     end on
1073     )NKSP_CODE",
1074     .expectStringExitResult = "foo bar 3.14"
1075     });
1076    
1077     // std unit tests ...
1078    
1079     runScript({
1080     .code = R"NKSP_CODE(
1081     on init
1082     declare $i := 500Hz
1083     declare @s := "foo" & " bar" & " " & $i
1084     exit(@s)
1085     end on
1086     )NKSP_CODE",
1087     .expectStringExitResult = "foo bar 500Hz"
1088     });
1089    
1090     runScript({
1091     .code = R"NKSP_CODE(
1092     on init
1093     declare ~r := 3.14s
1094     declare @s := "foo" & " bar" & " " & ~r
1095     exit(@s)
1096     end on
1097     )NKSP_CODE",
1098     .expectStringExitResult = "foo bar 3.14s"
1099     });
1100    
1101     runScript({
1102     .code = R"NKSP_CODE(
1103     on init
1104     declare ~r := -22.3mdB
1105     declare @s := "foo" & " bar" & " " & ~r
1106     exit(@s)
1107     end on
1108     )NKSP_CODE",
1109     .expectStringExitResult = "foo bar -22.3mdB"
1110     });
1111    
1112     runScript({
1113     .code = R"NKSP_CODE(
1114     on init
1115     declare $i := 20us
1116     declare @s := "foo" & " bar" & " " & $i
1117     exit(@s)
1118     end on
1119     )NKSP_CODE",
1120     .expectStringExitResult = "foo bar 20us"
1121     });
1122    
1123     runScript({
1124     .code = R"NKSP_CODE(
1125     on init
1126     declare $i := 20kHz
1127     declare @s := "foo" & " bar" & " " & $i
1128     exit(@s)
1129     end on
1130     )NKSP_CODE",
1131     .expectStringExitResult = "foo bar 20kHz"
1132     });
1133    
1134     runScript({
1135     .code = R"NKSP_CODE(
1136     on init
1137     declare $i := -6dB
1138     declare @s := "foo" & " bar" & " " & $i
1139     exit(@s)
1140     end on
1141     )NKSP_CODE",
1142     .expectStringExitResult = "foo bar -6dB"
1143     });
1144    
1145     runScript({
1146     .code = R"NKSP_CODE(
1147     on init
1148     declare $i := 1us * 1d
1149     declare @s := "foo" & " bar" & " " & $i
1150     exit(@s)
1151     end on
1152     )NKSP_CODE",
1153     .expectStringExitResult = "foo bar 1*10^-7s"
1154     });
1155    
1156     runScript({
1157     .code = R"NKSP_CODE(
1158     on init
1159     declare ~r := 12.4mc
1160     declare @s := "foo" & " bar" & " " & ~r
1161     exit(@s)
1162     end on
1163     )NKSP_CODE",
1164     .expectStringExitResult = "foo bar 12.4mc"
1165     });
1166    
1167 schoenebeck 3551 #if !SILENT_TEST
1168     std::cout << std::endl;
1169     #endif
1170     }
1171    
1172 schoenebeck 3575 static void testNegOperator() {
1173     #if !SILENT_TEST
1174     std::cout << "UNIT TEST: negate (-) operator\n";
1175     #endif
1176    
1177     // integer tests ...
1178    
1179     runScript({
1180     .code = R"NKSP_CODE(
1181     on init
1182     exit(-87)
1183     end on
1184     )NKSP_CODE",
1185     .expectIntExitResult = -87
1186     });
1187    
1188     runScript({
1189     .code = R"NKSP_CODE(
1190     on init
1191     declare $foo := -87
1192     exit(-$foo)
1193     end on
1194     )NKSP_CODE",
1195     .expectIntExitResult = 87
1196     });
1197    
1198     // real number tests ...
1199    
1200     runScript({
1201     .code = R"NKSP_CODE(
1202     on init
1203     exit(-99.3)
1204     end on
1205     )NKSP_CODE",
1206     .expectRealExitResult = -99.3
1207     });
1208    
1209     runScript({
1210     .code = R"NKSP_CODE(
1211     on init
1212     declare ~foo := -99.3
1213     exit(-~foo)
1214     end on
1215     )NKSP_CODE",
1216     .expectRealExitResult = 99.3
1217     });
1218    
1219 schoenebeck 3581 // std unit tests
1220    
1221     runScript({
1222     .code = R"NKSP_CODE(
1223     on init
1224     declare $foo := -87mdB
1225     exit(-$foo)
1226     end on
1227     )NKSP_CODE",
1228     .expectIntExitResult = 87,
1229     .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
1230     .expectExitResultUnit = VM_BEL
1231     });
1232    
1233     // 'final' ('!') operator tests ...
1234    
1235     runScript({
1236     .code = R"NKSP_CODE(
1237     on init
1238     declare $foo := !-87
1239     exit(-$foo)
1240     end on
1241     )NKSP_CODE",
1242     .expectIntExitResult = 87,
1243     .expectExitResultFinal = true
1244     });
1245    
1246     runScript({
1247     .code = R"NKSP_CODE(
1248     on init
1249     declare $foo := -87
1250     exit(-$foo)
1251     end on
1252     )NKSP_CODE",
1253     .expectIntExitResult = 87,
1254     .expectExitResultFinal = false
1255     });
1256    
1257 schoenebeck 3575 #if !SILENT_TEST
1258     std::cout << std::endl;
1259     #endif
1260     }
1261    
1262 schoenebeck 3551 static void testPlusOperator() {
1263     #if !SILENT_TEST
1264     std::cout << "UNIT TEST: plus (+) operator\n";
1265     #endif
1266    
1267 schoenebeck 3575 // integer tests ...
1268    
1269 schoenebeck 3551 runScript({
1270     .code = R"NKSP_CODE(
1271     on init
1272     exit(4 + 3)
1273     end on
1274     )NKSP_CODE",
1275     .expectIntExitResult = 7
1276     });
1277    
1278     runScript({
1279     .code = R"NKSP_CODE(
1280     on init
1281     exit(42 + 145)
1282     end on
1283     )NKSP_CODE",
1284     .expectIntExitResult = 187
1285     });
1286    
1287     runScript({
1288     .code = R"NKSP_CODE(
1289     on init
1290     exit(-4 + 2)
1291     end on
1292     )NKSP_CODE",
1293     .expectIntExitResult = -2
1294     });
1295    
1296 schoenebeck 3575 // real number tests ...
1297    
1298     runScript({
1299     .code = R"NKSP_CODE(
1300     on init
1301     exit(4.0 + 3.0)
1302     end on
1303     )NKSP_CODE",
1304     .expectRealExitResult = 7.0
1305     });
1306    
1307     runScript({
1308     .code = R"NKSP_CODE(
1309     on init
1310     exit(42.3 + 145.2)
1311     end on
1312     )NKSP_CODE",
1313     .expectRealExitResult = 187.5
1314     });
1315    
1316     runScript({
1317     .code = R"NKSP_CODE(
1318     on init
1319     exit(-4.0 + 2.2)
1320     end on
1321     )NKSP_CODE",
1322     .expectRealExitResult = -1.8
1323     });
1324    
1325 schoenebeck 3581 // std unit tests ...
1326    
1327     runScript({
1328     .code = R"NKSP_CODE(
1329     on init
1330     exit(42ms + 145ms)
1331     end on
1332     )NKSP_CODE",
1333     .expectIntExitResult = 187,
1334     .expectExitResultUnitPrefix = { VM_MILLI },
1335     .expectExitResultUnit = VM_SECOND
1336     });
1337    
1338     runScript({
1339     .code = R"NKSP_CODE(
1340     on init
1341     exit(1s + 145ms)
1342     end on
1343     )NKSP_CODE",
1344     .expectIntExitResult = 1145,
1345     .expectExitResultUnitPrefix = { VM_MILLI },
1346     .expectExitResultUnit = VM_SECOND
1347     });
1348    
1349     runScript({
1350     .code = R"NKSP_CODE(
1351     on init
1352     exit(42ms + 145)
1353     end on
1354     )NKSP_CODE",
1355     .expectParseError = true // units must match for + operator
1356     });
1357    
1358     runScript({
1359     .code = R"NKSP_CODE(
1360     on init
1361     exit(42 + 145ms)
1362     end on
1363     )NKSP_CODE",
1364     .expectParseError = true // units must match for + operator
1365     });
1366    
1367     runScript({
1368     .code = R"NKSP_CODE(
1369     on init
1370     exit(42Hz + 145s)
1371     end on
1372     )NKSP_CODE",
1373     .expectParseError = true // units must match for + operator
1374     });
1375    
1376     runScript({
1377     .code = R"NKSP_CODE(
1378     on init
1379     exit(42.1ms + 145.3ms)
1380     end on
1381     )NKSP_CODE",
1382     .expectRealExitResult = 187.4,
1383     .expectExitResultUnitPrefix = { VM_MILLI },
1384     .expectExitResultUnit = VM_SECOND
1385     });
1386    
1387     runScript({
1388     .code = R"NKSP_CODE(
1389     on init
1390     exit(1.1s + 145.0ms)
1391     end on
1392     )NKSP_CODE",
1393     .expectRealExitResult = 1245.0,
1394     .expectExitResultUnitPrefix = { VM_MILLI },
1395     .expectExitResultUnit = VM_SECOND
1396     });
1397    
1398     runScript({
1399     .code = R"NKSP_CODE(
1400     on init
1401     exit(42.1ms + 145.3)
1402     end on
1403     )NKSP_CODE",
1404     .expectParseError = true // units must match for + operator
1405     });
1406    
1407     runScript({
1408     .code = R"NKSP_CODE(
1409     on init
1410     exit(42.0 + 145.0ms)
1411     end on
1412     )NKSP_CODE",
1413     .expectParseError = true // units must match for + operator
1414     });
1415    
1416     runScript({
1417     .code = R"NKSP_CODE(
1418     on init
1419     exit(42.0Hz + 145.0s)
1420     end on
1421     )NKSP_CODE",
1422     .expectParseError = true // units must match for + operator
1423     });
1424    
1425     // 'final' ('!') operator tests ...
1426    
1427     runScript({
1428     .code = R"NKSP_CODE(
1429     on init
1430     exit(!4 + !3)
1431     end on
1432     )NKSP_CODE",
1433     .expectIntExitResult = 7,
1434     .expectExitResultFinal = true
1435     });
1436    
1437     runScript({
1438     .code = R"NKSP_CODE(
1439     on init
1440     exit(4 + 3)
1441     end on
1442     )NKSP_CODE",
1443     .expectIntExitResult = 7,
1444     .expectExitResultFinal = false
1445     });
1446    
1447     runScript({
1448     .code = R"NKSP_CODE(
1449     on init
1450     exit(!4.1 + !3.3)
1451     end on
1452     )NKSP_CODE",
1453     .expectRealExitResult = 7.4,
1454     .expectExitResultFinal = true
1455     });
1456    
1457     runScript({
1458     .code = R"NKSP_CODE(
1459     on init
1460     exit(4.1 + 3.3)
1461     end on
1462     )NKSP_CODE",
1463     .expectRealExitResult = 7.4,
1464     .expectExitResultFinal = false
1465     });
1466    
1467 schoenebeck 3551 #if !SILENT_TEST
1468     std::cout << std::endl;
1469     #endif
1470     }
1471    
1472     static void testMinusOperator() {
1473     #if !SILENT_TEST
1474     std::cout << "UNIT TEST: minus (-) operator\n";
1475     #endif
1476    
1477 schoenebeck 3575 // integer tests ...
1478    
1479 schoenebeck 3551 runScript({
1480     .code = R"NKSP_CODE(
1481     on init
1482     exit(4 - 3)
1483     end on
1484     )NKSP_CODE",
1485     .expectIntExitResult = 1
1486     });
1487    
1488     runScript({
1489     .code = R"NKSP_CODE(
1490     on init
1491     exit(139 - 74)
1492     end on
1493     )NKSP_CODE",
1494     .expectIntExitResult = 65
1495     });
1496    
1497     runScript({
1498     .code = R"NKSP_CODE(
1499     on init
1500     exit(3 - 9)
1501     end on
1502     )NKSP_CODE",
1503     .expectIntExitResult = -6
1504     });
1505    
1506     runScript({
1507     .code = R"NKSP_CODE(
1508     on init
1509     exit(-3 - 18)
1510     end on
1511     )NKSP_CODE",
1512     .expectIntExitResult = -21
1513     });
1514    
1515 schoenebeck 3575 // real number tests ...
1516    
1517     runScript({
1518     .code = R"NKSP_CODE(
1519     on init
1520     exit(4.0 - 0.2)
1521     end on
1522     )NKSP_CODE",
1523     .expectRealExitResult = 3.8
1524     });
1525    
1526     runScript({
1527     .code = R"NKSP_CODE(
1528     on init
1529     exit(3.1 - 9.65)
1530     end on
1531     )NKSP_CODE",
1532     .expectRealExitResult = -6.55
1533     });
1534    
1535     runScript({
1536     .code = R"NKSP_CODE(
1537     on init
1538     exit(-3.0 - 18.1)
1539     end on
1540     )NKSP_CODE",
1541     .expectRealExitResult = -21.1
1542     });
1543    
1544 schoenebeck 3581 // std unit tests ...
1545    
1546     runScript({
1547     .code = R"NKSP_CODE(
1548     on init
1549     exit(1000ms - 145ms)
1550     end on
1551     )NKSP_CODE",
1552     .expectIntExitResult = 855,
1553     .expectExitResultUnitPrefix = { VM_MILLI },
1554     .expectExitResultUnit = VM_SECOND
1555     });
1556    
1557     runScript({
1558     .code = R"NKSP_CODE(
1559     on init
1560     exit(1s - 145ms)
1561     end on
1562     )NKSP_CODE",
1563     .expectIntExitResult = 855,
1564     .expectExitResultUnitPrefix = { VM_MILLI },
1565     .expectExitResultUnit = VM_SECOND
1566     });
1567    
1568     runScript({
1569     .code = R"NKSP_CODE(
1570     on init
1571     exit(1s - 145)
1572     end on
1573     )NKSP_CODE",
1574     .expectParseError = true // units must match for - operator
1575     });
1576    
1577     runScript({
1578     .code = R"NKSP_CODE(
1579     on init
1580     exit(1 - 145s)
1581     end on
1582     )NKSP_CODE",
1583     .expectParseError = true // units must match for - operator
1584     });
1585    
1586     runScript({
1587     .code = R"NKSP_CODE(
1588     on init
1589     exit(1ms - 145mB)
1590     end on
1591     )NKSP_CODE",
1592     .expectParseError = true // units must match for - operator
1593     });
1594    
1595     runScript({
1596     .code = R"NKSP_CODE(
1597     on init
1598     exit(1.0ms - 0.1ms)
1599     end on
1600     )NKSP_CODE",
1601     .expectRealExitResult = 0.9,
1602     .expectExitResultUnitPrefix = { VM_MILLI },
1603     .expectExitResultUnit = VM_SECOND
1604     });
1605    
1606     runScript({
1607     .code = R"NKSP_CODE(
1608     on init
1609     exit(1.1s - 106.0ms)
1610     end on
1611     )NKSP_CODE",
1612     .expectRealExitResult = 994.0,
1613     .expectExitResultUnitPrefix = { VM_MILLI },
1614     .expectExitResultUnit = VM_SECOND
1615     });
1616    
1617     runScript({
1618     .code = R"NKSP_CODE(
1619     on init
1620     exit(1100.0ms - 0.106s)
1621     end on
1622     )NKSP_CODE",
1623     .expectRealExitResult = 994.0,
1624     .expectExitResultUnitPrefix = { VM_MILLI },
1625     .expectExitResultUnit = VM_SECOND
1626     });
1627    
1628     runScript({
1629     .code = R"NKSP_CODE(
1630     on init
1631     exit(1.0s - 145.0)
1632     end on
1633     )NKSP_CODE",
1634     .expectParseError = true // units must match for - operator
1635     });
1636    
1637     runScript({
1638     .code = R"NKSP_CODE(
1639     on init
1640     exit(1.0 - 145.0s)
1641     end on
1642     )NKSP_CODE",
1643     .expectParseError = true // units must match for - operator
1644     });
1645    
1646     runScript({
1647     .code = R"NKSP_CODE(
1648     on init
1649     exit(1.0ms - 145.0mB)
1650     end on
1651     )NKSP_CODE",
1652     .expectParseError = true // units must match for - operator
1653     });
1654    
1655     // 'final' ('!') operator tests ...
1656    
1657     runScript({
1658     .code = R"NKSP_CODE(
1659     on init
1660     exit(!5 - !3)
1661     end on
1662     )NKSP_CODE",
1663     .expectIntExitResult = 2,
1664     .expectExitResultFinal = true
1665     });
1666    
1667     runScript({
1668     .code = R"NKSP_CODE(
1669     on init
1670     exit(5 - 3)
1671     end on
1672     )NKSP_CODE",
1673     .expectIntExitResult = 2,
1674     .expectExitResultFinal = false
1675     });
1676    
1677     runScript({
1678     .code = R"NKSP_CODE(
1679     on init
1680     exit(!5.9 - !3.3)
1681     end on
1682     )NKSP_CODE",
1683     .expectRealExitResult = 2.6,
1684     .expectExitResultFinal = true
1685     });
1686    
1687     runScript({
1688     .code = R"NKSP_CODE(
1689     on init
1690     exit(5.9 - 3.3)
1691     end on
1692     )NKSP_CODE",
1693     .expectRealExitResult = 2.6,
1694     .expectExitResultFinal = false
1695     });
1696    
1697 schoenebeck 3551 #if !SILENT_TEST
1698     std::cout << std::endl;
1699     #endif
1700     }
1701    
1702     static void testModuloOperator() {
1703     #if !SILENT_TEST
1704     std::cout << "UNIT TEST: modulo (mod) operator\n";
1705     #endif
1706    
1707 schoenebeck 3575 // integer tests ...
1708    
1709 schoenebeck 3551 runScript({
1710     .code = R"NKSP_CODE(
1711     on init
1712     exit(10 mod 8)
1713     end on
1714     )NKSP_CODE",
1715     .expectIntExitResult = 2
1716     });
1717    
1718 schoenebeck 3575 runScript({
1719     .code = R"NKSP_CODE(
1720     on init
1721     declare $a := 10
1722     declare $b := 8
1723     exit($a mod $b)
1724     end on
1725     )NKSP_CODE",
1726     .expectIntExitResult = 2
1727     });
1728    
1729     // real number tests ...
1730     // (mod operator prohibits real numbers ATM)
1731    
1732     runScript({
1733     .code = R"NKSP_CODE(
1734     on init
1735     exit(10.0 mod 8.0)
1736     end on
1737     )NKSP_CODE",
1738     .expectParseError = true // mod operator prohibits real numbers ATM
1739     });
1740    
1741     runScript({
1742     .code = R"NKSP_CODE(
1743     on init
1744     exit(10 mod 8.0)
1745     end on
1746     )NKSP_CODE",
1747     .expectParseError = true // mod operator prohibits real numbers ATM
1748     });
1749    
1750     runScript({
1751     .code = R"NKSP_CODE(
1752     on init
1753     exit(10.0 mod 8)
1754     end on
1755     )NKSP_CODE",
1756     .expectParseError = true // mod operator prohibits real numbers ATM
1757     });
1758    
1759     runScript({
1760     .code = R"NKSP_CODE(
1761     on init
1762     declare ~a := 10.0
1763     declare ~b := 8.0
1764     exit(~a mod ~b)
1765     end on
1766     )NKSP_CODE",
1767     .expectParseError = true // mod operator prohibits real numbers ATM
1768     });
1769    
1770 schoenebeck 3581 // std unit tests ...
1771    
1772     runScript({
1773     .code = R"NKSP_CODE(
1774     on init
1775     exit(10s mod 8)
1776     end on
1777     )NKSP_CODE",
1778     .expectParseError = true // mod operator prohibits std units ATM
1779     });
1780    
1781     runScript({
1782     .code = R"NKSP_CODE(
1783     on init
1784     exit(10 mod 8s)
1785     end on
1786     )NKSP_CODE",
1787     .expectParseError = true // mod operator prohibits std units ATM
1788     });
1789    
1790     runScript({
1791     .code = R"NKSP_CODE(
1792     on init
1793     exit(10s mod 8s)
1794     end on
1795     )NKSP_CODE",
1796     .expectParseError = true // mod operator prohibits std units ATM
1797     });
1798    
1799     // 'final' ('!') operator tests ...
1800    
1801     runScript({
1802     .code = R"NKSP_CODE(
1803     on init
1804     exit(!10 mod !8)
1805     end on
1806     )NKSP_CODE",
1807     .expectIntExitResult = 2,
1808     .expectExitResultFinal = true
1809     });
1810    
1811     runScript({
1812     .code = R"NKSP_CODE(
1813     on init
1814     exit(10 mod 8)
1815     end on
1816     )NKSP_CODE",
1817     .expectIntExitResult = 2,
1818     .expectExitResultFinal = false
1819     });
1820    
1821 schoenebeck 3551 #if !SILENT_TEST
1822     std::cout << std::endl;
1823     #endif
1824     }
1825    
1826     static void testMultiplyOperator() {
1827     #if !SILENT_TEST
1828     std::cout << "UNIT TEST: multiply (*) operator\n";
1829     #endif
1830    
1831 schoenebeck 3575 // integer tests ...
1832    
1833 schoenebeck 3551 runScript({
1834     .code = R"NKSP_CODE(
1835     on init
1836     exit(10 * 8)
1837     end on
1838     )NKSP_CODE",
1839     .expectIntExitResult = 80
1840     });
1841    
1842     runScript({
1843     .code = R"NKSP_CODE(
1844     on init
1845     exit(-3 * -4)
1846     end on
1847     )NKSP_CODE",
1848     .expectIntExitResult = 12
1849     });
1850    
1851     runScript({
1852     .code = R"NKSP_CODE(
1853     on init
1854     exit(-52 * 63)
1855     end on
1856     )NKSP_CODE",
1857     .expectIntExitResult = -3276
1858     });
1859    
1860     runScript({
1861     .code = R"NKSP_CODE(
1862     on init
1863     exit(123 * -59)
1864     end on
1865     )NKSP_CODE",
1866     .expectIntExitResult = -7257
1867     });
1868    
1869 schoenebeck 3575 // real number tests ...
1870    
1871     runScript({
1872     .code = R"NKSP_CODE(
1873     on init
1874     exit(10.2 * 8.4)
1875     end on
1876     )NKSP_CODE",
1877     .expectRealExitResult = 85.68
1878     });
1879    
1880     runScript({
1881     .code = R"NKSP_CODE(
1882     on init
1883     exit(10.0 * -3.33)
1884     end on
1885     )NKSP_CODE",
1886     .expectRealExitResult = -33.3
1887     });
1888    
1889     runScript({
1890     .code = R"NKSP_CODE(
1891     on init
1892     exit(-3.33 * 10.0)
1893     end on
1894     )NKSP_CODE",
1895     .expectRealExitResult = -33.3
1896     });
1897    
1898     runScript({
1899     .code = R"NKSP_CODE(
1900     on init
1901     exit(-3.33 * -10.0)
1902     end on
1903     )NKSP_CODE",
1904     .expectRealExitResult = 33.3
1905     });
1906    
1907     // mixed type tests ...
1908     // (mixed int * real forbidden ATM)
1909    
1910     runScript({
1911     .code = R"NKSP_CODE(
1912     on init
1913     exit(2 * 3.0)
1914     end on
1915     )NKSP_CODE",
1916     .expectParseError = true // mixed int * real forbidden ATM
1917     });
1918    
1919     runScript({
1920     .code = R"NKSP_CODE(
1921     on init
1922     exit(2.0 * 3)
1923     end on
1924     )NKSP_CODE",
1925     .expectParseError = true // mixed int * real forbidden ATM
1926     });
1927    
1928 schoenebeck 3581 // std unit tests ...
1929    
1930     runScript({
1931     .code = R"NKSP_CODE(
1932     on init
1933     exit(10ms * 8)
1934     end on
1935     )NKSP_CODE",
1936     .expectIntExitResult = 80,
1937     .expectExitResultUnitPrefix = { VM_MILLI },
1938     .expectExitResultUnit = VM_SECOND
1939     });
1940    
1941     runScript({
1942     .code = R"NKSP_CODE(
1943     on init
1944     exit(10 * 8ms)
1945     end on
1946     )NKSP_CODE",
1947     .expectIntExitResult = 80,
1948     .expectExitResultUnitPrefix = { VM_MILLI },
1949     .expectExitResultUnit = VM_SECOND
1950     });
1951    
1952     runScript({
1953     .code = R"NKSP_CODE(
1954     on init
1955     exit(10s * 8s)
1956     end on
1957     )NKSP_CODE",
1958     .expectParseError = true // units on both sides not allowed for * ATM
1959     });
1960    
1961     runScript({
1962     .code = R"NKSP_CODE(
1963     on init
1964     exit(10cs * 8d)
1965     end on
1966     )NKSP_CODE",
1967     .expectIntExitResult = 80,
1968     .expectExitResultUnitPrefix = { VM_MILLI },
1969     .expectExitResultUnit = VM_SECOND
1970     });
1971    
1972     runScript({
1973     .code = R"NKSP_CODE(
1974     on init
1975     exit(10m * 8ms)
1976     end on
1977     )NKSP_CODE",
1978     .expectIntExitResult = 80,
1979     .expectExitResultUnitPrefix = { VM_MICRO },
1980     .expectExitResultUnit = VM_SECOND
1981     });
1982    
1983     runScript({
1984     .code = R"NKSP_CODE(
1985     on init
1986     exit(10ms * 8k)
1987     end on
1988     )NKSP_CODE",
1989     .expectIntExitResult = 80,
1990     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
1991     .expectExitResultUnit = VM_SECOND
1992     });
1993    
1994     runScript({
1995     .code = R"NKSP_CODE(
1996     on init
1997     exit(10.1ms * 8.0)
1998     end on
1999     )NKSP_CODE",
2000     .expectRealExitResult = 80.8,
2001     .expectExitResultUnitPrefix = { VM_MILLI },
2002     .expectExitResultUnit = VM_SECOND
2003     });
2004    
2005     runScript({
2006     .code = R"NKSP_CODE(
2007     on init
2008     exit(10.1 * 8.0ms)
2009     end on
2010     )NKSP_CODE",
2011     .expectRealExitResult = 80.8,
2012     .expectExitResultUnitPrefix = { VM_MILLI },
2013     .expectExitResultUnit = VM_SECOND
2014     });
2015    
2016     runScript({
2017     .code = R"NKSP_CODE(
2018     on init
2019     exit(10.0s * 8.0s)
2020     end on
2021     )NKSP_CODE",
2022     .expectParseError = true // units on both sides not allowed for * ATM
2023     });
2024    
2025     runScript({
2026     .code = R"NKSP_CODE(
2027     on init
2028     exit(10.1ds * 8.0c)
2029     end on
2030     )NKSP_CODE",
2031     .expectRealExitResult = 80.8,
2032     .expectExitResultUnitPrefix = { VM_MILLI },
2033     .expectExitResultUnit = VM_SECOND
2034     });
2035    
2036     runScript({
2037     .code = R"NKSP_CODE(
2038     on init
2039     exit(10.1m * 8.0ms)
2040     end on
2041     )NKSP_CODE",
2042     .expectRealExitResult = 80.8,
2043     .expectExitResultUnitPrefix = { VM_MICRO },
2044     .expectExitResultUnit = VM_SECOND
2045     });
2046    
2047     runScript({
2048     .code = R"NKSP_CODE(
2049     on init
2050     exit(10.1m * 8.0ks)
2051     end on
2052     )NKSP_CODE",
2053     .expectRealExitResult = 80.8,
2054     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2055     .expectExitResultUnit = VM_SECOND
2056     });
2057    
2058     // 'final' ('!') operator tests ...
2059    
2060     runScript({
2061     .code = R"NKSP_CODE(
2062     on init
2063     exit(!10 * !8)
2064     end on
2065     )NKSP_CODE",
2066     .expectIntExitResult = 80,
2067     .expectExitResultFinal = true
2068     });
2069    
2070     runScript({
2071     .code = R"NKSP_CODE(
2072     on init
2073     exit(10 * 8)
2074     end on
2075     )NKSP_CODE",
2076     .expectIntExitResult = 80,
2077     .expectExitResultFinal = false
2078     });
2079    
2080     runScript({
2081     .code = R"NKSP_CODE(
2082     on init
2083     exit(!10 * 8)
2084     end on
2085     )NKSP_CODE",
2086     .expectIntExitResult = 80,
2087     .expectExitResultFinal = true,
2088     .expectParseWarning = true // since final only on one side, result will be final though
2089     });
2090    
2091     runScript({
2092     .code = R"NKSP_CODE(
2093     on init
2094     exit(10 * !8)
2095     end on
2096     )NKSP_CODE",
2097     .expectIntExitResult = 80,
2098     .expectExitResultFinal = true,
2099     .expectParseWarning = true // since final only on one side, result will be final though
2100     });
2101    
2102     runScript({
2103     .code = R"NKSP_CODE(
2104     on init
2105     exit(!10.1 * !8.0)
2106     end on
2107     )NKSP_CODE",
2108     .expectRealExitResult = 80.8,
2109     .expectExitResultFinal = true
2110     });
2111    
2112     runScript({
2113     .code = R"NKSP_CODE(
2114     on init
2115     exit(10.1 * 8.0)
2116     end on
2117     )NKSP_CODE",
2118     .expectRealExitResult = 80.8,
2119     .expectExitResultFinal = false
2120     });
2121    
2122     runScript({
2123     .code = R"NKSP_CODE(
2124     on init
2125     exit(!10.1 * 8.0)
2126     end on
2127     )NKSP_CODE",
2128     .expectRealExitResult = 80.8,
2129     .expectExitResultFinal = true,
2130     .expectParseWarning = true // since final only on one side, result will be final though
2131     });
2132    
2133     runScript({
2134     .code = R"NKSP_CODE(
2135     on init
2136     exit(10.1 * !8.0)
2137     end on
2138     )NKSP_CODE",
2139     .expectRealExitResult = 80.8,
2140     .expectExitResultFinal = true,
2141     .expectParseWarning = true // since final only on one side, result will be final though
2142     });
2143    
2144 schoenebeck 3551 #if !SILENT_TEST
2145     std::cout << std::endl;
2146     #endif
2147     }
2148    
2149     static void testDivideOperator() {
2150     #if !SILENT_TEST
2151     std::cout << "UNIT TEST: divide (/) operator\n";
2152     #endif
2153    
2154 schoenebeck 3575 // integer tests ...
2155    
2156 schoenebeck 3551 runScript({
2157     .code = R"NKSP_CODE(
2158     on init
2159     exit(9 / 3)
2160     end on
2161     )NKSP_CODE",
2162     .expectIntExitResult = 3
2163     });
2164    
2165     runScript({
2166     .code = R"NKSP_CODE(
2167     on init
2168     exit(-27 / 3)
2169     end on
2170     )NKSP_CODE",
2171     .expectIntExitResult = -9
2172     });
2173    
2174     runScript({
2175     .code = R"NKSP_CODE(
2176     on init
2177     exit(35 / -5)
2178     end on
2179     )NKSP_CODE",
2180     .expectIntExitResult = -7
2181     });
2182    
2183     runScript({
2184     .code = R"NKSP_CODE(
2185     on init
2186     exit(39 / -5)
2187     end on
2188     )NKSP_CODE",
2189     .expectIntExitResult = -7
2190     });
2191    
2192 schoenebeck 3575 // real number tests ...
2193    
2194     runScript({
2195     .code = R"NKSP_CODE(
2196     on init
2197     exit(9.0 / 10.0)
2198     end on
2199     )NKSP_CODE",
2200     .expectRealExitResult = 0.9
2201     });
2202    
2203     runScript({
2204     .code = R"NKSP_CODE(
2205     on init
2206     exit(-9.0 / 10.0)
2207     end on
2208     )NKSP_CODE",
2209     .expectRealExitResult = -0.9
2210     });
2211    
2212     runScript({
2213     .code = R"NKSP_CODE(
2214     on init
2215     exit(9.0 / -10.0)
2216     end on
2217     )NKSP_CODE",
2218     .expectRealExitResult = -0.9
2219     });
2220    
2221     runScript({
2222     .code = R"NKSP_CODE(
2223     on init
2224     exit(-9.0 / -10.0)
2225     end on
2226     )NKSP_CODE",
2227     .expectRealExitResult = 0.9
2228     });
2229    
2230     // mixed type tests ...
2231     // (mixed int / real forbidden ATM)
2232    
2233     runScript({
2234     .code = R"NKSP_CODE(
2235     on init
2236     exit(9 / 10.0)
2237     end on
2238     )NKSP_CODE",
2239     .expectParseError = true // mixed int / real forbidden ATM
2240     });
2241    
2242     runScript({
2243     .code = R"NKSP_CODE(
2244     on init
2245     exit(9.0 / 10)
2246     end on
2247     )NKSP_CODE",
2248     .expectParseError = true // mixed int / real forbidden ATM
2249     });
2250    
2251 schoenebeck 3581 // std unit tests ...
2252    
2253     runScript({
2254     .code = R"NKSP_CODE(
2255     on init
2256     exit(-27us / 3)
2257     end on
2258     )NKSP_CODE",
2259     .expectIntExitResult = -9,
2260     .expectExitResultUnitPrefix = { VM_MICRO },
2261     .expectExitResultUnit = VM_SECOND
2262     });
2263    
2264     runScript({
2265     .code = R"NKSP_CODE(
2266     on init
2267     exit(-27mdB / 3mdB)
2268     end on
2269     )NKSP_CODE",
2270     .expectIntExitResult = -9,
2271     .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2272     .expectExitResultUnit = VM_NO_UNIT
2273     });
2274    
2275     runScript({
2276     .code = R"NKSP_CODE(
2277     on init
2278     exit(-27s / 3m)
2279     end on
2280     )NKSP_CODE",
2281     .expectIntExitResult = -9,
2282     .expectExitResultUnitPrefix = { VM_KILO },
2283     .expectExitResultUnit = VM_SECOND
2284     });
2285    
2286     runScript({
2287     .code = R"NKSP_CODE(
2288     on init
2289     exit(-27us / 3m)
2290     end on
2291     )NKSP_CODE",
2292     .expectIntExitResult = -9,
2293     .expectExitResultUnitPrefix = { VM_MILLI },
2294     .expectExitResultUnit = VM_SECOND
2295     });
2296    
2297     runScript({
2298     .code = R"NKSP_CODE(
2299     on init
2300     exit(-27 / 3s)
2301     end on
2302     )NKSP_CODE",
2303     .expectParseError = true // illegal unit type arrangement for divisions
2304     });
2305    
2306     runScript({
2307     .code = R"NKSP_CODE(
2308     on init
2309     exit(-27s / 3Hz)
2310     end on
2311     )NKSP_CODE",
2312     .expectParseError = true // unit types are not matching
2313     });
2314    
2315     // 'final' ('!') operator tests ...
2316    
2317     runScript({
2318     .code = R"NKSP_CODE(
2319     on init
2320     exit(!-27 / !3)
2321     end on
2322     )NKSP_CODE",
2323     .expectIntExitResult = -9,
2324     .expectExitResultFinal = true
2325     });
2326    
2327     runScript({
2328     .code = R"NKSP_CODE(
2329     on init
2330     exit(-27 / 3)
2331     end on
2332     )NKSP_CODE",
2333     .expectIntExitResult = -9,
2334     .expectExitResultFinal = false
2335     });
2336    
2337     runScript({
2338     .code = R"NKSP_CODE(
2339     on init
2340     exit(!-27 / 3)
2341     end on
2342     )NKSP_CODE",
2343     .expectIntExitResult = -9,
2344     .expectExitResultFinal = true,
2345     .expectParseWarning = true // final only on one side, result will be final though
2346     });
2347    
2348     runScript({
2349     .code = R"NKSP_CODE(
2350     on init
2351     exit(-27 / !3)
2352     end on
2353     )NKSP_CODE",
2354     .expectIntExitResult = -9,
2355     .expectExitResultFinal = true,
2356     .expectParseWarning = true // final only on one side, result will be final though
2357     });
2358    
2359 schoenebeck 3551 #if !SILENT_TEST
2360     std::cout << std::endl;
2361     #endif
2362     }
2363    
2364     static void testSmallerThanOperator() {
2365     #if !SILENT_TEST
2366     std::cout << "UNIT TEST: smaller than (<) operator\n";
2367     #endif
2368    
2369 schoenebeck 3575 // integer tests ...
2370    
2371 schoenebeck 3551 runScript({
2372     .code = R"NKSP_CODE(
2373     on init
2374     exit(3 < 4)
2375     end on
2376     )NKSP_CODE",
2377     .expectBoolExitResult = true
2378     });
2379    
2380     runScript({
2381     .code = R"NKSP_CODE(
2382     on init
2383     exit(4 < 3)
2384     end on
2385     )NKSP_CODE",
2386     .expectBoolExitResult = false
2387     });
2388    
2389     runScript({
2390     .code = R"NKSP_CODE(
2391     on init
2392     exit(-4 < 3)
2393     end on
2394     )NKSP_CODE",
2395     .expectBoolExitResult = true
2396     });
2397    
2398     runScript({
2399     .code = R"NKSP_CODE(
2400     on init
2401     exit(3 < -4)
2402     end on
2403     )NKSP_CODE",
2404     .expectBoolExitResult = false
2405     });
2406    
2407     runScript({
2408     .code = R"NKSP_CODE(
2409     on init
2410     exit(123 < -45)
2411     end on
2412     )NKSP_CODE",
2413     .expectBoolExitResult = false
2414     });
2415    
2416     runScript({
2417     .code = R"NKSP_CODE(
2418     on init
2419     exit(-45 < 123)
2420     end on
2421     )NKSP_CODE",
2422     .expectBoolExitResult = true
2423     });
2424    
2425 schoenebeck 3575 // real number tests ...
2426    
2427     runScript({
2428     .code = R"NKSP_CODE(
2429     on init
2430     exit(3.0 < 4.0)
2431     end on
2432     )NKSP_CODE",
2433     .expectBoolExitResult = true
2434     });
2435    
2436     runScript({
2437     .code = R"NKSP_CODE(
2438     on init
2439     exit(4.0 < 3.0)
2440     end on
2441     )NKSP_CODE",
2442     .expectBoolExitResult = false
2443     });
2444    
2445     runScript({
2446     .code = R"NKSP_CODE(
2447     on init
2448     exit(1.2 < 1.23)
2449     end on
2450     )NKSP_CODE",
2451     .expectBoolExitResult = true
2452     });
2453    
2454     runScript({
2455     .code = R"NKSP_CODE(
2456     on init
2457     exit(1.23 < 1.2)
2458     end on
2459     )NKSP_CODE",
2460     .expectBoolExitResult = false
2461     });
2462    
2463     runScript({
2464     .code = R"NKSP_CODE(
2465     on init
2466     exit(-4.0 < 3.0)
2467     end on
2468     )NKSP_CODE",
2469     .expectBoolExitResult = true
2470     });
2471    
2472     runScript({
2473     .code = R"NKSP_CODE(
2474     on init
2475     exit(3.0 < -4.0)
2476     end on
2477     )NKSP_CODE",
2478     .expectBoolExitResult = false
2479     });
2480    
2481     runScript({
2482     .code = R"NKSP_CODE(
2483     on init
2484     exit(123.0 < -45.0)
2485     end on
2486     )NKSP_CODE",
2487     .expectBoolExitResult = false
2488     });
2489    
2490     runScript({
2491     .code = R"NKSP_CODE(
2492     on init
2493     exit(-45.0 < 123.0)
2494     end on
2495     )NKSP_CODE",
2496     .expectBoolExitResult = true
2497     });
2498    
2499     // mixed type tests ...
2500    
2501     runScript({
2502     .code = R"NKSP_CODE(
2503     on init
2504     exit(9 < 9.1)
2505     end on
2506     )NKSP_CODE",
2507     .expectBoolExitResult = true
2508     });
2509    
2510     runScript({
2511     .code = R"NKSP_CODE(
2512     on init
2513     exit(9.1 < 9)
2514     end on
2515     )NKSP_CODE",
2516     .expectBoolExitResult = false
2517     });
2518    
2519 schoenebeck 3581 // std unit tests ...
2520    
2521     runScript({
2522     .code = R"NKSP_CODE(
2523     on init
2524     exit(13ms < 14ms)
2525     end on
2526     )NKSP_CODE",
2527     .expectBoolExitResult = true
2528     });
2529    
2530     runScript({
2531     .code = R"NKSP_CODE(
2532     on init
2533     exit(14ms < 13ms)
2534     end on
2535     )NKSP_CODE",
2536     .expectBoolExitResult = false
2537     });
2538    
2539     runScript({
2540     .code = R"NKSP_CODE(
2541     on init
2542     exit(1s < 990ms)
2543     end on
2544     )NKSP_CODE",
2545     .expectBoolExitResult = false
2546     });
2547    
2548     runScript({
2549     .code = R"NKSP_CODE(
2550     on init
2551     exit(990ms < 1s)
2552     end on
2553     )NKSP_CODE",
2554     .expectBoolExitResult = true
2555     });
2556    
2557     runScript({
2558     .code = R"NKSP_CODE(
2559     on init
2560     exit(1000ms < 1s)
2561     end on
2562     )NKSP_CODE",
2563     .expectBoolExitResult = false
2564     });
2565    
2566     runScript({
2567     .code = R"NKSP_CODE(
2568     on init
2569     exit(1s < 1000ms)
2570     end on
2571     )NKSP_CODE",
2572     .expectBoolExitResult = false
2573     });
2574    
2575     runScript({
2576     .code = R"NKSP_CODE(
2577     on init
2578     exit(1s < 1)
2579     end on
2580     )NKSP_CODE",
2581     .expectParseError = true // units on both sides must match
2582     });
2583    
2584     runScript({
2585     .code = R"NKSP_CODE(
2586     on init
2587     exit(1 < 1s)
2588     end on
2589     )NKSP_CODE",
2590     .expectParseError = true // units on both sides must match
2591     });
2592    
2593     runScript({
2594     .code = R"NKSP_CODE(
2595     on init
2596     exit(1Hz < 1B)
2597     end on
2598     )NKSP_CODE",
2599     .expectParseError = true // units on both sides must match
2600     });
2601    
2602     runScript({
2603     .code = R"NKSP_CODE(
2604     on init
2605     exit(13.0ms < 13.1ms)
2606     end on
2607     )NKSP_CODE",
2608     .expectBoolExitResult = true
2609     });
2610    
2611     runScript({
2612     .code = R"NKSP_CODE(
2613     on init
2614     exit(13.1ms < 13.0ms)
2615     end on
2616     )NKSP_CODE",
2617     .expectBoolExitResult = false
2618     });
2619    
2620     runScript({
2621     .code = R"NKSP_CODE(
2622     on init
2623     exit(0.9s < 600.0ms)
2624     end on
2625     )NKSP_CODE",
2626     .expectBoolExitResult = false
2627     });
2628    
2629     runScript({
2630     .code = R"NKSP_CODE(
2631     on init
2632     exit(600.0ms < 0.9s)
2633     end on
2634     )NKSP_CODE",
2635     .expectBoolExitResult = true
2636     });
2637    
2638     runScript({
2639     .code = R"NKSP_CODE(
2640     on init
2641     exit(5.1kHz < 5100.0Hz)
2642     end on
2643     )NKSP_CODE",
2644     .expectBoolExitResult = false
2645     });
2646    
2647     runScript({
2648     .code = R"NKSP_CODE(
2649     on init
2650     exit(5100.0Hz < 5.1kHz)
2651     end on
2652     )NKSP_CODE",
2653     .expectBoolExitResult = false
2654     });
2655    
2656     runScript({
2657     .code = R"NKSP_CODE(
2658     on init
2659     exit(1.0Hz < 1.1)
2660     end on
2661     )NKSP_CODE",
2662     .expectParseError = true // units on both sides must match
2663     });
2664    
2665     runScript({
2666     .code = R"NKSP_CODE(
2667     on init
2668     exit(1.2 < 1.34mdB)
2669     end on
2670     )NKSP_CODE",
2671     .expectParseError = true // units on both sides must match
2672     });
2673    
2674     runScript({
2675     .code = R"NKSP_CODE(
2676     on init
2677     exit(9.23us < 3.14kHz)
2678     end on
2679     )NKSP_CODE",
2680     .expectParseError = true // units on both sides must match
2681     });
2682    
2683     // 'final' ('!') operator tests ...
2684     // (should always yield in false for relation operators)
2685    
2686     runScript({
2687     .code = R"NKSP_CODE(
2688     on init
2689     exit(!-4 < !3)
2690     end on
2691     )NKSP_CODE",
2692     .expectBoolExitResult = true,
2693     .expectExitResultFinal = false
2694     });
2695    
2696     runScript({
2697     .code = R"NKSP_CODE(
2698     on init
2699     exit(-4 < 3)
2700     end on
2701     )NKSP_CODE",
2702     .expectBoolExitResult = true,
2703     .expectExitResultFinal = false
2704     });
2705    
2706 schoenebeck 3551 #if !SILENT_TEST
2707     std::cout << std::endl;
2708     #endif
2709     }
2710    
2711     static void testGreaterThanOperator() {
2712     #if !SILENT_TEST
2713     std::cout << "UNIT TEST: greater than (>) operator\n";
2714     #endif
2715    
2716 schoenebeck 3575 // integer tests ...
2717    
2718 schoenebeck 3551 runScript({
2719     .code = R"NKSP_CODE(
2720     on init
2721     exit(3 > 4)
2722     end on
2723     )NKSP_CODE",
2724     .expectBoolExitResult = false
2725     });
2726    
2727     runScript({
2728     .code = R"NKSP_CODE(
2729     on init
2730     exit(4 > 3)
2731     end on
2732     )NKSP_CODE",
2733     .expectBoolExitResult = true
2734     });
2735    
2736     runScript({
2737     .code = R"NKSP_CODE(
2738     on init
2739     exit(-4 > 3)
2740     end on
2741     )NKSP_CODE",
2742     .expectBoolExitResult = false
2743     });
2744    
2745     runScript({
2746     .code = R"NKSP_CODE(
2747     on init
2748     exit(3 > -4)
2749     end on
2750     )NKSP_CODE",
2751     .expectBoolExitResult = true
2752     });
2753    
2754     runScript({
2755     .code = R"NKSP_CODE(
2756     on init
2757     exit(123 > -45)
2758     end on
2759     )NKSP_CODE",
2760     .expectBoolExitResult = true
2761     });
2762    
2763     runScript({
2764     .code = R"NKSP_CODE(
2765     on init
2766     exit(-45 > 123)
2767     end on
2768     )NKSP_CODE",
2769     .expectBoolExitResult = false
2770     });
2771    
2772 schoenebeck 3575 // real number tests ...
2773    
2774     runScript({
2775     .code = R"NKSP_CODE(
2776     on init
2777     exit(3.0 > 4.0)
2778     end on
2779     )NKSP_CODE",
2780     .expectBoolExitResult = false
2781     });
2782    
2783     runScript({
2784     .code = R"NKSP_CODE(
2785     on init
2786     exit(4.0 > 3.0)
2787     end on
2788     )NKSP_CODE",
2789     .expectBoolExitResult = true
2790     });
2791    
2792     runScript({
2793     .code = R"NKSP_CODE(
2794     on init
2795     exit(1.2 > 1.23)
2796     end on
2797     )NKSP_CODE",
2798     .expectBoolExitResult = false
2799     });
2800    
2801     runScript({
2802     .code = R"NKSP_CODE(
2803     on init
2804     exit(1.23 > 1.2)
2805     end on
2806     )NKSP_CODE",
2807     .expectBoolExitResult = true
2808     });
2809    
2810     runScript({
2811     .code = R"NKSP_CODE(
2812     on init
2813     exit(-4.0 > 3.0)
2814     end on
2815     )NKSP_CODE",
2816     .expectBoolExitResult = false
2817     });
2818    
2819     runScript({
2820     .code = R"NKSP_CODE(
2821     on init
2822     exit(3.0 > -4.0)
2823     end on
2824     )NKSP_CODE",
2825     .expectBoolExitResult = true
2826     });
2827    
2828     runScript({
2829     .code = R"NKSP_CODE(
2830     on init
2831     exit(123.0 > -45.0)
2832     end on
2833     )NKSP_CODE",
2834     .expectBoolExitResult = true
2835     });
2836    
2837     runScript({
2838     .code = R"NKSP_CODE(
2839     on init
2840     exit(-45.0 > 123.0)
2841     end on
2842     )NKSP_CODE",
2843     .expectBoolExitResult = false
2844     });
2845    
2846     // mixed type tests ...
2847    
2848     runScript({
2849     .code = R"NKSP_CODE(
2850     on init
2851     exit(9 > 9.1)
2852     end on
2853     )NKSP_CODE",
2854     .expectBoolExitResult = false
2855     });
2856    
2857     runScript({
2858     .code = R"NKSP_CODE(
2859     on init
2860     exit(9.1 > 9)
2861     end on
2862     )NKSP_CODE",
2863     .expectBoolExitResult = true
2864     });
2865    
2866 schoenebeck 3581 // std unit tests ...
2867    
2868     runScript({
2869     .code = R"NKSP_CODE(
2870     on init
2871     exit(13ms > 14ms)
2872     end on
2873     )NKSP_CODE",
2874     .expectBoolExitResult = false
2875     });
2876    
2877     runScript({
2878     .code = R"NKSP_CODE(
2879     on init
2880     exit(14ms > 13ms)
2881     end on
2882     )NKSP_CODE",
2883     .expectBoolExitResult = true
2884     });
2885    
2886     runScript({
2887     .code = R"NKSP_CODE(
2888     on init
2889     exit(1s > 990ms)
2890     end on
2891     )NKSP_CODE",
2892     .expectBoolExitResult = true
2893     });
2894    
2895     runScript({
2896     .code = R"NKSP_CODE(
2897     on init
2898     exit(990ms > 1s)
2899     end on
2900     )NKSP_CODE",
2901     .expectBoolExitResult = false
2902     });
2903    
2904     runScript({
2905     .code = R"NKSP_CODE(
2906     on init
2907     exit(1000ms > 1s)
2908     end on
2909     )NKSP_CODE",
2910     .expectBoolExitResult = false
2911     });
2912    
2913     runScript({
2914     .code = R"NKSP_CODE(
2915     on init
2916     exit(1s > 1000ms)
2917     end on
2918     )NKSP_CODE",
2919     .expectBoolExitResult = false
2920     });
2921    
2922     runScript({
2923     .code = R"NKSP_CODE(
2924     on init
2925     exit(1s > 1)
2926     end on
2927     )NKSP_CODE",
2928     .expectParseError = true // units on both sides must match
2929     });
2930    
2931     runScript({
2932     .code = R"NKSP_CODE(
2933     on init
2934     exit(1 > 1s)
2935     end on
2936     )NKSP_CODE",
2937     .expectParseError = true // units on both sides must match
2938     });
2939    
2940     runScript({
2941     .code = R"NKSP_CODE(
2942     on init
2943     exit(1Hz > 1B)
2944     end on
2945     )NKSP_CODE",
2946     .expectParseError = true // units on both sides must match
2947     });
2948    
2949     runScript({
2950     .code = R"NKSP_CODE(
2951     on init
2952     exit(13.0ms > 13.1ms)
2953     end on
2954     )NKSP_CODE",
2955     .expectBoolExitResult = false
2956     });
2957    
2958     runScript({
2959     .code = R"NKSP_CODE(
2960     on init
2961     exit(13.1ms > 13.0ms)
2962     end on
2963     )NKSP_CODE",
2964     .expectBoolExitResult = true
2965     });
2966    
2967     runScript({
2968     .code = R"NKSP_CODE(
2969     on init
2970     exit(0.9s > 600.0ms)
2971     end on
2972     )NKSP_CODE",
2973     .expectBoolExitResult = true
2974     });
2975    
2976     runScript({
2977     .code = R"NKSP_CODE(
2978     on init
2979     exit(600.0ms > 0.9s)
2980     end on
2981     )NKSP_CODE",
2982     .expectBoolExitResult = false
2983     });
2984    
2985     runScript({
2986     .code = R"NKSP_CODE(
2987     on init
2988     exit(5.1kHz > 5100.0Hz)
2989     end on
2990     )NKSP_CODE",
2991     .expectBoolExitResult = false
2992     });
2993    
2994     runScript({
2995     .code = R"NKSP_CODE(
2996     on init
2997     exit(5100.0Hz > 5.1kHz)
2998     end on
2999     )NKSP_CODE",
3000     .expectBoolExitResult = false
3001     });
3002    
3003     runScript({
3004     .code = R"NKSP_CODE(
3005     on init
3006     exit(1.0Hz > 1.1)
3007     end on
3008     )NKSP_CODE",
3009     .expectParseError = true // units on both sides must match
3010     });
3011    
3012     runScript({
3013     .code = R"NKSP_CODE(
3014     on init
3015     exit(1.2 > 1.34mdB)
3016     end on
3017     )NKSP_CODE",
3018     .expectParseError = true // units on both sides must match
3019     });
3020    
3021     runScript({
3022     .code = R"NKSP_CODE(
3023     on init
3024     exit(9.23us > 3.14kHz)
3025     end on
3026     )NKSP_CODE",
3027     .expectParseError = true // units on both sides must match
3028     });
3029    
3030     // 'final' ('!') operator tests ...
3031     // (should always yield in false for relation operators)
3032    
3033     runScript({
3034     .code = R"NKSP_CODE(
3035     on init
3036     exit(!-4 > !3)
3037     end on
3038     )NKSP_CODE",
3039     .expectBoolExitResult = false,
3040     .expectExitResultFinal = false
3041     });
3042    
3043     runScript({
3044     .code = R"NKSP_CODE(
3045     on init
3046     exit(-4 > 3)
3047     end on
3048     )NKSP_CODE",
3049     .expectBoolExitResult = false,
3050     .expectExitResultFinal = false
3051     });
3052    
3053 schoenebeck 3551 #if !SILENT_TEST
3054     std::cout << std::endl;
3055     #endif
3056     }
3057    
3058     static void testSmallerOrEqualOperator() {
3059     #if !SILENT_TEST
3060     std::cout << "UNIT TEST: smaller-or-equal (<=) operator\n";
3061     #endif
3062    
3063 schoenebeck 3575 // integer tests ...
3064    
3065 schoenebeck 3551 runScript({
3066     .code = R"NKSP_CODE(
3067     on init
3068     exit(3 <= 3)
3069     end on
3070     )NKSP_CODE",
3071     .expectBoolExitResult = true
3072     });
3073    
3074     runScript({
3075     .code = R"NKSP_CODE(
3076     on init
3077     exit(4 <= 4)
3078     end on
3079     )NKSP_CODE",
3080     .expectBoolExitResult = true
3081     });
3082    
3083     runScript({
3084     .code = R"NKSP_CODE(
3085     on init
3086     exit(-23 <= -23)
3087     end on
3088     )NKSP_CODE",
3089     .expectBoolExitResult = true
3090     });
3091    
3092     runScript({
3093     .code = R"NKSP_CODE(
3094     on init
3095     exit(23 <= -23)
3096     end on
3097     )NKSP_CODE",
3098     .expectBoolExitResult = false
3099     });
3100    
3101     runScript({
3102     .code = R"NKSP_CODE(
3103     on init
3104     exit(3 <= 4)
3105     end on
3106     )NKSP_CODE",
3107     .expectBoolExitResult = true
3108     });
3109    
3110     runScript({
3111     .code = R"NKSP_CODE(
3112     on init
3113     exit(4 <= 3)
3114     end on
3115     )NKSP_CODE",
3116     .expectBoolExitResult = false
3117     });
3118    
3119     runScript({
3120     .code = R"NKSP_CODE(
3121     on init
3122     exit(-4 <= 3)
3123     end on
3124     )NKSP_CODE",
3125     .expectBoolExitResult = true
3126     });
3127    
3128     runScript({
3129     .code = R"NKSP_CODE(
3130     on init
3131     exit(3 <= -4)
3132     end on
3133     )NKSP_CODE",
3134     .expectBoolExitResult = false
3135     });
3136