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

Contents of /linuxsampler/trunk/src/scriptvm/tests/NKSPCoreLangTest.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3678 - (show annotations) (download)
Fri Dec 27 22:46:08 2019 UTC (4 years, 3 months ago) by schoenebeck
File size: 185616 byte(s)
* NKSP: Added built-in script functions "msb()" and "lsb()".

* Bumped version (2.1.1.svn26).

1 /*
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 #include "../../common/RTMath.h"
16 #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 bool expectParseWarning;
35 bool expectRuntimeError;
36 bool expectNoExitResult;
37 bool expectExitResultIsInt;
38 bool expectExitResultIsReal;
39 bool prohibitExitFunctionArguments;
40 optional<vmint> expectIntExitResult;
41 optional<bool> expectBoolExitResult;
42 optional<vmfloat> expectRealExitResult;
43 optional<String> expectStringExitResult;
44 vector<MetricPrefix_t> expectExitResultUnitPrefix;
45 optional<StdUnit_t> expectExitResultUnit;
46 optional<bool> expectExitResultFinal;
47 };
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 vector<ParserIssue> warnings = parserCtx->warnings();
59 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 if (opt.expectParseWarning) {
69 TEST_ASSERT(!warnings.empty());
70 } else {
71 for (ParserIssue& wrn : warnings) {
72 wrn.dump();
73 }
74 }
75 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 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 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 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 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 if (opt.expectExitResultUnit) {
130 VMExpr* resExpr = execCtx->exitResult();
131 TEST_ASSERT(resExpr);
132 VMNumberExpr* numberExpr = resExpr->asNumber();
133 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 VMNumberExpr* numberExpr = resExpr->asNumber();
140 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 VMNumberExpr* numberExpr = resExpr->asNumber();
156 TEST_ASSERT(numberExpr);
157 TEST_ASSERT(numberExpr->isFinal() == *opt.expectExitResultFinal);
158 }
159 }
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 // integer tests ...
194
195 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 // string tests ...
230
231 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 // 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 // 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 // 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 #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 // strings only tests ...
1020
1021 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 // integer tests ...
1032
1033 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 // 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 #if !SILENT_TEST
1168 std::cout << std::endl;
1169 #endif
1170 }
1171
1172 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 // 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 //TODO: the following are unary '+' operator tests which should be moved to their own function (lazy me).
1258
1259 runScript({
1260 .code = R"NKSP_CODE(
1261 on init
1262 exit(+54)
1263 end on
1264 )NKSP_CODE",
1265 .expectIntExitResult = 54
1266 });
1267
1268 runScript({
1269 .code = R"NKSP_CODE(
1270 on init
1271 declare $foo := +54
1272 exit( $foo )
1273 end on
1274 )NKSP_CODE",
1275 .expectIntExitResult = 54
1276 });
1277
1278 runScript({
1279 .code = R"NKSP_CODE(
1280 on init
1281 exit(+0.45)
1282 end on
1283 )NKSP_CODE",
1284 .expectRealExitResult = 0.45
1285 });
1286
1287 runScript({
1288 .code = R"NKSP_CODE(
1289 on init
1290 declare ~foo := +0.29
1291 exit( ~foo )
1292 end on
1293 )NKSP_CODE",
1294 .expectRealExitResult = 0.29
1295 });
1296
1297 #if !SILENT_TEST
1298 std::cout << std::endl;
1299 #endif
1300 }
1301
1302 static void testPlusOperator() {
1303 #if !SILENT_TEST
1304 std::cout << "UNIT TEST: plus (+) operator\n";
1305 #endif
1306
1307 // integer tests ...
1308
1309 runScript({
1310 .code = R"NKSP_CODE(
1311 on init
1312 exit(4 + 3)
1313 end on
1314 )NKSP_CODE",
1315 .expectIntExitResult = 7
1316 });
1317
1318 runScript({
1319 .code = R"NKSP_CODE(
1320 on init
1321 exit(42 + 145)
1322 end on
1323 )NKSP_CODE",
1324 .expectIntExitResult = 187
1325 });
1326
1327 runScript({
1328 .code = R"NKSP_CODE(
1329 on init
1330 exit(-4 + 2)
1331 end on
1332 )NKSP_CODE",
1333 .expectIntExitResult = -2
1334 });
1335
1336 // real number tests ...
1337
1338 runScript({
1339 .code = R"NKSP_CODE(
1340 on init
1341 exit(4.0 + 3.0)
1342 end on
1343 )NKSP_CODE",
1344 .expectRealExitResult = 7.0
1345 });
1346
1347 runScript({
1348 .code = R"NKSP_CODE(
1349 on init
1350 exit(42.3 + 145.2)
1351 end on
1352 )NKSP_CODE",
1353 .expectRealExitResult = 187.5
1354 });
1355
1356 runScript({
1357 .code = R"NKSP_CODE(
1358 on init
1359 exit(-4.0 + 2.2)
1360 end on
1361 )NKSP_CODE",
1362 .expectRealExitResult = -1.8
1363 });
1364
1365 // std unit tests ...
1366
1367 runScript({
1368 .code = R"NKSP_CODE(
1369 on init
1370 exit(42ms + 145ms)
1371 end on
1372 )NKSP_CODE",
1373 .expectIntExitResult = 187,
1374 .expectExitResultUnitPrefix = { VM_MILLI },
1375 .expectExitResultUnit = VM_SECOND
1376 });
1377
1378 runScript({
1379 .code = R"NKSP_CODE(
1380 on init
1381 exit(1s + 145ms)
1382 end on
1383 )NKSP_CODE",
1384 .expectIntExitResult = 1145,
1385 .expectExitResultUnitPrefix = { VM_MILLI },
1386 .expectExitResultUnit = VM_SECOND
1387 });
1388
1389 runScript({
1390 .code = R"NKSP_CODE(
1391 on init
1392 exit(42ms + 145)
1393 end on
1394 )NKSP_CODE",
1395 .expectParseError = true // units must match for + operator
1396 });
1397
1398 runScript({
1399 .code = R"NKSP_CODE(
1400 on init
1401 exit(42 + 145ms)
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(42Hz + 145s)
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.1ms + 145.3ms)
1420 end on
1421 )NKSP_CODE",
1422 .expectRealExitResult = 187.4,
1423 .expectExitResultUnitPrefix = { VM_MILLI },
1424 .expectExitResultUnit = VM_SECOND
1425 });
1426
1427 runScript({
1428 .code = R"NKSP_CODE(
1429 on init
1430 exit(1.1s + 145.0ms)
1431 end on
1432 )NKSP_CODE",
1433 .expectRealExitResult = 1245.0,
1434 .expectExitResultUnitPrefix = { VM_MILLI },
1435 .expectExitResultUnit = VM_SECOND
1436 });
1437
1438 runScript({
1439 .code = R"NKSP_CODE(
1440 on init
1441 exit(42.1ms + 145.3)
1442 end on
1443 )NKSP_CODE",
1444 .expectParseError = true // units must match for + operator
1445 });
1446
1447 runScript({
1448 .code = R"NKSP_CODE(
1449 on init
1450 exit(42.0 + 145.0ms)
1451 end on
1452 )NKSP_CODE",
1453 .expectParseError = true // units must match for + operator
1454 });
1455
1456 runScript({
1457 .code = R"NKSP_CODE(
1458 on init
1459 exit(42.0Hz + 145.0s)
1460 end on
1461 )NKSP_CODE",
1462 .expectParseError = true // units must match for + operator
1463 });
1464
1465 // 'final' ('!') operator tests ...
1466
1467 runScript({
1468 .code = R"NKSP_CODE(
1469 on init
1470 exit(!4 + !3)
1471 end on
1472 )NKSP_CODE",
1473 .expectIntExitResult = 7,
1474 .expectExitResultFinal = true
1475 });
1476
1477 runScript({
1478 .code = R"NKSP_CODE(
1479 on init
1480 exit(4 + 3)
1481 end on
1482 )NKSP_CODE",
1483 .expectIntExitResult = 7,
1484 .expectExitResultFinal = false
1485 });
1486
1487 runScript({
1488 .code = R"NKSP_CODE(
1489 on init
1490 exit(!4.1 + !3.3)
1491 end on
1492 )NKSP_CODE",
1493 .expectRealExitResult = 7.4,
1494 .expectExitResultFinal = true
1495 });
1496
1497 runScript({
1498 .code = R"NKSP_CODE(
1499 on init
1500 exit(4.1 + 3.3)
1501 end on
1502 )NKSP_CODE",
1503 .expectRealExitResult = 7.4,
1504 .expectExitResultFinal = false
1505 });
1506
1507 #if !SILENT_TEST
1508 std::cout << std::endl;
1509 #endif
1510 }
1511
1512 static void testMinusOperator() {
1513 #if !SILENT_TEST
1514 std::cout << "UNIT TEST: minus (-) operator\n";
1515 #endif
1516
1517 // integer tests ...
1518
1519 runScript({
1520 .code = R"NKSP_CODE(
1521 on init
1522 exit(4 - 3)
1523 end on
1524 )NKSP_CODE",
1525 .expectIntExitResult = 1
1526 });
1527
1528 runScript({
1529 .code = R"NKSP_CODE(
1530 on init
1531 exit(139 - 74)
1532 end on
1533 )NKSP_CODE",
1534 .expectIntExitResult = 65
1535 });
1536
1537 runScript({
1538 .code = R"NKSP_CODE(
1539 on init
1540 exit(3 - 9)
1541 end on
1542 )NKSP_CODE",
1543 .expectIntExitResult = -6
1544 });
1545
1546 runScript({
1547 .code = R"NKSP_CODE(
1548 on init
1549 exit(-3 - 18)
1550 end on
1551 )NKSP_CODE",
1552 .expectIntExitResult = -21
1553 });
1554
1555 // real number tests ...
1556
1557 runScript({
1558 .code = R"NKSP_CODE(
1559 on init
1560 exit(4.0 - 0.2)
1561 end on
1562 )NKSP_CODE",
1563 .expectRealExitResult = 3.8
1564 });
1565
1566 runScript({
1567 .code = R"NKSP_CODE(
1568 on init
1569 exit(3.1 - 9.65)
1570 end on
1571 )NKSP_CODE",
1572 .expectRealExitResult = -6.55
1573 });
1574
1575 runScript({
1576 .code = R"NKSP_CODE(
1577 on init
1578 exit(-3.0 - 18.1)
1579 end on
1580 )NKSP_CODE",
1581 .expectRealExitResult = -21.1
1582 });
1583
1584 // std unit tests ...
1585
1586 runScript({
1587 .code = R"NKSP_CODE(
1588 on init
1589 exit(1000ms - 145ms)
1590 end on
1591 )NKSP_CODE",
1592 .expectIntExitResult = 855,
1593 .expectExitResultUnitPrefix = { VM_MILLI },
1594 .expectExitResultUnit = VM_SECOND
1595 });
1596
1597 runScript({
1598 .code = R"NKSP_CODE(
1599 on init
1600 exit(1s - 145ms)
1601 end on
1602 )NKSP_CODE",
1603 .expectIntExitResult = 855,
1604 .expectExitResultUnitPrefix = { VM_MILLI },
1605 .expectExitResultUnit = VM_SECOND
1606 });
1607
1608 runScript({
1609 .code = R"NKSP_CODE(
1610 on init
1611 exit(1s - 145)
1612 end on
1613 )NKSP_CODE",
1614 .expectParseError = true // units must match for - operator
1615 });
1616
1617 runScript({
1618 .code = R"NKSP_CODE(
1619 on init
1620 exit(1 - 145s)
1621 end on
1622 )NKSP_CODE",
1623 .expectParseError = true // units must match for - operator
1624 });
1625
1626 runScript({
1627 .code = R"NKSP_CODE(
1628 on init
1629 exit(1ms - 145mB)
1630 end on
1631 )NKSP_CODE",
1632 .expectParseError = true // units must match for - operator
1633 });
1634
1635 runScript({
1636 .code = R"NKSP_CODE(
1637 on init
1638 exit(1.0ms - 0.1ms)
1639 end on
1640 )NKSP_CODE",
1641 .expectRealExitResult = 0.9,
1642 .expectExitResultUnitPrefix = { VM_MILLI },
1643 .expectExitResultUnit = VM_SECOND
1644 });
1645
1646 runScript({
1647 .code = R"NKSP_CODE(
1648 on init
1649 exit(1.1s - 106.0ms)
1650 end on
1651 )NKSP_CODE",
1652 .expectRealExitResult = 994.0,
1653 .expectExitResultUnitPrefix = { VM_MILLI },
1654 .expectExitResultUnit = VM_SECOND
1655 });
1656
1657 runScript({
1658 .code = R"NKSP_CODE(
1659 on init
1660 exit(1100.0ms - 0.106s)
1661 end on
1662 )NKSP_CODE",
1663 .expectRealExitResult = 994.0,
1664 .expectExitResultUnitPrefix = { VM_MILLI },
1665 .expectExitResultUnit = VM_SECOND
1666 });
1667
1668 runScript({
1669 .code = R"NKSP_CODE(
1670 on init
1671 exit(1.0s - 145.0)
1672 end on
1673 )NKSP_CODE",
1674 .expectParseError = true // units must match for - operator
1675 });
1676
1677 runScript({
1678 .code = R"NKSP_CODE(
1679 on init
1680 exit(1.0 - 145.0s)
1681 end on
1682 )NKSP_CODE",
1683 .expectParseError = true // units must match for - operator
1684 });
1685
1686 runScript({
1687 .code = R"NKSP_CODE(
1688 on init
1689 exit(1.0ms - 145.0mB)
1690 end on
1691 )NKSP_CODE",
1692 .expectParseError = true // units must match for - operator
1693 });
1694
1695 // 'final' ('!') operator tests ...
1696
1697 runScript({
1698 .code = R"NKSP_CODE(
1699 on init
1700 exit(!5 - !3)
1701 end on
1702 )NKSP_CODE",
1703 .expectIntExitResult = 2,
1704 .expectExitResultFinal = true
1705 });
1706
1707 runScript({
1708 .code = R"NKSP_CODE(
1709 on init
1710 exit(5 - 3)
1711 end on
1712 )NKSP_CODE",
1713 .expectIntExitResult = 2,
1714 .expectExitResultFinal = false
1715 });
1716
1717 runScript({
1718 .code = R"NKSP_CODE(
1719 on init
1720 exit(!5.9 - !3.3)
1721 end on
1722 )NKSP_CODE",
1723 .expectRealExitResult = 2.6,
1724 .expectExitResultFinal = true
1725 });
1726
1727 runScript({
1728 .code = R"NKSP_CODE(
1729 on init
1730 exit(5.9 - 3.3)
1731 end on
1732 )NKSP_CODE",
1733 .expectRealExitResult = 2.6,
1734 .expectExitResultFinal = false
1735 });
1736
1737 #if !SILENT_TEST
1738 std::cout << std::endl;
1739 #endif
1740 }
1741
1742 static void testModuloOperator() {
1743 #if !SILENT_TEST
1744 std::cout << "UNIT TEST: modulo (mod) operator\n";
1745 #endif
1746
1747 // integer tests ...
1748
1749 runScript({
1750 .code = R"NKSP_CODE(
1751 on init
1752 exit(10 mod 8)
1753 end on
1754 )NKSP_CODE",
1755 .expectIntExitResult = 2
1756 });
1757
1758 runScript({
1759 .code = R"NKSP_CODE(
1760 on init
1761 declare $a := 10
1762 declare $b := 8
1763 exit($a mod $b)
1764 end on
1765 )NKSP_CODE",
1766 .expectIntExitResult = 2
1767 });
1768
1769 // real number tests ...
1770 // (mod operator prohibits real numbers ATM)
1771
1772 runScript({
1773 .code = R"NKSP_CODE(
1774 on init
1775 exit(10.0 mod 8.0)
1776 end on
1777 )NKSP_CODE",
1778 .expectParseError = true // mod operator prohibits real numbers ATM
1779 });
1780
1781 runScript({
1782 .code = R"NKSP_CODE(
1783 on init
1784 exit(10 mod 8.0)
1785 end on
1786 )NKSP_CODE",
1787 .expectParseError = true // mod operator prohibits real numbers ATM
1788 });
1789
1790 runScript({
1791 .code = R"NKSP_CODE(
1792 on init
1793 exit(10.0 mod 8)
1794 end on
1795 )NKSP_CODE",
1796 .expectParseError = true // mod operator prohibits real numbers ATM
1797 });
1798
1799 runScript({
1800 .code = R"NKSP_CODE(
1801 on init
1802 declare ~a := 10.0
1803 declare ~b := 8.0
1804 exit(~a mod ~b)
1805 end on
1806 )NKSP_CODE",
1807 .expectParseError = true // mod operator prohibits real numbers ATM
1808 });
1809
1810 // std unit tests ...
1811
1812 runScript({
1813 .code = R"NKSP_CODE(
1814 on init
1815 exit(10s mod 8)
1816 end on
1817 )NKSP_CODE",
1818 .expectParseError = true // mod operator prohibits std units ATM
1819 });
1820
1821 runScript({
1822 .code = R"NKSP_CODE(
1823 on init
1824 exit(10 mod 8s)
1825 end on
1826 )NKSP_CODE",
1827 .expectParseError = true // mod operator prohibits std units ATM
1828 });
1829
1830 runScript({
1831 .code = R"NKSP_CODE(
1832 on init
1833 exit(10s mod 8s)
1834 end on
1835 )NKSP_CODE",
1836 .expectParseError = true // mod operator prohibits std units ATM
1837 });
1838
1839 // 'final' ('!') operator tests ...
1840
1841 runScript({
1842 .code = R"NKSP_CODE(
1843 on init
1844 exit(!10 mod !8)
1845 end on
1846 )NKSP_CODE",
1847 .expectIntExitResult = 2,
1848 .expectExitResultFinal = true
1849 });
1850
1851 runScript({
1852 .code = R"NKSP_CODE(
1853 on init
1854 exit(10 mod 8)
1855 end on
1856 )NKSP_CODE",
1857 .expectIntExitResult = 2,
1858 .expectExitResultFinal = false
1859 });
1860
1861 #if !SILENT_TEST
1862 std::cout << std::endl;
1863 #endif
1864 }
1865
1866 static void testMultiplyOperator() {
1867 #if !SILENT_TEST
1868 std::cout << "UNIT TEST: multiply (*) operator\n";
1869 #endif
1870
1871 // integer tests ...
1872
1873 runScript({
1874 .code = R"NKSP_CODE(
1875 on init
1876 exit(10 * 8)
1877 end on
1878 )NKSP_CODE",
1879 .expectIntExitResult = 80
1880 });
1881
1882 runScript({
1883 .code = R"NKSP_CODE(
1884 on init
1885 exit(-3 * -4)
1886 end on
1887 )NKSP_CODE",
1888 .expectIntExitResult = 12
1889 });
1890
1891 runScript({
1892 .code = R"NKSP_CODE(
1893 on init
1894 exit(-52 * 63)
1895 end on
1896 )NKSP_CODE",
1897 .expectIntExitResult = -3276
1898 });
1899
1900 runScript({
1901 .code = R"NKSP_CODE(
1902 on init
1903 exit(123 * -59)
1904 end on
1905 )NKSP_CODE",
1906 .expectIntExitResult = -7257
1907 });
1908
1909 // real number tests ...
1910
1911 runScript({
1912 .code = R"NKSP_CODE(
1913 on init
1914 exit(10.2 * 8.4)
1915 end on
1916 )NKSP_CODE",
1917 .expectRealExitResult = 85.68
1918 });
1919
1920 runScript({
1921 .code = R"NKSP_CODE(
1922 on init
1923 exit(10.0 * -3.33)
1924 end on
1925 )NKSP_CODE",
1926 .expectRealExitResult = -33.3
1927 });
1928
1929 runScript({
1930 .code = R"NKSP_CODE(
1931 on init
1932 exit(-3.33 * 10.0)
1933 end on
1934 )NKSP_CODE",
1935 .expectRealExitResult = -33.3
1936 });
1937
1938 runScript({
1939 .code = R"NKSP_CODE(
1940 on init
1941 exit(-3.33 * -10.0)
1942 end on
1943 )NKSP_CODE",
1944 .expectRealExitResult = 33.3
1945 });
1946
1947 // mixed type tests ...
1948 // (mixed int * real forbidden ATM)
1949
1950 runScript({
1951 .code = R"NKSP_CODE(
1952 on init
1953 exit(2 * 3.0)
1954 end on
1955 )NKSP_CODE",
1956 .expectParseError = true // mixed int * real forbidden ATM
1957 });
1958
1959 runScript({
1960 .code = R"NKSP_CODE(
1961 on init
1962 exit(2.0 * 3)
1963 end on
1964 )NKSP_CODE",
1965 .expectParseError = true // mixed int * real forbidden ATM
1966 });
1967
1968 // std unit tests ...
1969
1970 runScript({
1971 .code = R"NKSP_CODE(
1972 on init
1973 exit(10ms * 8)
1974 end on
1975 )NKSP_CODE",
1976 .expectIntExitResult = 80,
1977 .expectExitResultUnitPrefix = { VM_MILLI },
1978 .expectExitResultUnit = VM_SECOND
1979 });
1980
1981 runScript({
1982 .code = R"NKSP_CODE(
1983 on init
1984 exit(10 * 8ms)
1985 end on
1986 )NKSP_CODE",
1987 .expectIntExitResult = 80,
1988 .expectExitResultUnitPrefix = { VM_MILLI },
1989 .expectExitResultUnit = VM_SECOND
1990 });
1991
1992 runScript({
1993 .code = R"NKSP_CODE(
1994 on init
1995 exit(10s * 8s)
1996 end on
1997 )NKSP_CODE",
1998 .expectParseError = true // units on both sides not allowed for * ATM
1999 });
2000
2001 runScript({
2002 .code = R"NKSP_CODE(
2003 on init
2004 exit(10cs * 8d)
2005 end on
2006 )NKSP_CODE",
2007 .expectIntExitResult = 80,
2008 .expectExitResultUnitPrefix = { VM_MILLI },
2009 .expectExitResultUnit = VM_SECOND
2010 });
2011
2012 runScript({
2013 .code = R"NKSP_CODE(
2014 on init
2015 exit(10m * 8ms)
2016 end on
2017 )NKSP_CODE",
2018 .expectIntExitResult = 80,
2019 .expectExitResultUnitPrefix = { VM_MICRO },
2020 .expectExitResultUnit = VM_SECOND
2021 });
2022
2023 runScript({
2024 .code = R"NKSP_CODE(
2025 on init
2026 exit(10ms * 8k)
2027 end on
2028 )NKSP_CODE",
2029 .expectIntExitResult = 80,
2030 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2031 .expectExitResultUnit = VM_SECOND
2032 });
2033
2034 runScript({
2035 .code = R"NKSP_CODE(
2036 on init
2037 exit(10.1ms * 8.0)
2038 end on
2039 )NKSP_CODE",
2040 .expectRealExitResult = 80.8,
2041 .expectExitResultUnitPrefix = { VM_MILLI },
2042 .expectExitResultUnit = VM_SECOND
2043 });
2044
2045 runScript({
2046 .code = R"NKSP_CODE(
2047 on init
2048 exit(10.1 * 8.0ms)
2049 end on
2050 )NKSP_CODE",
2051 .expectRealExitResult = 80.8,
2052 .expectExitResultUnitPrefix = { VM_MILLI },
2053 .expectExitResultUnit = VM_SECOND
2054 });
2055
2056 runScript({
2057 .code = R"NKSP_CODE(
2058 on init
2059 exit(10.0s * 8.0s)
2060 end on
2061 )NKSP_CODE",
2062 .expectParseError = true // units on both sides not allowed for * ATM
2063 });
2064
2065 runScript({
2066 .code = R"NKSP_CODE(
2067 on init
2068 exit(10.1ds * 8.0c)
2069 end on
2070 )NKSP_CODE",
2071 .expectRealExitResult = 80.8,
2072 .expectExitResultUnitPrefix = { VM_MILLI },
2073 .expectExitResultUnit = VM_SECOND
2074 });
2075
2076 runScript({
2077 .code = R"NKSP_CODE(
2078 on init
2079 exit(10.1m * 8.0ms)
2080 end on
2081 )NKSP_CODE",
2082 .expectRealExitResult = 80.8,
2083 .expectExitResultUnitPrefix = { VM_MICRO },
2084 .expectExitResultUnit = VM_SECOND
2085 });
2086
2087 runScript({
2088 .code = R"NKSP_CODE(
2089 on init
2090 exit(10.1m * 8.0ks)
2091 end on
2092 )NKSP_CODE",
2093 .expectRealExitResult = 80.8,
2094 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2095 .expectExitResultUnit = VM_SECOND
2096 });
2097
2098 // 'final' ('!') operator tests ...
2099
2100 runScript({
2101 .code = R"NKSP_CODE(
2102 on init
2103 exit(!10 * !8)
2104 end on
2105 )NKSP_CODE",
2106 .expectIntExitResult = 80,
2107 .expectExitResultFinal = true
2108 });
2109
2110 runScript({
2111 .code = R"NKSP_CODE(
2112 on init
2113 exit(10 * 8)
2114 end on
2115 )NKSP_CODE",
2116 .expectIntExitResult = 80,
2117 .expectExitResultFinal = false
2118 });
2119
2120 runScript({
2121 .code = R"NKSP_CODE(
2122 on init
2123 exit(!10 * 8)
2124 end on
2125 )NKSP_CODE",
2126 .expectIntExitResult = 80,
2127 .expectExitResultFinal = true,
2128 .expectParseWarning = true // since final only on one side, result will be final though
2129 });
2130
2131 runScript({
2132 .code = R"NKSP_CODE(
2133 on init
2134 exit(10 * !8)
2135 end on
2136 )NKSP_CODE",
2137 .expectIntExitResult = 80,
2138 .expectExitResultFinal = true,
2139 .expectParseWarning = true // since final only on one side, result will be final though
2140 });
2141
2142 runScript({
2143 .code = R"NKSP_CODE(
2144 on init
2145 exit(!10.1 * !8.0)
2146 end on
2147 )NKSP_CODE",
2148 .expectRealExitResult = 80.8,
2149 .expectExitResultFinal = true
2150 });
2151
2152 runScript({
2153 .code = R"NKSP_CODE(
2154 on init
2155 exit(10.1 * 8.0)
2156 end on
2157 )NKSP_CODE",
2158 .expectRealExitResult = 80.8,
2159 .expectExitResultFinal = false
2160 });
2161
2162 runScript({
2163 .code = R"NKSP_CODE(
2164 on init
2165 exit(!10.1 * 8.0)
2166 end on
2167 )NKSP_CODE",
2168 .expectRealExitResult = 80.8,
2169 .expectExitResultFinal = true,
2170 .expectParseWarning = true // since final only on one side, result will be final though
2171 });
2172
2173 runScript({
2174 .code = R"NKSP_CODE(
2175 on init
2176 exit(10.1 * !8.0)
2177 end on
2178 )NKSP_CODE",
2179 .expectRealExitResult = 80.8,
2180 .expectExitResultFinal = true,
2181 .expectParseWarning = true // since final only on one side, result will be final though
2182 });
2183
2184 #if !SILENT_TEST
2185 std::cout << std::endl;
2186 #endif
2187 }
2188
2189 static void testDivideOperator() {
2190 #if !SILENT_TEST
2191 std::cout << "UNIT TEST: divide (/) operator\n";
2192 #endif
2193
2194 // integer tests ...
2195
2196 runScript({
2197 .code = R"NKSP_CODE(
2198 on init
2199 exit(9 / 3)
2200 end on
2201 )NKSP_CODE",
2202 .expectIntExitResult = 3
2203 });
2204
2205 runScript({
2206 .code = R"NKSP_CODE(
2207 on init
2208 exit(-27 / 3)
2209 end on
2210 )NKSP_CODE",
2211 .expectIntExitResult = -9
2212 });
2213
2214 runScript({
2215 .code = R"NKSP_CODE(
2216 on init
2217 exit(35 / -5)
2218 end on
2219 )NKSP_CODE",
2220 .expectIntExitResult = -7
2221 });
2222
2223 runScript({
2224 .code = R"NKSP_CODE(
2225 on init
2226 exit(39 / -5)
2227 end on
2228 )NKSP_CODE",
2229 .expectIntExitResult = -7
2230 });
2231
2232 // real number tests ...
2233
2234 runScript({
2235 .code = R"NKSP_CODE(
2236 on init
2237 exit(9.0 / 10.0)
2238 end on
2239 )NKSP_CODE",
2240 .expectRealExitResult = 0.9
2241 });
2242
2243 runScript({
2244 .code = R"NKSP_CODE(
2245 on init
2246 exit(-9.0 / 10.0)
2247 end on
2248 )NKSP_CODE",
2249 .expectRealExitResult = -0.9
2250 });
2251
2252 runScript({
2253 .code = R"NKSP_CODE(
2254 on init
2255 exit(9.0 / -10.0)
2256 end on
2257 )NKSP_CODE",
2258 .expectRealExitResult = -0.9
2259 });
2260
2261 runScript({
2262 .code = R"NKSP_CODE(
2263 on init
2264 exit(-9.0 / -10.0)
2265 end on
2266 )NKSP_CODE",
2267 .expectRealExitResult = 0.9
2268 });
2269
2270 // mixed type tests ...
2271 // (mixed int / real forbidden ATM)
2272
2273 runScript({
2274 .code = R"NKSP_CODE(
2275 on init
2276 exit(9 / 10.0)
2277 end on
2278 )NKSP_CODE",
2279 .expectParseError = true // mixed int / real forbidden ATM
2280 });
2281
2282 runScript({
2283 .code = R"NKSP_CODE(
2284 on init
2285 exit(9.0 / 10)
2286 end on
2287 )NKSP_CODE",
2288 .expectParseError = true // mixed int / real forbidden ATM
2289 });
2290
2291 // std unit tests ...
2292
2293 runScript({
2294 .code = R"NKSP_CODE(
2295 on init
2296 exit(-27us / 3)
2297 end on
2298 )NKSP_CODE",
2299 .expectIntExitResult = -9,
2300 .expectExitResultUnitPrefix = { VM_MICRO },
2301 .expectExitResultUnit = VM_SECOND
2302 });
2303
2304 runScript({
2305 .code = R"NKSP_CODE(
2306 on init
2307 exit(-27mdB / 3mdB)
2308 end on
2309 )NKSP_CODE",
2310 .expectIntExitResult = -9,
2311 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
2312 .expectExitResultUnit = VM_NO_UNIT
2313 });
2314
2315 runScript({
2316 .code = R"NKSP_CODE(
2317 on init
2318 exit(-27s / 3m)
2319 end on
2320 )NKSP_CODE",
2321 .expectIntExitResult = -9,
2322 .expectExitResultUnitPrefix = { VM_KILO },
2323 .expectExitResultUnit = VM_SECOND
2324 });
2325
2326 runScript({
2327 .code = R"NKSP_CODE(
2328 on init
2329 exit(-27us / 3m)
2330 end on
2331 )NKSP_CODE",
2332 .expectIntExitResult = -9,
2333 .expectExitResultUnitPrefix = { VM_MILLI },
2334 .expectExitResultUnit = VM_SECOND
2335 });
2336
2337 runScript({
2338 .code = R"NKSP_CODE(
2339 on init
2340 exit(-27 / 3s)
2341 end on
2342 )NKSP_CODE",
2343 .expectParseError = true // illegal unit type arrangement for divisions
2344 });
2345
2346 runScript({
2347 .code = R"NKSP_CODE(
2348 on init
2349 exit(-27s / 3Hz)
2350 end on
2351 )NKSP_CODE",
2352 .expectParseError = true // unit types are not matching
2353 });
2354
2355 // 'final' ('!') operator tests ...
2356
2357 runScript({
2358 .code = R"NKSP_CODE(
2359 on init
2360 exit(!-27 / !3)
2361 end on
2362 )NKSP_CODE",
2363 .expectIntExitResult = -9,
2364 .expectExitResultFinal = true
2365 });
2366
2367 runScript({
2368 .code = R"NKSP_CODE(
2369 on init
2370 exit(-27 / 3)
2371 end on
2372 )NKSP_CODE",
2373 .expectIntExitResult = -9,
2374 .expectExitResultFinal = false
2375 });
2376
2377 runScript({
2378 .code = R"NKSP_CODE(
2379 on init
2380 exit(!-27 / 3)
2381 end on
2382 )NKSP_CODE",
2383 .expectIntExitResult = -9,
2384 .expectExitResultFinal = true,
2385 .expectParseWarning = true // final only on one side, result will be final though
2386 });
2387
2388 runScript({
2389 .code = R"NKSP_CODE(
2390 on init
2391 exit(-27 / !3)
2392 end on
2393 )NKSP_CODE",
2394 .expectIntExitResult = -9,
2395 .expectExitResultFinal = true,
2396 .expectParseWarning = true // final only on one side, result will be final though
2397 });
2398
2399 #if !SILENT_TEST
2400 std::cout << std::endl;
2401 #endif
2402 }
2403
2404 static void testSmallerThanOperator() {
2405 #if !SILENT_TEST
2406 std::cout << "UNIT TEST: smaller than (<) operator\n";
2407 #endif
2408
2409 // integer tests ...
2410
2411 runScript({
2412 .code = R"NKSP_CODE(
2413 on init
2414 exit(3 < 4)
2415 end on
2416 )NKSP_CODE",
2417 .expectBoolExitResult = true
2418 });
2419
2420 runScript({
2421 .code = R"NKSP_CODE(
2422 on init
2423 exit(4 < 3)
2424 end on
2425 )NKSP_CODE",
2426 .expectBoolExitResult = false
2427 });
2428
2429 runScript({
2430 .code = R"NKSP_CODE(
2431 on init
2432 exit(-4 < 3)
2433 end on
2434 )NKSP_CODE",
2435 .expectBoolExitResult = true
2436 });
2437
2438 runScript({
2439 .code = R"NKSP_CODE(
2440 on init
2441 exit(3 < -4)
2442 end on
2443 )NKSP_CODE",
2444 .expectBoolExitResult = false
2445 });
2446
2447 runScript({
2448 .code = R"NKSP_CODE(
2449 on init
2450 exit(123 < -45)
2451 end on
2452 )NKSP_CODE",
2453 .expectBoolExitResult = false
2454 });
2455
2456 runScript({
2457 .code = R"NKSP_CODE(
2458 on init
2459 exit(-45 < 123)
2460 end on
2461 )NKSP_CODE",
2462 .expectBoolExitResult = true
2463 });
2464
2465 // real number tests ...
2466
2467 runScript({
2468 .code = R"NKSP_CODE(
2469 on init
2470 exit(3.0 < 4.0)
2471 end on
2472 )NKSP_CODE",
2473 .expectBoolExitResult = true
2474 });
2475
2476 runScript({
2477 .code = R"NKSP_CODE(
2478 on init
2479 exit(4.0 < 3.0)
2480 end on
2481 )NKSP_CODE",
2482 .expectBoolExitResult = false
2483 });
2484
2485 runScript({
2486 .code = R"NKSP_CODE(
2487 on init
2488 exit(1.2 < 1.23)
2489 end on
2490 )NKSP_CODE",
2491 .expectBoolExitResult = true
2492 });
2493
2494 runScript({
2495 .code = R"NKSP_CODE(
2496 on init
2497 exit(1.23 < 1.2)
2498 end on
2499 )NKSP_CODE",
2500 .expectBoolExitResult = false
2501 });
2502
2503 runScript({
2504 .code = R"NKSP_CODE(
2505 on init
2506 exit(-4.0 < 3.0)
2507 end on
2508 )NKSP_CODE",
2509 .expectBoolExitResult = true
2510 });
2511
2512 runScript({
2513 .code = R"NKSP_CODE(
2514 on init
2515 exit(3.0 < -4.0)
2516 end on
2517 )NKSP_CODE",
2518 .expectBoolExitResult = false
2519 });
2520
2521 runScript({
2522 .code = R"NKSP_CODE(
2523 on init
2524 exit(123.0 < -45.0)
2525 end on
2526 )NKSP_CODE",
2527 .expectBoolExitResult = false
2528 });
2529
2530 runScript({
2531 .code = R"NKSP_CODE(
2532 on init
2533 exit(-45.0 < 123.0)
2534 end on
2535 )NKSP_CODE",
2536 .expectBoolExitResult = true
2537 });
2538
2539 // mixed type tests ...
2540
2541 runScript({
2542 .code = R"NKSP_CODE(
2543 on init
2544 exit(9 < 9.1)
2545 end on
2546 )NKSP_CODE",
2547 .expectBoolExitResult = true
2548 });
2549
2550 runScript({
2551 .code = R"NKSP_CODE(
2552 on init
2553 exit(9.1 < 9)
2554 end on
2555 )NKSP_CODE",
2556 .expectBoolExitResult = false
2557 });
2558
2559 // std unit tests ...
2560
2561 runScript({
2562 .code = R"NKSP_CODE(
2563 on init
2564 exit(13ms < 14ms)
2565 end on
2566 )NKSP_CODE",
2567 .expectBoolExitResult = true
2568 });
2569
2570 runScript({
2571 .code = R"NKSP_CODE(
2572 on init
2573 exit(14ms < 13ms)
2574 end on
2575 )NKSP_CODE",
2576 .expectBoolExitResult = false
2577 });
2578
2579 runScript({
2580 .code = R"NKSP_CODE(
2581 on init
2582 exit(1s < 990ms)
2583 end on
2584 )NKSP_CODE",
2585 .expectBoolExitResult = false
2586 });
2587
2588 runScript({
2589 .code = R"NKSP_CODE(
2590 on init
2591 exit(990ms < 1s)
2592 end on
2593 )NKSP_CODE",
2594 .expectBoolExitResult = true
2595 });
2596
2597 runScript({
2598 .code = R"NKSP_CODE(
2599 on init
2600 exit(1000ms < 1s)
2601 end on
2602 )NKSP_CODE",
2603 .expectBoolExitResult = false
2604 });
2605
2606 runScript({
2607 .code = R"NKSP_CODE(
2608 on init
2609 exit(1s < 1000ms)
2610 end on
2611 )NKSP_CODE",
2612 .expectBoolExitResult = false
2613 });
2614
2615 runScript({
2616 .code = R"NKSP_CODE(
2617 on init
2618 exit(1s < 1)
2619 end on
2620 )NKSP_CODE",
2621 .expectParseError = true // units on both sides must match
2622 });
2623
2624 runScript({
2625 .code = R"NKSP_CODE(
2626 on init
2627 exit(1 < 1s)
2628 end on
2629 )NKSP_CODE",
2630 .expectParseError = true // units on both sides must match
2631 });
2632
2633 runScript({
2634 .code = R"NKSP_CODE(
2635 on init
2636 exit(1Hz < 1B)
2637 end on
2638 )NKSP_CODE",
2639 .expectParseError = true // units on both sides must match
2640 });
2641
2642 runScript({
2643 .code = R"NKSP_CODE(
2644 on init
2645 exit(13.0ms < 13.1ms)
2646 end on
2647 )NKSP_CODE",
2648 .expectBoolExitResult = true
2649 });
2650
2651 runScript({
2652 .code = R"NKSP_CODE(
2653 on init
2654 exit(13.1ms < 13.0ms)
2655 end on
2656 )NKSP_CODE",
2657 .expectBoolExitResult = false
2658 });
2659
2660 runScript({
2661 .code = R"NKSP_CODE(
2662 on init
2663 exit(0.9s < 600.0ms)
2664 end on
2665 )NKSP_CODE",
2666 .expectBoolExitResult = false
2667 });
2668
2669 runScript({
2670 .code = R"NKSP_CODE(
2671 on init
2672 exit(600.0ms < 0.9s)
2673 end on
2674 )NKSP_CODE",
2675 .expectBoolExitResult = true
2676 });
2677
2678 runScript({
2679 .code = R"NKSP_CODE(
2680 on init
2681 exit(5.1kHz < 5100.0Hz)
2682 end on
2683 )NKSP_CODE",
2684 .expectBoolExitResult = false
2685 });
2686
2687 runScript({
2688 .code = R"NKSP_CODE(
2689 on init
2690 exit(5100.0Hz < 5.1kHz)
2691 end on
2692 )NKSP_CODE",
2693 .expectBoolExitResult = false
2694 });
2695
2696 runScript({
2697 .code = R"NKSP_CODE(
2698 on init
2699 exit(1.0Hz < 1.1)
2700 end on
2701 )NKSP_CODE",
2702 .expectParseError = true // units on both sides must match
2703 });
2704
2705 runScript({
2706 .code = R"NKSP_CODE(
2707 on init
2708 exit(1.2 < 1.34mdB)
2709 end on
2710 )NKSP_CODE",
2711 .expectParseError = true // units on both sides must match
2712 });
2713
2714 runScript({
2715 .code = R"NKSP_CODE(
2716 on init
2717 exit(9.23us < 3.14kHz)
2718 end on
2719 )NKSP_CODE",
2720 .expectParseError = true // units on both sides must match
2721 });
2722
2723 // 'final' ('!') operator tests ...
2724 // (should always yield in false for relation operators)
2725
2726 runScript({
2727 .code = R"NKSP_CODE(
2728 on init
2729 exit(!-4 < !3)
2730 end on
2731 )NKSP_CODE",
2732 .expectBoolExitResult = true,
2733 .expectExitResultFinal = false
2734 });
2735
2736 runScript({
2737 .code = R"NKSP_CODE(
2738 on init
2739 exit(-4 < 3)
2740 end on
2741 )NKSP_CODE",
2742 .expectBoolExitResult = true,
2743 .expectExitResultFinal = false
2744 });
2745
2746 #if !SILENT_TEST
2747 std::cout << std::endl;
2748 #endif
2749 }
2750
2751 static void testGreaterThanOperator() {
2752 #if !SILENT_TEST
2753 std::cout << "UNIT TEST: greater than (>) operator\n";
2754 #endif
2755
2756 // integer tests ...
2757
2758 runScript({
2759 .code = R"NKSP_CODE(
2760 on init
2761 exit(3 > 4)
2762 end on
2763 )NKSP_CODE",
2764 .expectBoolExitResult = false
2765 });
2766
2767 runScript({
2768 .code = R"NKSP_CODE(
2769 on init
2770 exit(4 > 3)
2771 end on
2772 )NKSP_CODE",
2773 .expectBoolExitResult = true
2774 });
2775
2776 runScript({
2777 .code = R"NKSP_CODE(
2778 on init
2779 exit(-4 > 3)
2780 end on
2781 )NKSP_CODE",
2782 .expectBoolExitResult = false
2783 });
2784
2785 runScript({
2786 .code = R"NKSP_CODE(
2787 on init
2788 exit(3 > -4)
2789 end on
2790 )NKSP_CODE",
2791 .expectBoolExitResult = true
2792 });
2793
2794 runScript({
2795 .code = R"NKSP_CODE(
2796 on init
2797 exit(123 > -45)
2798 end on
2799 )NKSP_CODE",
2800 .expectBoolExitResult = true
2801 });
2802
2803 runScript({
2804 .code = R"NKSP_CODE(
2805 on init
2806 exit(-45 > 123)
2807 end on
2808 )NKSP_CODE",
2809 .expectBoolExitResult = false
2810 });
2811
2812 // real number tests ...
2813
2814 runScript({
2815 .code = R"NKSP_CODE(
2816 on init
2817 exit(3.0 > 4.0)
2818 end on
2819 )NKSP_CODE",
2820 .expectBoolExitResult = false
2821 });
2822
2823 runScript({
2824 .code = R"NKSP_CODE(
2825 on init
2826 exit(4.0 > 3.0)
2827 end on
2828 )NKSP_CODE",
2829 .expectBoolExitResult = true
2830 });
2831
2832 runScript({
2833 .code = R"NKSP_CODE(
2834 on init
2835 exit(1.2 > 1.23)
2836 end on
2837 )NKSP_CODE",
2838 .expectBoolExitResult = false
2839 });
2840
2841 runScript({
2842 .code = R"NKSP_CODE(
2843 on init
2844 exit(1.23 > 1.2)
2845 end on
2846 )NKSP_CODE",
2847 .expectBoolExitResult = true
2848 });
2849
2850 runScript({
2851 .code = R"NKSP_CODE(
2852 on init
2853 exit(-4.0 > 3.0)
2854 end on
2855 )NKSP_CODE",
2856 .expectBoolExitResult = false
2857 });
2858
2859 runScript({
2860 .code = R"NKSP_CODE(
2861 on init
2862 exit(3.0 > -4.0)
2863 end on
2864 )NKSP_CODE",
2865 .expectBoolExitResult = true
2866 });
2867
2868 runScript({
2869 .code = R"NKSP_CODE(
2870 on init
2871 exit(123.0 > -45.0)
2872 end on
2873 )NKSP_CODE",
2874 .expectBoolExitResult = true
2875 });
2876
2877 runScript({
2878 .code = R"NKSP_CODE(
2879 on init
2880 exit(-45.0 > 123.0)
2881 end on
2882 )NKSP_CODE",
2883 .expectBoolExitResult = false
2884 });
2885
2886 // mixed type tests ...
2887
2888 runScript({
2889 .code = R"NKSP_CODE(
2890 on init
2891 exit(9 > 9.1)
2892 end on
2893 )NKSP_CODE",
2894 .expectBoolExitResult = false
2895 });
2896
2897 runScript({
2898 .code = R"NKSP_CODE(
2899 on init
2900 exit(9.1 > 9)
2901 end on
2902 )NKSP_CODE",
2903 .expectBoolExitResult = true
2904 });
2905
2906 // std unit tests ...
2907
2908 runScript({
2909 .code = R"NKSP_CODE(
2910 on init
2911 exit(13ms > 14ms)
2912 end on
2913 )NKSP_CODE",
2914 .expectBoolExitResult = false
2915 });
2916
2917 runScript({
2918 .code = R"NKSP_CODE(
2919 on init
2920 exit(14ms > 13ms)
2921 end on
2922 )NKSP_CODE",
2923 .expectBoolExitResult = true
2924 });
2925
2926 runScript({
2927 .code = R"NKSP_CODE(
2928 on init
2929 exit(1s > 990ms)
2930 end on
2931 )NKSP_CODE",
2932 .expectBoolExitResult = true
2933 });
2934
2935 runScript({
2936 .code = R"NKSP_CODE(
2937 on init
2938 exit(990ms > 1s)
2939 end on
2940 )NKSP_CODE",
2941 .expectBoolExitResult = false
2942 });
2943
2944 runScript({
2945 .code = R"NKSP_CODE(
2946 on init
2947 exit(1000ms > 1s)
2948 end on
2949 )NKSP_CODE",
2950 .expectBoolExitResult = false
2951 });
2952
2953 runScript({
2954 .code = R"NKSP_CODE(
2955 on init
2956 exit(1s > 1000ms)
2957 end on
2958 )NKSP_CODE",
2959 .expectBoolExitResult = false
2960 });
2961
2962 runScript({
2963 .code = R"NKSP_CODE(
2964 on init
2965 exit(1s > 1)
2966 end on
2967 )NKSP_CODE",
2968 .expectParseError = true // units on both sides must match
2969 });
2970
2971 runScript({
2972 .code = R"NKSP_CODE(
2973 on init
2974 exit(1 > 1s)
2975 end on
2976 )NKSP_CODE",
2977 .expectParseError = true // units on both sides must match
2978 });
2979
2980 runScript({
2981 .code = R"NKSP_CODE(
2982 on init
2983 exit(1Hz > 1B)
2984 end on
2985 )NKSP_CODE",
2986 .expectParseError = true // units on both sides must match
2987 });
2988
2989 runScript({
2990 .code = R"NKSP_CODE(
2991 on init
2992 exit(13.0ms > 13.1ms)
2993 end on
2994 )NKSP_CODE",
2995 .expectBoolExitResult = false
2996 });
2997
2998 runScript({
2999 .code = R"NKSP_CODE(
3000 on init
3001 exit(13.1ms > 13.0ms)
3002 end on
3003 )NKSP_CODE",
3004 .expectBoolExitResult = true
3005 });
3006
3007 runScript({
3008 .code = R"NKSP_CODE(
3009 on init
3010 exit(0.9s > 600.0ms)
3011 end on
3012 )NKSP_CODE",
3013 .expectBoolExitResult = true
3014 });
3015
3016 runScript({
3017 .code = R"NKSP_CODE(
3018 on init
3019 exit(600.0ms > 0.9s)
3020 end on
3021 )NKSP_CODE",
3022 .expectBoolExitResult = false
3023 });
3024
3025 runScript({
3026 .code = R"NKSP_CODE(
3027 on init
3028 exit(5.1kHz > 5100.0Hz)
3029 end on
3030 )NKSP_CODE",
3031 .expectBoolExitResult = false
3032 });
3033
3034 runScript({
3035 .code = R"NKSP_CODE(
3036 on init
3037 exit(5100.0Hz > 5.1kHz)
3038 end on
3039 )NKSP_CODE",
3040 .expectBoolExitResult = false
3041 });
3042
3043 runScript({
3044 .code = R"NKSP_CODE(
3045 on init
3046 exit(1.0Hz > 1.1)
3047 end on
3048 )NKSP_CODE",
3049 .expectParseError = true // units on both sides must match
3050 });
3051
3052 runScript({
3053 .code = R"NKSP_CODE(
3054 on init
3055 exit(1.2 > 1.34mdB)
3056 end on
3057 )NKSP_CODE",
3058 .expectParseError = true // units on both sides must match
3059 });
3060
3061 runScript({
3062 .code = R"NKSP_CODE(
3063 on init
3064 exit(9.23us > 3.14kHz)
3065 end on
3066 )NKSP_CODE",
3067 .expectParseError = true // units on both sides must match
3068 });
3069
3070 // 'final' ('!') operator tests ...
3071 // (should always yield in false for relation operators)
3072
3073 runScript({
3074 .code = R"NKSP_CODE(
3075 on init
3076 exit(!-4 > !3)
3077 end on
3078 )NKSP_CODE",
3079 .expectBoolExitResult = false,
3080 .expectExitResultFinal = false
3081 });
3082
3083 runScript({
3084 .code = R"NKSP_CODE(
3085 on init
3086 exit(-4 > 3)
3087 end on
3088 )NKSP_CODE",
3089 .expectBoolExitResult = false,
3090 .expectExitResultFinal = false
3091 });
3092
3093 #if !SILENT_TEST
3094 std::cout << std::endl;
3095 #endif
3096 }
3097
3098 static void testSmallerOrEqualOperator() {
3099 #if !SILENT_TEST
3100 std::cout << "UNIT TEST: smaller-or-equal (<=) operator\n";
3101 #endif
3102
3103 // integer tests ...
3104
3105 runScript({
3106 .code = R"NKSP_CODE(
3107 on init
3108 exit(3 <= 3)
3109 end on
3110 )NKSP_CODE",
3111 .expectBoolExitResult = true
3112 });
3113
3114 runScript({
3115 .code = R"NKSP_CODE(
3116 on init
3117 exit(4 <= 4)
3118 end on
3119 )NKSP_CODE",
3120 .expectBoolExitResult = true
3121 });
3122
3123 runScript({
3124 .code = R"NKSP_CODE(
3125 on init
3126 exit(-23 <= -23)
3127 end on
3128 )NKSP_CODE",
3129 .expectBoolExitResult = true
3130 });
3131
3132 runScript({
3133 .code = R"NKSP_CODE(
3134 on init
3135 exit(23 <= -23)
3136 end on
3137 )NKSP_CODE",
3138 .expectBoolExitResult = false
3139 });
3140
3141 runScript({
3142 .code = R"NKSP_CODE(
3143 on init
3144 exit(3 <= 4)
3145 end on
3146 )NKSP_CODE",
3147 .expectBoolExitResult = true
3148 });
3149
3150 runScript({
3151 .code = R"NKSP_CODE(
3152 on init
3153 exit(4 <= 3)
3154 end on
3155 )NKSP_CODE",
3156 .expectBoolExitResult = false
3157 });
3158
3159 runScript({
3160 .code = R"NKSP_CODE(
3161 on init
3162 exit(-4 <= 3)
3163 end on
3164 )NKSP_CODE",
3165 .expectBoolExitResult = true
3166 });
3167
3168 runScript({
3169 .code = R"NKSP_CODE(
3170 on init
3171 exit(3 <= -4)
3172 end on
3173 )NKSP_CODE",
3174 .expectBoolExitResult = false
3175 });
3176
3177 runScript({
3178 .code = R"NKSP_CODE(
3179 on init
3180 exit(123 <= -45)
3181 end on
3182 )NKSP_CODE",
3183 .expectBoolExitResult = false
3184 });
3185
3186 runScript({
3187 .code = R"NKSP_CODE(
3188 on init
3189 exit(-45 <= 123)
3190 end on
3191 )NKSP_CODE",
3192 .expectBoolExitResult = true
3193 });
3194
3195 // real number tests ...
3196
3197 runScript({
3198 .code = R"NKSP_CODE(
3199 on init
3200 exit(3.0 <= 3.0)
3201 end on
3202 )NKSP_CODE",
3203 .expectBoolExitResult = true
3204 });
3205
3206 runScript({
3207 .code = R"NKSP_CODE(
3208 on init
3209 exit(4.33 <= 4.33)
3210 end on
3211 )NKSP_CODE",
3212 .expectBoolExitResult = true
3213 });
3214
3215 runScript({
3216 .code = R"NKSP_CODE(
3217 on init
3218 exit(-23.1 <= -23.1)
3219 end on
3220 )NKSP_CODE",
3221 .expectBoolExitResult = true
3222 });
3223
3224 runScript({
3225 .code = R"NKSP_CODE(
3226 on init
3227 exit(23.3 <= -23.3)
3228 end on
3229 )NKSP_CODE",
3230 .expectBoolExitResult = false
3231 });
3232
3233 runScript({
3234 .code = R"NKSP_CODE(
3235 on init
3236 exit(3.0 <= 4.0)
3237 end on
3238 )NKSP_CODE",
3239 .expectBoolExitResult = true
3240 });
3241
3242 runScript({
3243 .code = R"NKSP_CODE(
3244 on init
3245 exit(4.0 <= 3.0)
3246 end on
3247 )NKSP_CODE",
3248 .expectBoolExitResult = false
3249 });
3250
3251 runScript({
3252 .code = R"NKSP_CODE(
3253 on init
3254 exit(-4.0 <= 3.0)
3255 end on
3256 )NKSP_CODE",
3257 .expectBoolExitResult = true
3258 });
3259
3260 runScript({
3261 .code = R"NKSP_CODE(
3262 on init
3263 exit(3.0 <= -4.0)
3264 end on
3265 )NKSP_CODE",
3266 .expectBoolExitResult = false
3267 });
3268
3269 runScript({
3270 .code = R"NKSP_CODE(
3271 on init
3272 exit(123.0 <= -45.0)
3273 end on
3274 )NKSP_CODE",
3275 .expectBoolExitResult = false
3276 });
3277
3278 runScript({
3279 .code = R"NKSP_CODE(
3280 on init
3281 exit(-45.0 <= 123.0)
3282 end on
3283 )NKSP_CODE",
3284 .expectBoolExitResult = true
3285 });
3286
3287 // mixed type tests ...
3288
3289 runScript({
3290 .code = R"NKSP_CODE(
3291 on init
3292 exit(9 <= 9.1)
3293 end on
3294 )NKSP_CODE",
3295 .expectBoolExitResult = true
3296 });
3297
3298 runScript({
3299 .code = R"NKSP_CODE(
3300 on init
3301 exit(9.1 <= 9)
3302 end on
3303 )NKSP_CODE",
3304 .expectBoolExitResult = false
3305 });
3306
3307 runScript({
3308 .code = R"NKSP_CODE(
3309 on init
3310 exit(9 <= 9.0)
3311 end on
3312 )NKSP_CODE",
3313 .expectBoolExitResult = true
3314 });
3315
3316 runScript({
3317 .code = R"NKSP_CODE(
3318 on init
3319 exit(9.0 <= 9)
3320 end on
3321 )NKSP_CODE",
3322 .expectBoolExitResult = true
3323 });
3324
3325 // std unit tests ...
3326
3327 runScript({
3328 .code = R"NKSP_CODE(
3329 on init
3330 exit(13ms <= 14ms)
3331 end on
3332 )NKSP_CODE",
3333 .expectBoolExitResult = true
3334 });
3335
3336 runScript({
3337 .code = R"NKSP_CODE(
3338 on init
3339 exit(14ms <= 13ms)
3340 end on
3341 )NKSP_CODE",
3342 .expectBoolExitResult = false
3343 });
3344
3345 runScript({
3346 .code = R"NKSP_CODE(
3347 on init
3348 exit(1s <= 990ms)
3349 end on
3350 )NKSP_CODE",
3351 .expectBoolExitResult = false
3352 });
3353
3354 runScript({
3355 .code = R"NKSP_CODE(
3356 on init
3357 exit(990ms <= 1s)
3358 end on
3359 )NKSP_CODE",
3360 .expectBoolExitResult = true
3361 });
3362
3363 runScript({
3364 .code = R"NKSP_CODE(
3365 on init
3366 exit(1000ms <= 1s)
3367 end on
3368 )NKSP_CODE",
3369 .expectBoolExitResult = true
3370 });
3371
3372 runScript({
3373 .code = R"NKSP_CODE(
3374 on init
3375 exit(1s <= 1000ms)
3376 end on
3377 )NKSP_CODE",
3378 .expectBoolExitResult = true
3379 });
3380
3381 runScript({
3382 .code = R"NKSP_CODE(
3383 on init
3384 exit(1s <= 1)
3385 end on
3386 )NKSP_CODE",
3387 .expectParseError = true // units on both sides must match
3388 });
3389
3390 runScript({
3391 .code = R"NKSP_CODE(
3392 on init
3393 exit(1 <= 1s)
3394 end on
3395 )NKSP_CODE",
3396 .expectParseError = true // units on both sides must match
3397 });
3398
3399 runScript({
3400 .code = R"NKSP_CODE(
3401 on init
3402 exit(1Hz <= 1B)
3403 end on
3404 )NKSP_CODE",
3405 .expectParseError = true // units on both sides must match
3406 });
3407
3408 runScript({
3409 .code = R"NKSP_CODE(
3410 on init
3411 exit(13.0ms <= 13.1ms)
3412 end on
3413 )NKSP_CODE",
3414 .expectBoolExitResult = true
3415 });
3416
3417 runScript({
3418 .code = R"NKSP_CODE(
3419 on init
3420 exit(13.1ms <= 13.0ms)
3421 end on
3422 )NKSP_CODE",
3423 .expectBoolExitResult = false
3424 });
3425
3426 runScript({
3427 .code = R"NKSP_CODE(
3428 on init
3429 exit(0.9s <= 600.0ms)
3430 end on
3431 )NKSP_CODE",
3432 .expectBoolExitResult = false
3433 });
3434
3435 runScript({
3436 .code = R"NKSP_CODE(
3437 on init
3438 exit(600.0ms <= 0.9s)
3439 end on
3440 )NKSP_CODE",
3441 .expectBoolExitResult = true
3442 });
3443
3444 runScript({
3445 .code = R"NKSP_CODE(
3446 on init
3447 exit(5.1kHz <= 5100.0Hz)
3448 end on
3449 )NKSP_CODE",
3450 .expectBoolExitResult = true
3451 });
3452
3453 runScript({
3454 .code = R"NKSP_CODE(
3455 on init
3456 exit(5100.0Hz <= 5.1kHz)
3457 end on
3458 )NKSP_CODE",
3459 .expectBoolExitResult = true
3460 });
3461
3462 runScript({
3463 .code = R"NKSP_CODE(
3464 on init
3465 exit(1.0Hz <= 1.1)
3466 end on
3467 )NKSP_CODE",
3468 .expectParseError = true // units on both sides must match
3469 });
3470
3471 runScript({
3472 .code = R"NKSP_CODE(
3473 on init
3474 exit(1.2 <= 1.34mdB)
3475 end on
3476 )NKSP_CODE",
3477 .expectParseError = true // units on both sides must match
3478 });
3479
3480 runScript({
3481 .code = R"NKSP_CODE(
3482 on init
3483 exit(9.23us <= 3.14kHz)
3484 end on
3485 )NKSP_CODE",
3486 .expectParseError = true // units on both sides must match
3487 });
3488
3489 // 'final' ('!') operator tests ...
3490 // (should always yield in false for relation operators)
3491
3492 runScript({
3493 .code = R"NKSP_CODE(
3494 on init
3495 exit(!-4 <= !3)
3496 end on
3497 )NKSP_CODE",
3498 .expectBoolExitResult = true,
3499 .expectExitResultFinal = false
3500 });
3501
3502 runScript({
3503 .code = R"NKSP_CODE(
3504 on init
3505 exit(-4 <= 3)
3506 end on
3507 )NKSP_CODE",
3508 .expectBoolExitResult = true,
3509 .expectExitResultFinal = false
3510 });
3511
3512 #if !SILENT_TEST
3513 std::cout << std::endl;
3514 #endif
3515 }
3516
3517 static void testGreaterOrEqualOperator() {
3518 #if !SILENT_TEST
3519 std::cout << "UNIT TEST: greater-or-equal (>=) operator\n";
3520 #endif
3521
3522 // integer tests ...
3523
3524 runScript({
3525 .code = R"NKSP_CODE(
3526 on init
3527 exit(3 >= 3)
3528 end on
3529 )NKSP_CODE",
3530 .expectBoolExitResult = true
3531 });
3532
3533 runScript({
3534 .code = R"NKSP_CODE(
3535 on init
3536 exit(4 >= 4)
3537 end on
3538 )NKSP_CODE",
3539 .expectBoolExitResult = true
3540 });
3541
3542 runScript({
3543 .code = R"NKSP_CODE(
3544 on init
3545 exit(-23 >= -23)
3546 end on
3547 )NKSP_CODE",
3548 .expectBoolExitResult = true
3549 });
3550
3551 runScript({
3552 .code = R"NKSP_CODE(
3553 on init
3554 exit(23 >= -23)
3555 end on
3556 )NKSP_CODE",
3557 .expectBoolExitResult = true
3558 });
3559
3560 runScript({
3561 .code = R"NKSP_CODE(
3562 on init
3563 exit(3 >= 4)
3564 end on
3565 )NKSP_CODE",
3566 .expectBoolExitResult = false
3567 });
3568
3569 runScript({
3570 .code = R"NKSP_CODE(
3571 on init
3572 exit(4 >= 3)
3573 end on
3574 )NKSP_CODE",
3575 .expectBoolExitResult = true
3576 });
3577
3578 runScript({
3579 .code = R"NKSP_CODE(
3580 on init
3581 exit(-4 >= 3)
3582 end on
3583 )NKSP_CODE",
3584 .expectBoolExitResult = false
3585 });
3586
3587 runScript({
3588 .code = R"NKSP_CODE(
3589 on init
3590 exit(3 >= -4)
3591 end on
3592 )NKSP_CODE",
3593 .expectBoolExitResult = true
3594 });
3595
3596 runScript({
3597 .code = R"NKSP_CODE(
3598 on init
3599 exit(123 >= -45)
3600 end on
3601 )NKSP_CODE",
3602 .expectBoolExitResult = true
3603 });
3604
3605 runScript({
3606 .code = R"NKSP_CODE(
3607 on init
3608 exit(-45 >= 123)
3609 end on
3610 )NKSP_CODE",
3611 .expectBoolExitResult = false
3612 });
3613
3614 // real number tests ...
3615
3616 runScript({
3617 .code = R"NKSP_CODE(
3618 on init
3619 exit(3.0 >= 3.0)
3620 end on
3621 )NKSP_CODE",
3622 .expectBoolExitResult = true
3623 });
3624
3625 runScript({
3626 .code = R"NKSP_CODE(
3627 on init
3628 exit(3.1 >= 3.1)
3629 end on
3630 )NKSP_CODE",
3631 .expectBoolExitResult = true
3632 });
3633
3634 runScript({
3635 .code = R"NKSP_CODE(
3636 on init
3637 exit(3.1 >= 3.0)
3638 end on
3639 )NKSP_CODE",
3640 .expectBoolExitResult = true
3641 });
3642
3643 runScript({
3644 .code = R"NKSP_CODE(
3645 on init
3646 exit(3.0 >= 3.1)
3647 end on
3648 )NKSP_CODE",
3649 .expectBoolExitResult = false
3650 });
3651
3652 runScript({
3653 .code = R"NKSP_CODE(
3654 on init
3655 exit(-23.33 >= -23.33)
3656 end on
3657 )NKSP_CODE",
3658 .expectBoolExitResult = true
3659 });
3660
3661 runScript({
3662 .code = R"NKSP_CODE(
3663 on init
3664 exit(23.0 >= -23.0)
3665 end on
3666 )NKSP_CODE",
3667 .expectBoolExitResult = true
3668 });
3669
3670 runScript({
3671 .code = R"NKSP_CODE(
3672 on init
3673 exit(3.0 >= 4.0)
3674 end on
3675 )NKSP_CODE",
3676 .expectBoolExitResult = false
3677 });
3678
3679 runScript({
3680 .code = R"NKSP_CODE(
3681 on init
3682 exit(4.0 >= 3.0)
3683 end on
3684 )NKSP_CODE",
3685 .expectBoolExitResult = true
3686 });
3687
3688 runScript({
3689 .code = R"NKSP_CODE(
3690 on init
3691 exit(-4.0 >= 3.0)
3692 end on
3693 )NKSP_CODE",
3694 .expectBoolExitResult = false
3695 });
3696
3697 runScript({
3698 .code = R"NKSP_CODE(
3699 on init
3700 exit(3.0 >= -4.0)
3701 end on
3702 )NKSP_CODE",
3703 .expectBoolExitResult = true
3704 });
3705
3706 runScript({
3707 .code = R"NKSP_CODE(
3708 on init
3709 exit(123.0 >= -45.0)
3710 end on
3711 )NKSP_CODE",
3712 .expectBoolExitResult = true
3713 });
3714
3715 runScript({
3716 .code = R"NKSP_CODE(
3717 on init
3718 exit(-45.0 >= 123.0)
3719 end on
3720 )NKSP_CODE",
3721 .expectBoolExitResult = false
3722 });
3723
3724 // mixed type tests ...
3725
3726 runScript({
3727 .code = R"NKSP_CODE(
3728 on init
3729 exit(9 >= 9.1)
3730 end on
3731 )NKSP_CODE",
3732 .expectBoolExitResult = false
3733 });
3734
3735 runScript({
3736 .code = R"NKSP_CODE(
3737 on init
3738 exit(9.1 >= 9)
3739 end on
3740 )NKSP_CODE",
3741 .expectBoolExitResult = true
3742 });
3743
3744 runScript({
3745 .code = R"NKSP_CODE(
3746 on init
3747 exit(9 >= 9.0)
3748 end on
3749 )NKSP_CODE",
3750 .expectBoolExitResult = true
3751 });
3752
3753 runScript({
3754 .code = R"NKSP_CODE(
3755 on init
3756 exit(9.0 >= 9)
3757 end on
3758 )NKSP_CODE",
3759 .expectBoolExitResult = true
3760 });
3761
3762 // std unit tests ...
3763
3764 runScript({
3765 .code = R"NKSP_CODE(
3766 on init
3767 exit(13ms >= 14ms)
3768 end on
3769 )NKSP_CODE",
3770 .expectBoolExitResult = false
3771 });
3772
3773 runScript({
3774 .code = R"NKSP_CODE(
3775 on init
3776 exit(14ms >= 13ms)
3777 end on
3778 )NKSP_CODE",
3779 .expectBoolExitResult = true
3780 });
3781
3782 runScript({
3783 .code = R"NKSP_CODE(
3784 on init
3785 exit(1s >= 990ms)
3786 end on
3787 )NKSP_CODE",
3788 .expectBoolExitResult = true
3789 });
3790
3791 runScript({
3792 .code = R"NKSP_CODE(
3793 on init
3794 exit(990ms >= 1s)
3795 end on
3796 )NKSP_CODE",
3797 .expectBoolExitResult = false
3798 });
3799
3800 runScript({
3801 .code = R"NKSP_CODE(
3802 on init
3803 exit(1000ms >= 1s)
3804 end on
3805 )NKSP_CODE",
3806 .expectBoolExitResult = true
3807 });
3808
3809 runScript({
3810 .code = R"NKSP_CODE(
3811 on init
3812 exit(1s >= 1000ms)
3813 end on
3814 )NKSP_CODE",
3815 .expectBoolExitResult = true
3816 });
3817
3818 runScript({
3819 .code = R"NKSP_CODE(
3820 on init
3821 exit(1s >= 1)
3822 end on
3823 )NKSP_CODE",
3824 .expectParseError = true // units on both sides must match
3825 });
3826
3827 runScript({
3828 .code = R"NKSP_CODE(
3829 on init
3830 exit(1 >= 1s)
3831 end on
3832 )NKSP_CODE",
3833 .expectParseError = true // units on both sides must match
3834 });
3835
3836 runScript({
3837 .code = R"NKSP_CODE(
3838 on init
3839 exit(1Hz >= 1B)
3840 end on
3841 )NKSP_CODE",
3842 .expectParseError = true // units on both sides must match
3843 });
3844
3845 runScript({
3846 .code = R"NKSP_CODE(
3847 on init
3848 exit(13.0ms >= 13.1ms)
3849 end on
3850 )NKSP_CODE",
3851 .expectBoolExitResult = false
3852 });
3853
3854 runScript({
3855 .code = R"NKSP_CODE(
3856 on init
3857 exit(13.1ms >= 13.0ms)
3858 end on
3859 )NKSP_CODE",
3860 .expectBoolExitResult = true
3861 });
3862
3863 runScript({
3864 .code = R"NKSP_CODE(
3865 on init
3866 exit(0.9s >= 600.0ms)
3867 end on
3868 )NKSP_CODE",
3869 .expectBoolExitResult = true
3870 });
3871
3872 runScript({
3873 .code = R"NKSP_CODE(
3874 on init
3875 exit(600.0ms >= 0.9s)
3876 end on
3877 )NKSP_CODE",
3878 .expectBoolExitResult = false
3879 });
3880
3881 runScript({
3882 .code = R"NKSP_CODE(
3883 on init
3884 exit(5.1kHz >= 5100.0Hz)
3885 end on
3886 )NKSP_CODE",
3887 .expectBoolExitResult = true
3888 });
3889
3890 runScript({
3891 .code = R"NKSP_CODE(
3892 on init
3893 exit(5100.0Hz >= 5.1kHz)
3894 end on
3895 )NKSP_CODE",
3896 .expectBoolExitResult = true
3897 });
3898
3899 runScript({
3900 .code = R"NKSP_CODE(
3901 on init
3902 exit(1.0Hz >= 1.1)
3903 end on
3904 )NKSP_CODE",
3905 .expectParseError = true // units on both sides must match
3906 });
3907
3908 runScript({
3909 .code = R"NKSP_CODE(
3910 on init
3911 exit(1.2 >= 1.34mdB)
3912 end on
3913 )NKSP_CODE",
3914 .expectParseError = true // units on both sides must match
3915 });
3916
3917 runScript({
3918 .code = R"NKSP_CODE(
3919 on init
3920 exit(9.23us >= 3.14kHz)
3921 end on
3922 )NKSP_CODE",
3923 .expectParseError = true // units on both sides must match
3924 });
3925
3926 // 'final' ('!') operator tests ...
3927 // (should always yield in false for relation operators)
3928
3929 runScript({
3930 .code = R"NKSP_CODE(
3931 on init
3932 exit(!-4 >= !3)
3933 end on
3934 )NKSP_CODE",
3935 .expectBoolExitResult = false,
3936 .expectExitResultFinal = false
3937 });
3938
3939 runScript({
3940 .code = R"NKSP_CODE(
3941 on init
3942 exit(-4 >= 3)
3943 end on
3944 )NKSP_CODE",
3945 .expectBoolExitResult = false,
3946 .expectExitResultFinal = false
3947 });
3948
3949 #if !SILENT_TEST
3950 std::cout << std::endl;
3951 #endif
3952 }
3953
3954 static void testEqualOperator() {
3955 #if !SILENT_TEST
3956 std::cout << "UNIT TEST: equal (=) operator\n";
3957 #endif
3958
3959 // integer tests ...
3960
3961 runScript({
3962 .code = R"NKSP_CODE(
3963 on init
3964 exit(3 = 3)
3965 end on
3966 )NKSP_CODE",
3967 .expectBoolExitResult = true
3968 });
3969
3970 runScript({
3971 .code = R"NKSP_CODE(
3972 on init
3973 exit(4 = 4)
3974 end on
3975 )NKSP_CODE",
3976 .expectBoolExitResult = true
3977 });
3978
3979 runScript({
3980 .code = R"NKSP_CODE(
3981 on init
3982 exit(3 = 4)
3983 end on
3984 )NKSP_CODE",
3985 .expectBoolExitResult = false
3986 });
3987
3988 runScript({
3989 .code = R"NKSP_CODE(
3990 on init
3991 exit(23 = -23)
3992 end on
3993 )NKSP_CODE",
3994 .expectBoolExitResult = false
3995 });
3996
3997 // real number tests ...
3998
3999 runScript({
4000 .code = R"NKSP_CODE(
4001 on init
4002 exit(3.0 = 3.0)
4003 end on
4004 )NKSP_CODE",
4005 .expectBoolExitResult = true
4006 });
4007
4008 runScript({
4009 .code = R"NKSP_CODE(
4010 on init
4011 exit(4.33 = 4.33)
4012 end on
4013 )NKSP_CODE",
4014 .expectBoolExitResult = true
4015 });
4016
4017 runScript({
4018 .code = R"NKSP_CODE(
4019 on init
4020 exit(4.31 = 4.35)
4021 end on
4022 )NKSP_CODE",
4023 .expectBoolExitResult = false
4024 });
4025
4026 runScript({
4027 .code = R"NKSP_CODE(
4028 on init
4029 exit(3.0 = 4.0)
4030 end on
4031 )NKSP_CODE",
4032 .expectBoolExitResult = false
4033 });
4034
4035 runScript({
4036 .code = R"NKSP_CODE(
4037 on init
4038 exit(23.0 = -23.0)
4039 end on
4040 )NKSP_CODE",
4041 .expectBoolExitResult = false
4042 });
4043
4044 // deal with inaccuracy of float point
4045 runScript({
4046 .code = R"NKSP_CODE(
4047 on init
4048 declare ~a := 0.165
4049 declare ~b := 0.185
4050 declare ~x := 0.1
4051 declare ~y := 0.25
4052 exit(~a + ~b = ~x + ~y) { both sides should actually be 0.35, they slightly deviate both though }
4053 end on
4054 )NKSP_CODE",
4055 .expectBoolExitResult = true // our implementation of real number equal comparison should take care about floating point tolerance
4056 });
4057
4058 // deal with inaccuracy of float point
4059 runScript({
4060 .code = R"NKSP_CODE(
4061 on init
4062 declare ~a := 0.166
4063 declare ~b := 0.185
4064 declare ~x := 0.1
4065 declare ~y := 0.25
4066 exit(~a + ~b = ~x + ~y) { left side approx. 0.351, right side approx. 0.35 }
4067 end on
4068 )NKSP_CODE",
4069 .expectBoolExitResult = false
4070 });
4071
4072 // mixed type tests ...
4073
4074 runScript({
4075 .code = R"NKSP_CODE(
4076 on init
4077 exit(23 = 23.0)
4078 end on
4079 )NKSP_CODE",
4080 .expectBoolExitResult = true
4081 });
4082
4083 runScript({
4084 .code = R"NKSP_CODE(
4085 on init
4086 exit(23.0 = 23)
4087 end on
4088 )NKSP_CODE",
4089 .expectBoolExitResult = true
4090 });
4091
4092 runScript({
4093 .code = R"NKSP_CODE(
4094 on init
4095 exit(23 = 23.1)
4096 end on
4097 )NKSP_CODE",
4098 .expectBoolExitResult = false
4099 });
4100
4101 runScript({
4102 .code = R"NKSP_CODE(
4103 on init
4104 exit(23.1 = 23)
4105 end on
4106 )NKSP_CODE",
4107 .expectBoolExitResult = false
4108 });
4109
4110 // std unit tests ...
4111
4112 runScript({
4113 .code = R"NKSP_CODE(
4114 on init
4115 exit(13ms = 14ms)
4116 end on
4117 )NKSP_CODE",
4118 .expectBoolExitResult = false
4119 });
4120
4121 runScript({
4122 .code = R"NKSP_CODE(
4123 on init
4124 exit(14ms = 13ms)
4125 end on
4126 )NKSP_CODE",
4127 .expectBoolExitResult = false
4128 });
4129
4130 runScript({
4131 .code = R"NKSP_CODE(
4132 on init
4133 exit(1s = 1ms)
4134 end on
4135 )NKSP_CODE",
4136 .expectBoolExitResult = false
4137 });
4138
4139 runScript({
4140 .code = R"NKSP_CODE(
4141 on init
4142 exit(1ms = 1s)
4143 end on
4144 )NKSP_CODE",
4145 .expectBoolExitResult = false
4146 });
4147
4148 runScript({
4149 .code = R"NKSP_CODE(
4150 on init
4151 exit(3.14kHz = 3140Hz)
4152 end on
4153 )NKSP_CODE",
4154 .expectBoolExitResult = true
4155 });
4156
4157 runScript({
4158 .code = R"NKSP_CODE(
4159 on init
4160 exit(3140Hz = 3.14kHz)
4161 end on
4162 )NKSP_CODE",
4163 .expectBoolExitResult = true
4164 });
4165
4166 runScript({
4167 .code = R"NKSP_CODE(
4168 on init
4169 exit(1s = 1)
4170 end on
4171 )NKSP_CODE",
4172 .expectParseError = true // units on both sides must match
4173 });
4174
4175 runScript({
4176 .code = R"NKSP_CODE(
4177 on init
4178 exit(1 = 1s)
4179 end on
4180 )NKSP_CODE",
4181 .expectParseError = true // units on both sides must match
4182 });
4183
4184 runScript({
4185 .code = R"NKSP_CODE(
4186 on init
4187 exit(1Hz = 1B)
4188 end on
4189 )NKSP_CODE",
4190 .expectParseError = true // units on both sides must match
4191 });
4192
4193 // 'final' ('!') operator tests ...
4194 // (should always yield in false for relation operators)
4195
4196 runScript({
4197 .code = R"NKSP_CODE(
4198 on init
4199 exit(!-4 = !3)
4200 end on
4201 )NKSP_CODE",
4202 .expectBoolExitResult = false,
4203 .expectExitResultFinal = false
4204 });
4205
4206 runScript({
4207 .code = R"NKSP_CODE(
4208 on init
4209 exit(-4 = 3)
4210 end on
4211 )NKSP_CODE",
4212 .expectBoolExitResult = false,
4213 .expectExitResultFinal = false
4214 });
4215
4216 #if !SILENT_TEST
4217 std::cout << std::endl;
4218 #endif
4219 }
4220
4221 static void testUnequalOperator() {
4222 #if !SILENT_TEST
4223 std::cout << "UNIT TEST: unequal (#) operator\n";
4224 #endif
4225
4226 // integer tests ...
4227
4228 runScript({
4229 .code = R"NKSP_CODE(
4230 on init
4231 exit(3 # 3)
4232 end on
4233 )NKSP_CODE",
4234 .expectBoolExitResult = false
4235 });
4236
4237 runScript({
4238 .code = R"NKSP_CODE(
4239 on init
4240 exit(4 # 4)
4241 end on
4242 )NKSP_CODE",
4243 .expectBoolExitResult = false
4244 });
4245
4246 runScript({
4247 .code = R"NKSP_CODE(
4248 on init
4249 exit(3 # 4)
4250 end on
4251 )NKSP_CODE",
4252 .expectBoolExitResult = true
4253 });
4254
4255 runScript({
4256 .code = R"NKSP_CODE(
4257 on init
4258 exit(23 # -23)
4259 end on
4260 )NKSP_CODE",
4261 .expectBoolExitResult = true
4262 });
4263
4264 // real number tests ...
4265
4266 runScript({
4267 .code = R"NKSP_CODE(
4268 on init
4269 exit(3.0 # 3.0)
4270 end on
4271 )NKSP_CODE",
4272 .expectBoolExitResult = false
4273 });
4274
4275 runScript({
4276 .code = R"NKSP_CODE(
4277 on init
4278 exit(3.14 # 3.14)
4279 end on
4280 )NKSP_CODE",
4281 .expectBoolExitResult = false
4282 });
4283
4284 runScript({
4285 .code = R"NKSP_CODE(
4286 on init
4287 exit(3.19 # 3.12)
4288 end on
4289 )NKSP_CODE",
4290 .expectBoolExitResult = true
4291 });
4292
4293 runScript({
4294 .code = R"NKSP_CODE(
4295 on init
4296 exit(23.0 # -23.0)
4297 end on
4298 )NKSP_CODE",
4299 .expectBoolExitResult = true
4300 });
4301
4302 // deal with inaccuracy of float point
4303 runScript({
4304 .code = R"NKSP_CODE(
4305 on init
4306 declare ~a := 0.165
4307 declare ~b := 0.185
4308 declare ~x := 0.1
4309 declare ~y := 0.25
4310 exit(~a + ~b # ~x + ~y) { both sides should actually be 0.35, they slightly deviate both though }
4311 end on
4312 )NKSP_CODE",
4313 .expectBoolExitResult = false // our implementation of real number unequal comparison should take care about floating point tolerance
4314 });
4315
4316 // deal with inaccuracy of float point
4317 runScript({
4318 .code = R"NKSP_CODE(
4319 on init
4320 declare ~a := 0.166
4321 declare ~b := 0.185
4322 declare ~x := 0.1
4323 declare ~y := 0.25
4324 exit(~a + ~b # ~x + ~y) { left side approx. 0.351, right side approx. 0.35 }
4325 end on
4326 )NKSP_CODE",
4327 .expectBoolExitResult = true
4328 });
4329
4330 // mixed type tests ...
4331
4332 runScript({
4333 .code = R"NKSP_CODE(
4334 on init
4335 exit(3 # 3.0)
4336 end on
4337 )NKSP_CODE",
4338 .expectBoolExitResult = false
4339 });
4340
4341 runScript({
4342 .code = R"NKSP_CODE(
4343 on init
4344 exit(3.0 # 3)
4345 end on
4346 )NKSP_CODE",
4347 .expectBoolExitResult = false
4348 });
4349
4350 runScript({
4351 .code = R"NKSP_CODE(
4352 on init
4353 exit(3.1 # 3)
4354 end on
4355 )NKSP_CODE",
4356 .expectBoolExitResult = true
4357 });
4358
4359 runScript({
4360 .code = R"NKSP_CODE(
4361 on init
4362 exit(3 # 3.1)
4363 end on
4364 )NKSP_CODE",
4365 .expectBoolExitResult = true
4366 });
4367
4368 // std unit tests ...
4369
4370 runScript({
4371 .code = R"NKSP_CODE(
4372 on init
4373 exit(13ms # 14ms)
4374 end on
4375 )NKSP_CODE",
4376 .expectBoolExitResult = true
4377 });
4378
4379 runScript({
4380 .code = R"NKSP_CODE(
4381 on init
4382 exit(14ms # 13ms)
4383 end on
4384 )NKSP_CODE",
4385 .expectBoolExitResult = true
4386 });
4387
4388 runScript({
4389 .code = R"NKSP_CODE(
4390 on init
4391 exit(1s # 1ms)
4392 end on
4393 )NKSP_CODE",
4394 .expectBoolExitResult = true
4395 });
4396
4397 runScript({
4398 .code = R"NKSP_CODE(
4399 on init
4400 exit(1ms # 1s)
4401 end on
4402 )NKSP_CODE",
4403 .expectBoolExitResult = true
4404 });
4405
4406 runScript({
4407 .code = R"NKSP_CODE(
4408 on init
4409 exit(3.14kHz # 3140Hz)
4410 end on
4411 )NKSP_CODE",
4412 .expectBoolExitResult = false
4413 });
4414
4415 runScript({
4416 .code = R"NKSP_CODE(
4417 on init
4418 exit(3140Hz # 3.14kHz)
4419 end on
4420 )NKSP_CODE",
4421 .expectBoolExitResult = false
4422 });
4423
4424 runScript({
4425 .code = R"NKSP_CODE(
4426 on init
4427 exit(1s # 1)
4428 end on
4429 )NKSP_CODE",
4430 .expectParseError = true // units on both sides must match
4431 });
4432
4433 runScript({
4434 .code = R"NKSP_CODE(
4435 on init
4436 exit(1 # 1s)
4437 end on
4438 )NKSP_CODE",
4439 .expectParseError = true // units on both sides must match
4440 });
4441
4442 runScript({
4443 .code = R"NKSP_CODE(
4444 on init
4445 exit(1Hz # 1B)
4446 end on
4447 )NKSP_CODE",
4448 .expectParseError = true // units on both sides must match
4449 });
4450
4451 // 'final' ('!') operator tests ...
4452 // (should always yield in false for relation operators)
4453
4454 runScript({
4455 .code = R"NKSP_CODE(
4456 on init
4457 exit(!-4 # !3)
4458 end on
4459 )NKSP_CODE",
4460 .expectBoolExitResult = true,
4461 .expectExitResultFinal = false
4462 });
4463
4464 runScript({
4465 .code = R"NKSP_CODE(
4466 on init
4467 exit(-4 # 3)
4468 end on
4469 )NKSP_CODE",
4470 .expectBoolExitResult = true,
4471 .expectExitResultFinal = false
4472 });
4473
4474 #if !SILENT_TEST
4475 std::cout << std::endl;
4476 #endif
4477 }
4478
4479 static void testLogicalAndOperator() {
4480 #if !SILENT_TEST
4481 std::cout << "UNIT TEST: logical and (and) operator\n";
4482 #endif
4483
4484 // integer tests ...
4485
4486 runScript({
4487 .code = R"NKSP_CODE(
4488 on init
4489 exit(1 and 1)
4490 end on
4491 )NKSP_CODE",
4492 .expectBoolExitResult = true
4493 });
4494
4495 runScript({
4496 .code = R"NKSP_CODE(
4497 on init
4498 exit(1 and 2)
4499 end on
4500 )NKSP_CODE",
4501 .expectBoolExitResult = true
4502 });
4503
4504 runScript({
4505 .code = R"NKSP_CODE(
4506 on init
4507 exit(1 and 3)
4508 end on
4509 )NKSP_CODE",
4510 .expectBoolExitResult = true
4511 });
4512
4513 runScript({
4514 .code = R"NKSP_CODE(
4515 on init
4516 exit(1 and 0)
4517 end on
4518 )NKSP_CODE",
4519 .expectBoolExitResult = false
4520 });
4521
4522 runScript({
4523 .code = R"NKSP_CODE(
4524 on init
4525 exit(0 and 1)
4526 end on
4527 )NKSP_CODE",
4528 .expectBoolExitResult = false
4529 });
4530
4531 runScript({
4532 .code = R"NKSP_CODE(
4533 on init
4534 exit(0 and 0)
4535 end on
4536 )NKSP_CODE",
4537 .expectBoolExitResult = false
4538 });
4539
4540 // real number tests ...
4541 // (not allowed for this operator)
4542
4543 runScript({
4544 .code = R"NKSP_CODE(
4545 on init
4546 exit(1.0 and 1.0)
4547 end on
4548 )NKSP_CODE",
4549 .expectParseError = true // real numbers not allowed for this operator
4550 });
4551
4552 // mixed type tests ...
4553 // (not allowed for this operator)
4554
4555 runScript({
4556 .code = R"NKSP_CODE(
4557 on init
4558 exit(1.0 and 1)
4559 end on
4560 )NKSP_CODE",
4561 .expectParseError = true // real numbers not allowed for this operator
4562 });
4563
4564 runScript({
4565 .code = R"NKSP_CODE(
4566 on init
4567 exit(1 and 1.0)
4568 end on
4569 )NKSP_CODE",
4570 .expectParseError = true // real numbers not allowed for this operator
4571 });
4572
4573 // std unit tests ...
4574 // (not allowed for this operator)
4575
4576 runScript({
4577 .code = R"NKSP_CODE(
4578 on init
4579 exit(1s and 0)
4580 end on
4581 )NKSP_CODE",
4582 .expectParseError = true // std units not allowed for this operator
4583 });
4584
4585 runScript({
4586 .code = R"NKSP_CODE(
4587 on init
4588 exit(0 and 1s)
4589 end on
4590 )NKSP_CODE",
4591 .expectParseError = true // std units not allowed for this operator
4592 });
4593
4594 // 'final' ('!') operator tests ...
4595
4596 runScript({
4597 .code = R"NKSP_CODE(
4598 on init
4599 exit(!0 and !0)
4600 end on
4601 )NKSP_CODE",
4602 .expectExitResultFinal = true
4603 });
4604
4605 runScript({
4606 .code = R"NKSP_CODE(
4607 on init
4608 exit(0 and 0)
4609 end on
4610 )NKSP_CODE",
4611 .expectExitResultFinal = false
4612 });
4613
4614 #if !SILENT_TEST
4615 std::cout << std::endl;
4616 #endif
4617 }
4618
4619 static void testLogicalOrOperator() {
4620 #if !SILENT_TEST
4621 std::cout << "UNIT TEST: logical or (or) operator\n";
4622 #endif
4623
4624 // integer tests ...
4625
4626 runScript({
4627 .code = R"NKSP_CODE(
4628 on init
4629 exit(1 or 1)
4630 end on
4631 )NKSP_CODE",
4632 .expectBoolExitResult = true
4633 });
4634
4635 runScript({
4636 .code = R"NKSP_CODE(
4637 on init
4638 exit(1 or 2)
4639 end on
4640 )NKSP_CODE",
4641 .expectBoolExitResult = true
4642 });
4643
4644 runScript({
4645 .code = R"NKSP_CODE(
4646 on init
4647 exit(1 or 3)
4648 end on
4649 )NKSP_CODE",
4650 .expectBoolExitResult = true
4651 });
4652
4653 runScript({
4654 .code = R"NKSP_CODE(
4655 on init
4656 exit(1 or 0)
4657 end on
4658 )NKSP_CODE",
4659 .expectBoolExitResult = true
4660 });
4661
4662 runScript({
4663 .code = R"NKSP_CODE(
4664 on init
4665 exit(0 or 1)
4666 end on
4667 )NKSP_CODE",
4668 .expectBoolExitResult = true
4669 });
4670
4671 runScript({
4672 .code = R"NKSP_CODE(
4673 on init
4674 exit(0 or 0)
4675 end on
4676 )NKSP_CODE",
4677 .expectBoolExitResult = false
4678 });
4679
4680 // real number tests ...
4681 // (not allowed for this operator)
4682
4683 runScript({
4684 .code = R"NKSP_CODE(
4685 on init
4686 exit(1.0 or 1.0)
4687 end on
4688 )NKSP_CODE",
4689 .expectParseError = true // real numbers not allowed for this operator
4690 });
4691
4692 // mixed type tests ...
4693 // (not allowed for this operator)
4694
4695 runScript({
4696 .code = R"NKSP_CODE(
4697 on init
4698 exit(1.0 or 1)
4699 end on
4700 )NKSP_CODE",
4701 .expectParseError = true // real numbers not allowed for this operator
4702 });
4703
4704 runScript({
4705 .code = R"NKSP_CODE(
4706 on init
4707 exit(1 or 1.0)
4708 end on
4709 )NKSP_CODE",
4710 .expectParseError = true // real numbers not allowed for this operator
4711 });
4712
4713 // std unit tests ...
4714 // (not allowed for this operator)
4715
4716 runScript({
4717 .code = R"NKSP_CODE(
4718 on init
4719 exit(1s or 0)
4720 end on
4721 )NKSP_CODE",
4722 .expectParseError = true // std units not allowed for this operator
4723 });
4724
4725 runScript({
4726 .code = R"NKSP_CODE(
4727 on init
4728 exit(0 or 1s)
4729 end on
4730 )NKSP_CODE",
4731 .expectParseError = true // std units not allowed for this operator
4732 });
4733
4734 // 'final' ('!') operator tests ...
4735
4736 runScript({
4737 .code = R"NKSP_CODE(
4738 on init
4739 exit(!0 or !0)
4740 end on
4741 )NKSP_CODE",
4742 .expectExitResultFinal = true
4743 });
4744
4745 runScript({
4746 .code = R"NKSP_CODE(
4747 on init
4748 exit(0 or 0)
4749 end on
4750 )NKSP_CODE",
4751 .expectExitResultFinal = false
4752 });
4753
4754 #if !SILENT_TEST
4755 std::cout << std::endl;
4756 #endif
4757 }
4758
4759 static void testLogicalNotOperator() {
4760 #if !SILENT_TEST
4761 std::cout << "UNIT TEST: logical not (not) operator\n";
4762 #endif
4763
4764 // integer tests ...
4765
4766 runScript({
4767 .code = R"NKSP_CODE(
4768 on init
4769 exit(not 1)
4770 end on
4771 )NKSP_CODE",
4772 .expectBoolExitResult = false
4773 });
4774
4775 runScript({
4776 .code = R"NKSP_CODE(
4777 on init
4778 exit(not 2)
4779 end on
4780 )NKSP_CODE",
4781 .expectBoolExitResult = false
4782 });
4783
4784 runScript({
4785 .code = R"NKSP_CODE(
4786 on init
4787 exit(not 0)
4788 end on
4789 )NKSP_CODE",
4790 .expectBoolExitResult = true
4791 });
4792
4793 // real number tests ...
4794 // (not allowed for this operator)
4795
4796 runScript({
4797 .code = R"NKSP_CODE(
4798 on init
4799 exit(not 1.0)
4800 end on
4801 )NKSP_CODE",
4802 .expectParseError = true // real numbers not allowed for this operator
4803 });
4804
4805 // std unit tests ...
4806 // (not allowed for this operator)
4807
4808 runScript({
4809 .code = R"NKSP_CODE(
4810 on init
4811 exit(not 1s)
4812 end on
4813 )NKSP_CODE",
4814 .expectParseError = true // std units not allowed for this operator
4815 });
4816
4817 // 'final' ('!') operator tests ...
4818
4819 runScript({
4820 .code = R"NKSP_CODE(
4821 on init
4822 exit(not !1)
4823 end on
4824 )NKSP_CODE",
4825 .expectExitResultFinal = true
4826 });
4827
4828 runScript({
4829 .code = R"NKSP_CODE(
4830 on init
4831 exit(not 1)
4832 end on
4833 )NKSP_CODE",
4834 .expectExitResultFinal = false
4835 });
4836
4837 #if !SILENT_TEST
4838 std::cout << std::endl;
4839 #endif
4840 }
4841
4842 static void testBitwiseAndOperator() {
4843 #if !SILENT_TEST
4844 std::cout << "UNIT TEST: bitwise and (.and.) operator\n";
4845 #endif
4846
4847 // integer tests ...
4848
4849 runScript({
4850 .code = R"NKSP_CODE(
4851 on init
4852 exit(1 .and. 1)
4853 end on
4854 )NKSP_CODE",
4855 .expectIntExitResult = 1
4856 });
4857
4858 runScript({
4859 .code = R"NKSP_CODE(
4860 on init
4861 exit(43 .and. 142)
4862 end on
4863 )NKSP_CODE",
4864 .expectIntExitResult = 10
4865 });
4866
4867 // real number tests ...
4868 // (not allowed for this operator)
4869
4870 runScript({
4871 .code = R"NKSP_CODE(
4872 on init
4873 exit(1.0 .and. 1.0)
4874 end on
4875 )NKSP_CODE",
4876 .expectParseError = true // real numbers not allowed for this operator
4877 });
4878
4879 // mixed type tests ...
4880 // (not allowed for this operator)
4881
4882 runScript({
4883 .code = R"NKSP_CODE(
4884 on init
4885 exit(1.0 .and. 1)
4886 end on
4887 )NKSP_CODE",
4888 .expectParseError = true // real numbers not allowed for this operator
4889 });
4890
4891 runScript({
4892 .code = R"NKSP_CODE(
4893 on init
4894 exit(1 .and. 1.0)
4895 end on
4896 )NKSP_CODE",
4897 .expectParseError = true // real numbers not allowed for this operator
4898 });
4899
4900 // std unit tests ...
4901 // (not allowed for this operator)
4902
4903 runScript({
4904 .code = R"NKSP_CODE(
4905 on init
4906 exit(1s .and. 1)
4907 end on
4908 )NKSP_CODE",
4909 .expectParseError = true // std units not allowed for this operator
4910 });
4911
4912 runScript({
4913 .code = R"NKSP_CODE(
4914 on init
4915 exit(1 .and. 1s)
4916 end on
4917 )NKSP_CODE",
4918 .expectParseError = true // std units not allowed for this operator
4919 });
4920
4921 // 'final' ('!') operator tests ...
4922
4923 runScript({
4924 .code = R"NKSP_CODE(
4925 on init
4926 exit(!43 .and. !142)
4927 end on
4928 )NKSP_CODE",
4929 .expectIntExitResult = 10,
4930 .expectExitResultFinal = true
4931 });
4932
4933 runScript({
4934 .code = R"NKSP_CODE(
4935 on init
4936 exit(43 .and. 142)
4937 end on
4938 )NKSP_CODE",
4939 .expectIntExitResult = 10,
4940 .expectExitResultFinal = false
4941 });
4942
4943 #if !SILENT_TEST
4944 std::cout << std::endl;
4945 #endif
4946 }
4947
4948 static void testBitwiseOrOperator() {
4949 #if !SILENT_TEST
4950 std::cout << "UNIT TEST: bitwise or (.or.) operator\n";
4951 #endif
4952
4953 // integer tests ...
4954
4955 runScript({
4956 .code = R"NKSP_CODE(
4957 on init
4958 exit(1 .or. 1)
4959 end on
4960 )NKSP_CODE",
4961 .expectIntExitResult = 1
4962 });
4963
4964 runScript({
4965 .code = R"NKSP_CODE(
4966 on init
4967 exit(0 .or. 0)
4968 end on
4969 )NKSP_CODE",
4970 .expectIntExitResult = 0
4971 });
4972
4973 runScript({
4974 .code = R"NKSP_CODE(
4975 on init
4976 exit(43 .or. 142)
4977 end on
4978 )NKSP_CODE",
4979 .expectIntExitResult = 175
4980 });
4981
4982 // real number tests ...
4983 // (not allowed for this operator)
4984
4985 runScript({
4986 .code = R"NKSP_CODE(
4987 on init
4988 exit(1.0 .or. 1.0)
4989 end on
4990 )NKSP_CODE",
4991 .expectParseError = true // real numbers not allowed for this operator
4992 });
4993
4994 // mixed type tests ...
4995 // (not allowed for this operator)
4996
4997 runScript({
4998 .code = R"NKSP_CODE(
4999 on init
5000 exit(1.0 .or. 1)
5001 end on
5002 )NKSP_CODE",
5003 .expectParseError = true // real numbers not allowed for this operator
5004 });
5005
5006 runScript({
5007 .code = R"NKSP_CODE(
5008 on init
5009 exit(1 .or. 1.0)
5010 end on
5011 )NKSP_CODE",
5012 .expectParseError = true // real numbers not allowed for this operator
5013 });
5014
5015 // std unit tests ...
5016 // (not allowed for this operator)
5017
5018 runScript({
5019 .code = R"NKSP_CODE(
5020 on init
5021 exit(1s .or. 1)
5022 end on
5023 )NKSP_CODE",
5024 .expectParseError = true // std units not allowed for this operator
5025 });
5026
5027 runScript({
5028 .code = R"NKSP_CODE(
5029 on init
5030 exit(1 .or. 1s)
5031 end on
5032 )NKSP_CODE",
5033 .expectParseError = true // std units not allowed for this operator
5034 });
5035
5036 // 'final' ('!') operator tests ...
5037
5038 runScript({
5039 .code = R"NKSP_CODE(
5040 on init
5041 exit(!43 .or. !142)
5042 end on
5043 )NKSP_CODE",
5044 .expectIntExitResult = 175,
5045 .expectExitResultFinal = true
5046 });
5047
5048 runScript({
5049 .code = R"NKSP_CODE(
5050 on init
5051 exit(43 .or. 142)
5052 end on
5053 )NKSP_CODE",
5054 .expectIntExitResult = 175,
5055 .expectExitResultFinal = false
5056 });
5057
5058 #if !SILENT_TEST
5059 std::cout << std::endl;
5060 #endif
5061 }
5062
5063 static void testBitwiseNotOperator() {
5064 #if !SILENT_TEST
5065 std::cout << "UNIT TEST: bitwise not (.not.) operator\n";
5066 #endif
5067
5068 // integer tests ...
5069
5070 runScript({
5071 .code = R"NKSP_CODE(
5072 on init
5073 exit(.not. -1)
5074 end on
5075 )NKSP_CODE",
5076 .expectIntExitResult = 0
5077 });
5078
5079 runScript({
5080 .code = R"NKSP_CODE(
5081 on init
5082 exit(.not. 0)
5083 end on
5084 )NKSP_CODE",
5085 .expectIntExitResult = -1
5086 });
5087
5088 runScript({
5089 .code = R"NKSP_CODE(
5090 on init
5091 exit(.not. 3)
5092 end on
5093 )NKSP_CODE",
5094 .expectIntExitResult = ssize_t(size_t(-1) << 2)
5095 });
5096
5097 // real number tests ...
5098 // (not allowed for this operator)
5099
5100 runScript({
5101 .code = R"NKSP_CODE(
5102 on init
5103 exit(.not. 1.0)
5104 end on
5105 )NKSP_CODE",
5106 .expectParseError = true // real numbers not allowed for this operator
5107 });
5108
5109 runScript({
5110 .code = R"NKSP_CODE(
5111 on init
5112 exit(.not. -1.0)
5113 end on
5114 )NKSP_CODE",
5115 .expectParseError = true // real numbers not allowed for this operator
5116 });
5117
5118 // std unit tests ...
5119 // (not allowed for this operator)
5120
5121 runScript({
5122 .code = R"NKSP_CODE(
5123 on init
5124 exit(.not. 1s)
5125 end on
5126 )NKSP_CODE",
5127 .expectParseError = true // std units not allowed for this operator
5128 });
5129
5130 // 'final' ('!') operator tests ...
5131
5132 runScript({
5133 .code = R"NKSP_CODE(
5134 on init
5135 exit(.not. !0)
5136 end on
5137 )NKSP_CODE",
5138 .expectIntExitResult = -1,
5139 .expectExitResultFinal = true
5140 });
5141
5142 runScript({
5143 .code = R"NKSP_CODE(
5144 on init
5145 exit(.not. 0)
5146 end on
5147 )NKSP_CODE",
5148 .expectIntExitResult = -1,
5149 .expectExitResultFinal = false
5150 });
5151
5152 #if !SILENT_TEST
5153 std::cout << std::endl;
5154 #endif
5155 }
5156
5157 static void testPrecedenceOfOperators() {
5158 #if !SILENT_TEST
5159 std::cout << "UNIT TEST: precedence of operators\n";
5160 #endif
5161
5162 // integer tests ...
5163
5164 runScript({
5165 .code = R"NKSP_CODE(
5166 on init
5167 exit(3 + 4 * 2)
5168 end on
5169 )NKSP_CODE",
5170 .expectIntExitResult = 11
5171 });
5172
5173 runScript({
5174 .code = R"NKSP_CODE(
5175 on init
5176 exit(4 * 2 + 3)
5177 end on
5178 )NKSP_CODE",
5179 .expectIntExitResult = 11
5180 });
5181
5182 runScript({
5183 .code = R"NKSP_CODE(
5184 on init
5185 exit((3 + 4) * 2)
5186 end on
5187 )NKSP_CODE",
5188 .expectIntExitResult = 14
5189 });
5190
5191 runScript({
5192 .code = R"NKSP_CODE(
5193 on init
5194 exit(4 * (2 + 3))
5195 end on
5196 )NKSP_CODE",
5197 .expectIntExitResult = 20
5198 });
5199
5200 // real number tests ...
5201
5202 runScript({
5203 .code = R"NKSP_CODE(
5204 on init
5205 exit(3.2 + 4.0 * 2.0)
5206 end on
5207 )NKSP_CODE",
5208 .expectRealExitResult = 11.2
5209 });
5210
5211 runScript({
5212 .code = R"NKSP_CODE(
5213 on init
5214 exit(4.0 * 2.0 + 3.2)
5215 end on
5216 )NKSP_CODE",
5217 .expectRealExitResult = 11.2
5218 });
5219
5220 runScript({
5221 .code = R"NKSP_CODE(
5222 on init
5223 exit((3.2 + 4.0) * 2.0)
5224 end on
5225 )NKSP_CODE",
5226 .expectRealExitResult = 14.4
5227 });
5228
5229 runScript({
5230 .code = R"NKSP_CODE(
5231 on init
5232 exit(4.0 * (2.0 + 3.2))
5233 end on
5234 )NKSP_CODE",
5235 .expectRealExitResult = 20.8
5236 });
5237
5238 // std unit tests ...
5239
5240 runScript({
5241 .code = R"NKSP_CODE(
5242 on init
5243 exit(4 * (2us + 3us) + 7ms)
5244 end on
5245 )NKSP_CODE",
5246 .expectIntExitResult = 7020,
5247 .expectExitResultUnitPrefix = { VM_MICRO },
5248 .expectExitResultUnit = VM_SECOND
5249 });
5250
5251 runScript({
5252 .code = R"NKSP_CODE(
5253 on init
5254 declare $a := 4
5255 declare $c := 3us
5256 exit($a * (2us + $c) + 7ms)
5257 end on
5258 )NKSP_CODE",
5259 .expectIntExitResult = 7020,
5260 .expectExitResultUnitPrefix = { VM_MICRO },
5261 .expectExitResultUnit = VM_SECOND
5262 });
5263
5264 runScript({
5265 .code = R"NKSP_CODE(
5266 on init
5267 declare $a := 4
5268 declare $b := 2us
5269 declare $c := 3us
5270 exit($a * ($b + $c) + 7ms)
5271 end on
5272 )NKSP_CODE",
5273 .expectIntExitResult = 7020,
5274 .expectExitResultUnitPrefix = { VM_MICRO },
5275 .expectExitResultUnit = VM_SECOND
5276 });
5277
5278 runScript({
5279 .code = R"NKSP_CODE(
5280 on init
5281 declare $a := 4
5282 declare $b := 2us
5283 declare $c := 3us
5284 declare $d := 7ms
5285 exit($a * ($b + $c) + 7ms)
5286 end on
5287 )NKSP_CODE",
5288 .expectIntExitResult = 7020,
5289 .expectExitResultUnitPrefix = { VM_MICRO },
5290 .expectExitResultUnit = VM_SECOND
5291 });
5292
5293 runScript({
5294 .code = R"NKSP_CODE(
5295 on init
5296 declare $c := 3us
5297 declare $a := 4
5298 declare $d := 7ms
5299 declare $b := 2us
5300 exit($a * ($b + $c) + 7ms)
5301 end on
5302 )NKSP_CODE",
5303 .expectIntExitResult = 7020,
5304 .expectExitResultUnitPrefix = { VM_MICRO },
5305 .expectExitResultUnit = VM_SECOND
5306 });
5307
5308 runScript({
5309 .code = R"NKSP_CODE(
5310 on init
5311 exit(4.0 * (2.0mdB + 3.2mdB) / 2.0)
5312 end on
5313 )NKSP_CODE",
5314 .expectRealExitResult = 10.4,
5315 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5316 .expectExitResultUnit = VM_BEL
5317 });
5318
5319 runScript({
5320 .code = R"NKSP_CODE(
5321 on init
5322 declare ~a := 2.0mdB
5323 declare ~b := 3.2mdB
5324 exit(4.0 * (~a + ~b) / 2.0)
5325 end on
5326 )NKSP_CODE",
5327 .expectRealExitResult = 10.4,
5328 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5329 .expectExitResultUnit = VM_BEL
5330 });
5331
5332 runScript({
5333 .code = R"NKSP_CODE(
5334 on init
5335 declare ~b := 3.2mdB
5336 declare ~a := 2.0mdB
5337 exit(4.0 * (~a + ~b) / 2.0)
5338 end on
5339 )NKSP_CODE",
5340 .expectRealExitResult = 10.4,
5341 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5342 .expectExitResultUnit = VM_BEL
5343 });
5344
5345 runScript({
5346 .code = R"NKSP_CODE(
5347 on init
5348 declare ~a := 4.0
5349 declare ~b := 2.0mdB
5350 declare ~c := 3.2mdB
5351 declare ~d := 2.0
5352 exit((~a * (~b + ~c) / ~d) + 1.1mdB)
5353 end on
5354 )NKSP_CODE",
5355 .expectRealExitResult = 11.5,
5356 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5357 .expectExitResultUnit = VM_BEL
5358 });
5359
5360 runScript({
5361 .code = R"NKSP_CODE(
5362 on init
5363 declare ~c := 3.2mdB
5364 declare ~a := 4.0
5365 declare ~d := 2.0
5366 declare ~b := 2.0mdB
5367 exit(~a * (~b + ~c) / ~d + 1.1mdB)
5368 end on
5369 )NKSP_CODE",
5370 .expectRealExitResult = 11.5,
5371 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5372 .expectExitResultUnit = VM_BEL
5373 });
5374
5375 // 'final' ('!') operator tests ...
5376
5377 runScript({
5378 .code = R"NKSP_CODE(
5379 on init
5380 declare $a := 4
5381 declare $b := !2us
5382 declare $c := 3us
5383 declare $d := 7ms
5384 exit($a * ($b + $c) + 7ms)
5385 end on
5386 )NKSP_CODE",
5387 .expectIntExitResult = 7020,
5388 .expectExitResultUnitPrefix = { VM_MICRO },
5389 .expectExitResultUnit = VM_SECOND,
5390 .expectExitResultFinal = true,
5391 .expectParseWarning = true // only one operand is defined as 'final', result will be final though
5392 });
5393
5394 runScript({
5395 .code = R"NKSP_CODE(
5396 on init
5397 declare $a := 4
5398 declare $b := 2us
5399 declare $c := !3us
5400 declare $d := 7ms
5401 exit($a * ($b + $c) + 7ms)
5402 end on
5403 )NKSP_CODE",
5404 .expectIntExitResult = 7020,
5405 .expectExitResultUnitPrefix = { VM_MICRO },
5406 .expectExitResultUnit = VM_SECOND,
5407 .expectExitResultFinal = true,
5408 .expectParseWarning = true // only one operand is defined as 'final', result will be final though
5409 });
5410
5411 #if !SILENT_TEST
5412 std::cout << std::endl;
5413 #endif
5414 }
5415
5416 static void testBuiltInMinFunction() {
5417 #if !SILENT_TEST
5418 std::cout << "UNIT TEST: built-in min() function\n";
5419 #endif
5420
5421 runScript({
5422 .code = R"NKSP_CODE(
5423 on init
5424 declare $foo := min
5425 end on
5426 )NKSP_CODE",
5427 .expectParseError = true // because min() function requires 2 arguments
5428 });
5429
5430 runScript({
5431 .code = R"NKSP_CODE(
5432 on init
5433 declare $foo := min()
5434 end on
5435 )NKSP_CODE",
5436 .expectParseError = true // because min() function requires 2 arguments
5437 });
5438
5439 runScript({
5440 .code = R"NKSP_CODE(
5441 on init
5442 declare $foo := min(1)
5443 end on
5444 )NKSP_CODE",
5445 .expectParseError = true // because min() function requires 2 arguments
5446 });
5447
5448 // integer tests ...
5449
5450 runScript({
5451 .code = R"NKSP_CODE(
5452 on init
5453 declare $foo := min(1,2)
5454 exit($foo)
5455 end on
5456 )NKSP_CODE",
5457 .expectIntExitResult = 1
5458 });
5459
5460 runScript({
5461 .code = R"NKSP_CODE(
5462 on init
5463 declare $foo := min(-30,4)
5464 exit($foo)
5465 end on
5466 )NKSP_CODE",
5467 .expectIntExitResult = -30
5468 });
5469
5470 // real number tests ...
5471
5472 runScript({
5473 .code = R"NKSP_CODE(
5474 on init
5475 declare ~foo := min(1.0, 2.0)
5476 exit(~foo)
5477 end on
5478 )NKSP_CODE",
5479 .expectRealExitResult = 1.0
5480 });
5481
5482 runScript({
5483 .code = R"NKSP_CODE(
5484 on init
5485 declare ~foo := min(-30.0, 4.0)
5486 exit(~foo)
5487 end on
5488 )NKSP_CODE",
5489 .expectRealExitResult = -30.0
5490 });
5491
5492 runScript({
5493 .code = R"NKSP_CODE(
5494 on init
5495 declare ~foo := min(1.1, 1.13)
5496 exit(~foo)
5497 end on
5498 )NKSP_CODE",
5499 .expectRealExitResult = 1.1
5500 });
5501
5502 runScript({
5503 .code = R"NKSP_CODE(
5504 on init
5505 declare ~foo := min(1.13, 1.1)
5506 exit(~foo)
5507 end on
5508 )NKSP_CODE",
5509 .expectRealExitResult = 1.1
5510 });
5511
5512 // mixed type tests ...
5513
5514 runScript({
5515 .code = R"NKSP_CODE(
5516 on init
5517 declare ~foo := min(1, 1.16)
5518 exit(~foo)
5519 end on
5520 )NKSP_CODE",
5521 .expectRealExitResult = 1.0,
5522 .expectParseWarning = true // min() warns if data types of arguments not matching
5523 });
5524
5525 runScript({
5526 .code = R"NKSP_CODE(
5527 on init
5528 declare ~foo := min(-3.92, 9)
5529 exit(~foo)
5530 end on
5531 )NKSP_CODE",
5532 .expectRealExitResult = -3.92,
5533 .expectParseWarning = true // min() warns if data types of arguments not matching
5534 });
5535
5536 // std unit tests ...
5537
5538 runScript({
5539 .code = R"NKSP_CODE(
5540 on init
5541 declare $foo := min(30ms,4s)
5542 exit($foo)
5543 end on
5544 )NKSP_CODE",
5545 .expectIntExitResult = 30,
5546 .expectExitResultUnitPrefix = { VM_MILLI },
5547 .expectExitResultUnit = VM_SECOND,
5548 });
5549
5550 runScript({
5551 .code = R"NKSP_CODE(
5552 on init
5553 declare $foo := min(4s,30ms)
5554 exit($foo)
5555 end on
5556 )NKSP_CODE",
5557 .expectIntExitResult = 30,
5558 .expectExitResultUnitPrefix = { VM_MILLI },
5559 .expectExitResultUnit = VM_SECOND,
5560 });
5561
5562 runScript({
5563 .code = R"NKSP_CODE(
5564 on init
5565 declare $foo := min(-30mdB,-4dB)
5566 exit($foo)
5567 end on
5568 )NKSP_CODE",
5569 .expectIntExitResult = -4,
5570 .expectExitResultUnitPrefix = { VM_DECI },
5571 .expectExitResultUnit = VM_BEL,
5572 });
5573
5574 runScript({
5575 .code = R"NKSP_CODE(
5576 on init
5577 declare $foo := min(-4dB,-30mdB)
5578 exit($foo)
5579 end on
5580 )NKSP_CODE",
5581 .expectIntExitResult = -4,
5582 .expectExitResultUnitPrefix = { VM_DECI },
5583 .expectExitResultUnit = VM_BEL,
5584 });
5585
5586 runScript({
5587 .code = R"NKSP_CODE(
5588 on init
5589 declare $foo := min(-4s,-30Hz)
5590 exit($foo)
5591 end on
5592 )NKSP_CODE",
5593 .expectParseError = true // min() requires arguments to have same unit type
5594 });
5595
5596 runScript({
5597 .code = R"NKSP_CODE(
5598 on init
5599 declare $foo := min(-4s,-30)
5600 exit($foo)
5601 end on
5602 )NKSP_CODE",
5603 .expectParseError = true // min() requires arguments to have same unit type
5604 });
5605
5606 runScript({
5607 .code = R"NKSP_CODE(
5608 on init
5609 declare $foo := min(-4,-30s)
5610 exit($foo)
5611 end on
5612 )NKSP_CODE",
5613 .expectParseError = true // min() requires arguments to have same unit type
5614 });
5615
5616 runScript({
5617 .code = R"NKSP_CODE(
5618 on init
5619 declare ~foo := min(0.9s,1.0s)
5620 exit(~foo)
5621 end on
5622 )NKSP_CODE",
5623 .expectRealExitResult = 0.9,
5624 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
5625 .expectExitResultUnit = VM_SECOND,
5626 });
5627
5628 // 'final' ('!') operator tests ...
5629
5630 runScript({
5631 .code = R"NKSP_CODE(
5632 on init
5633 declare $foo := min(!30,!4)
5634 exit($foo)
5635 end on
5636 )NKSP_CODE",
5637 .expectIntExitResult = 4,
5638 .expectExitResultFinal = true
5639 });
5640
5641 runScript({
5642 .code = R"NKSP_CODE(
5643 on init
5644 declare $foo := min(30,4)
5645 exit($foo)
5646 end on
5647 )NKSP_CODE",
5648 .expectIntExitResult = 4,
5649 .expectExitResultFinal = false
5650 });
5651
5652 runScript({
5653 .code = R"NKSP_CODE(
5654 on init
5655 declare $foo := min(30,!4)
5656 exit($foo)
5657 end on
5658 )NKSP_CODE",
5659 .expectIntExitResult = 4,
5660 .expectExitResultFinal = true,
5661 .expectParseWarning = true // min() warns if only one argument is 'final'
5662 });
5663
5664 runScript({
5665 .code = R"NKSP_CODE(
5666 on init
5667 declare $foo := min(!30,4)
5668 exit($foo)
5669 end on
5670 )NKSP_CODE",
5671 .expectIntExitResult = 4,
5672 .expectExitResultFinal = true,
5673 .expectParseWarning = true // min() warns if only one argument is 'final'
5674 });
5675
5676 runScript({
5677 .code = R"NKSP_CODE(
5678 on init
5679 declare ~foo := min(!12.1,!12.2)
5680 exit(~foo)
5681 end on
5682 )NKSP_CODE",
5683 .expectRealExitResult = 12.1,
5684 .expectExitResultFinal = true
5685 });
5686
5687 runScript({
5688 .code = R"NKSP_CODE(
5689 on init
5690 declare ~foo := min(12.1,12.2)
5691 exit(~foo)
5692 end on
5693 )NKSP_CODE",
5694 .expectRealExitResult = 12.1,
5695 .expectExitResultFinal = false
5696 });
5697
5698 runScript({
5699 .code = R"NKSP_CODE(
5700 on init
5701 declare ~foo := min(!12.1,12.2)
5702 exit(~foo)
5703 end on
5704 )NKSP_CODE",
5705 .expectRealExitResult = 12.1,
5706 .expectExitResultFinal = true,
5707 .expectParseWarning = true // min() warns if only one argument is 'final'
5708 });
5709
5710 runScript({
5711 .code = R"NKSP_CODE(
5712 on init
5713 declare ~foo := min(12.1,!12.2)
5714 exit(~foo)
5715 end on
5716 )NKSP_CODE",
5717 .expectRealExitResult = 12.1,
5718 .expectExitResultFinal = true,
5719 .expectParseWarning = true // min() warns if only one argument is 'final'
5720 });
5721
5722 #if !SILENT_TEST
5723 std::cout << std::endl;
5724 #endif
5725 }
5726
5727 static void testBuiltInMaxFunction() {
5728 #if !SILENT_TEST
5729 std::cout << "UNIT TEST: built-in max() function\n";
5730 #endif
5731
5732 // integer tests ...
5733
5734 runScript({
5735 .code = R"NKSP_CODE(
5736 on init
5737 declare $foo := max
5738 end on
5739 )NKSP_CODE",
5740 .expectParseError = true // because max() function requires 2 arguments
5741 });
5742
5743 runScript({
5744 .code = R"NKSP_CODE(
5745 on init
5746 declare $foo := max()
5747 end on
5748 )NKSP_CODE",
5749 .expectParseError = true // because max() function requires 2 arguments
5750 });
5751
5752 runScript({
5753 .code = R"NKSP_CODE(
5754 on init
5755 declare $foo := max(1)
5756 end on
5757 )NKSP_CODE",
5758 .expectParseError = true // because max() function requires 2 arguments
5759 });
5760
5761 runScript({
5762 .code = R"NKSP_CODE(
5763 on init
5764 declare $foo := max(1,2)
5765 exit($foo)
5766 end on
5767 )NKSP_CODE",
5768 .expectIntExitResult = 2
5769 });
5770
5771 runScript({
5772 .code = R"NKSP_CODE(
5773 on init
5774 declare $foo := max(-30,4)
5775 exit($foo)
5776 end on
5777 )NKSP_CODE",
5778 .expectIntExitResult = 4
5779 });
5780
5781 // real number tests ...
5782
5783 runScript({
5784 .code = R"NKSP_CODE(
5785 on init
5786 declare ~foo := max(1.0, 2.0)
5787 exit(~foo)
5788 end on
5789 )NKSP_CODE",
5790 .expectRealExitResult = 2.0
5791 });
5792
5793 runScript({
5794 .code = R"NKSP_CODE(
5795 on init
5796 declare ~foo := max(-30.0, 4.0)
5797 exit(~foo)
5798 end on
5799 )NKSP_CODE",
5800 .expectRealExitResult = 4.0
5801 });
5802
5803 runScript({
5804 .code = R"NKSP_CODE(
5805 on init
5806 declare ~foo := max(1.1, 1.13)
5807 exit(~foo)
5808 end on
5809 )NKSP_CODE",
5810 .expectRealExitResult = 1.13
5811 });
5812
5813 runScript({
5814 .code = R"NKSP_CODE(
5815 on init
5816 declare ~foo := max(1.13, 1.1)
5817 exit(~foo)
5818 end on
5819 )NKSP_CODE",
5820 .expectRealExitResult = 1.13
5821 });
5822
5823 // mixed type tests ...
5824
5825 runScript({
5826 .code = R"NKSP_CODE(
5827 on init
5828 declare ~foo := max(1, 1.16)
5829 exit(~foo)
5830 end on
5831 )NKSP_CODE",
5832 .expectRealExitResult = 1.16,
5833 .expectParseWarning = true // max() warns if data types of arguments not matching
5834 });
5835
5836 runScript({
5837 .code = R"NKSP_CODE(
5838 on init
5839 declare ~foo := max(-3.92, 9)
5840 exit(~foo)
5841 end on
5842 )NKSP_CODE",
5843 .expectRealExitResult = 9.0,
5844 .expectParseWarning = true // max() warns if data types of arguments not matching
5845 });
5846
5847 // std unit tests ...
5848
5849 runScript({
5850 .code = R"NKSP_CODE(
5851 on init
5852 declare $foo := max(30ms,4s)
5853 exit($foo)
5854 end on
5855 )NKSP_CODE",
5856 .expectIntExitResult = 4,
5857 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
5858 .expectExitResultUnit = VM_SECOND,
5859 });
5860
5861 runScript({
5862 .code = R"NKSP_CODE(
5863 on init
5864 declare $foo := max(4s,30ms)
5865 exit($foo)
5866 end on
5867 )NKSP_CODE",
5868 .expectIntExitResult = 4,
5869 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
5870 .expectExitResultUnit = VM_SECOND,
5871 });
5872
5873 runScript({
5874 .code = R"NKSP_CODE(
5875 on init
5876 declare $foo := max(-30mdB,-4dB)
5877 exit($foo)
5878 end on
5879 )NKSP_CODE",
5880 .expectIntExitResult = -30,
5881 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5882 .expectExitResultUnit = VM_BEL,
5883 });
5884
5885 runScript({
5886 .code = R"NKSP_CODE(
5887 on init
5888 declare $foo := max(-4dB,-30mdB)
5889 exit($foo)
5890 end on
5891 )NKSP_CODE",
5892 .expectIntExitResult = -30,
5893 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
5894 .expectExitResultUnit = VM_BEL,
5895 });
5896
5897 runScript({
5898 .code = R"NKSP_CODE(
5899 on init
5900 declare $foo := max(-4s,-30Hz)
5901 exit($foo)
5902 end on
5903 )NKSP_CODE",
5904 .expectParseError = true // max() requires arguments to have same unit type
5905 });
5906
5907 runScript({
5908 .code = R"NKSP_CODE(
5909 on init
5910 declare $foo := max(-4s,-30)
5911 exit($foo)
5912 end on
5913 )NKSP_CODE",
5914 .expectParseError = true // max() requires arguments to have same unit type
5915 });
5916
5917 runScript({
5918 .code = R"NKSP_CODE(
5919 on init
5920 declare $foo := max(-4,-30s)
5921 exit($foo)
5922 end on
5923 )NKSP_CODE",
5924 .expectParseError = true // max() requires arguments to have same unit type
5925 });
5926
5927 runScript({
5928 .code = R"NKSP_CODE(
5929 on init
5930 declare ~foo := max(0.9s,1.0s)
5931 exit(~foo)
5932 end on
5933 )NKSP_CODE",
5934 .expectRealExitResult = 1.0,
5935 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
5936 .expectExitResultUnit = VM_SECOND,
5937 });
5938
5939 // 'final' ('!') operator tests ...
5940
5941 runScript({
5942 .code = R"NKSP_CODE(
5943 on init
5944 declare $foo := max(!30,!4)
5945 exit($foo)
5946 end on
5947 )NKSP_CODE",
5948 .expectIntExitResult = 30,
5949 .expectExitResultFinal = true
5950 });
5951
5952 runScript({
5953 .code = R"NKSP_CODE(
5954 on init
5955 declare $foo := max(30,4)
5956 exit($foo)
5957 end on
5958 )NKSP_CODE",
5959 .expectIntExitResult = 30,
5960 .expectExitResultFinal = false
5961 });
5962
5963 runScript({
5964 .code = R"NKSP_CODE(
5965 on init
5966 declare $foo := max(30,!4)
5967 exit($foo)
5968 end on
5969 )NKSP_CODE",
5970 .expectIntExitResult = 30,
5971 .expectExitResultFinal = true,
5972 .expectParseWarning = true // max() warns if only one argument is 'final'
5973 });
5974
5975 runScript({
5976 .code = R"NKSP_CODE(
5977 on init
5978 declare $foo := max(!30,4)
5979 exit($foo)
5980 end on
5981 )NKSP_CODE",
5982 .expectIntExitResult = 30,
5983 .expectExitResultFinal = true,
5984 .expectParseWarning = true // max() warns if only one argument is 'final'
5985 });
5986
5987 runScript({
5988 .code = R"NKSP_CODE(
5989 on init
5990 declare ~foo := max(!12.1,!12.2)
5991 exit(~foo)
5992 end on
5993 )NKSP_CODE",
5994 .expectRealExitResult = 12.2,
5995 .expectExitResultFinal = true
5996 });
5997
5998 runScript({
5999 .code = R"NKSP_CODE(
6000 on init
6001 declare ~foo := max(12.1,12.2)
6002 exit(~foo)
6003 end on
6004 )NKSP_CODE",
6005 .expectRealExitResult = 12.2,
6006 .expectExitResultFinal = false
6007 });
6008
6009 runScript({
6010 .code = R"NKSP_CODE(
6011 on init
6012 declare ~foo := max(!12.1,12.2)
6013 exit(~foo)
6014 end on
6015 )NKSP_CODE",
6016 .expectRealExitResult = 12.2,
6017 .expectExitResultFinal = true,
6018 .expectParseWarning = true // max() warns if only one argument is 'final'
6019 });
6020
6021 runScript({
6022 .code = R"NKSP_CODE(
6023 on init
6024 declare ~foo := max(12.1,!12.2)
6025 exit(~foo)
6026 end on
6027 )NKSP_CODE",
6028 .expectRealExitResult = 12.2,
6029 .expectExitResultFinal = true,
6030 .expectParseWarning = true // max() warns if only one argument is 'final'
6031 });
6032
6033 #if !SILENT_TEST
6034 std::cout << std::endl;
6035 #endif
6036 }
6037
6038 static void testBuiltInAbsFunction() {
6039 #if !SILENT_TEST
6040 std::cout << "UNIT TEST: built-in abs() function\n";
6041 #endif
6042
6043 runScript({
6044 .code = R"NKSP_CODE(
6045 on init
6046 declare $foo := abs
6047 end on
6048 )NKSP_CODE",
6049 .expectParseError = true // because abs() function requires 1 argument
6050 });
6051
6052 runScript({
6053 .code = R"NKSP_CODE(
6054 on init
6055 declare $foo := abs()
6056 end on
6057 )NKSP_CODE",
6058 .expectParseError = true // because abs() function requires 1 argument
6059 });
6060
6061 // integer tests ...
6062
6063 runScript({
6064 .code = R"NKSP_CODE(
6065 on init
6066 declare $foo := abs(23)
6067 exit($foo)
6068 end on
6069 )NKSP_CODE",
6070 .expectIntExitResult = 23
6071 });
6072
6073 runScript({
6074 .code = R"NKSP_CODE(
6075 on init
6076 declare $foo := abs(-23)
6077 exit($foo)
6078 end on
6079 )NKSP_CODE",
6080 .expectIntExitResult = 23
6081 });
6082
6083 // real number tests ...
6084
6085 runScript({
6086 .code = R"NKSP_CODE(
6087 on init
6088 declare ~foo := abs(23.0)
6089 exit(~foo)
6090 end on
6091 )NKSP_CODE",
6092 .expectRealExitResult = 23.0
6093 });
6094
6095 runScript({
6096 .code = R"NKSP_CODE(
6097 on init
6098 declare ~foo := abs(23.11)
6099 exit(~foo)
6100 end on
6101 )NKSP_CODE",
6102 .expectRealExitResult = 23.11
6103 });
6104
6105 runScript({
6106 .code = R"NKSP_CODE(
6107 on init
6108 declare ~foo := abs(-23.11)
6109 exit(~foo)
6110 end on
6111 )NKSP_CODE",
6112 .expectRealExitResult = 23.11
6113 });
6114
6115 runScript({
6116 .code = R"NKSP_CODE(
6117 on init
6118 declare ~bar := -23.11
6119 declare ~foo := abs(~bar)
6120 exit(~foo)
6121 end on
6122 )NKSP_CODE",
6123 .expectRealExitResult = 23.11
6124 });
6125
6126 // std unit tests ...
6127
6128 runScript({
6129 .code = R"NKSP_CODE(
6130 on init
6131 declare $foo := abs(-23kHz)
6132 exit($foo)
6133 end on
6134 )NKSP_CODE",
6135 .expectIntExitResult = 23,
6136 .expectExitResultUnitPrefix = { VM_KILO },
6137 .expectExitResultUnit = VM_HERTZ
6138 });
6139
6140 runScript({
6141 .code = R"NKSP_CODE(
6142 on init
6143 declare ~foo := abs(-23.4kHz)
6144 exit(~foo)
6145 end on
6146 )NKSP_CODE",
6147 .expectRealExitResult = 23.4,
6148 .expectExitResultUnitPrefix = { VM_KILO },
6149 .expectExitResultUnit = VM_HERTZ
6150 });
6151
6152 // 'final' ('!') operator tests ...
6153
6154 runScript({
6155 .code = R"NKSP_CODE(
6156 on init
6157 declare $foo := abs(!-23)
6158 exit($foo)
6159 end on
6160 )NKSP_CODE",
6161 .expectIntExitResult = 23,
6162 .expectExitResultFinal = true
6163 });
6164
6165 runScript({
6166 .code = R"NKSP_CODE(
6167 on init
6168 declare $foo := abs(-23)
6169 exit($foo)
6170 end on
6171 )NKSP_CODE",
6172 .expectIntExitResult = 23,
6173 .expectExitResultFinal = false
6174 });
6175
6176 runScript({
6177 .code = R"NKSP_CODE(
6178 on init
6179 declare ~foo := abs(!-23.2)
6180 exit(~foo)
6181 end on
6182 )NKSP_CODE",
6183 .expectRealExitResult = 23.2,
6184 .expectExitResultFinal = true
6185 });
6186
6187 runScript({
6188 .code = R"NKSP_CODE(
6189 on init
6190 declare ~foo := abs(-23.9)
6191 exit(~foo)
6192 end on
6193 )NKSP_CODE",
6194 .expectRealExitResult = 23.9,
6195 .expectExitResultFinal = false
6196 });
6197
6198 #if !SILENT_TEST
6199 std::cout << std::endl;
6200 #endif
6201 }
6202
6203 static void testBuiltInIncFunction() {
6204 #if !SILENT_TEST
6205 std::cout << "UNIT TEST: built-in inc() function\n";
6206 #endif
6207
6208 // integer tests ...
6209
6210 runScript({
6211 .code = R"NKSP_CODE(
6212 on init
6213 declare $foo := 5
6214 inc($foo)
6215 exit($foo)
6216 end on
6217 )NKSP_CODE",
6218 .expectIntExitResult = 6
6219 });
6220
6221 runScript({
6222 .code = R"NKSP_CODE(
6223 on init
6224 declare $foo := 5
6225 inc($foo)
6226 inc($foo)
6227 inc($foo)
6228 exit($foo)
6229 end on
6230 )NKSP_CODE",
6231 .expectIntExitResult = 8
6232 });
6233
6234 runScript({
6235 .code = R"NKSP_CODE(
6236 on init
6237 declare $foo := 5
6238 inc($foo)
6239 exit( inc($foo) )
6240 end on
6241 )NKSP_CODE",
6242 .expectIntExitResult = 7
6243 });
6244
6245 // std unit tests ...
6246
6247 runScript({
6248 .code = R"NKSP_CODE(
6249 on init
6250 declare $foo := 53mdB
6251 inc($foo)
6252 exit( inc($foo) )
6253 end on
6254 )NKSP_CODE",
6255 .expectIntExitResult = 55,
6256 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
6257 .expectExitResultUnit = VM_BEL,
6258 .expectParseWarning = true // inc() warns if argument has a unit
6259 });
6260
6261 // 'final' ('!') operator tests ...
6262
6263 runScript({
6264 .code = R"NKSP_CODE(
6265 on init
6266 declare $foo := !53
6267 inc($foo)
6268 exit( inc($foo) )
6269 end on
6270 )NKSP_CODE",
6271 .expectIntExitResult = 55,
6272 .expectExitResultFinal = true
6273 });
6274
6275 runScript({
6276 .code = R"NKSP_CODE(
6277 on init
6278 declare $foo := 53
6279 inc($foo)
6280 exit( inc($foo) )
6281 end on
6282 )NKSP_CODE",
6283 .expectIntExitResult = 55,
6284 .expectExitResultFinal = false
6285 });
6286
6287 runScript({
6288 .code = R"NKSP_CODE(
6289 on init
6290 declare $foo := 53
6291 inc($foo)
6292 exit( !inc($foo) )
6293 end on
6294 )NKSP_CODE",
6295 .expectIntExitResult = 55,
6296 .expectExitResultFinal = true
6297 });
6298
6299 #if !SILENT_TEST
6300 std::cout << std::endl;
6301 #endif
6302 }
6303
6304 static void testBuiltInDecFunction() {
6305 #if !SILENT_TEST
6306 std::cout << "UNIT TEST: built-in dec() function\n";
6307 #endif
6308
6309 // integer tests ...
6310
6311 runScript({
6312 .code = R"NKSP_CODE(
6313 on init
6314 declare $foo := 5
6315 dec($foo)
6316 exit($foo)
6317 end on
6318 )NKSP_CODE",
6319 .expectIntExitResult = 4
6320 });
6321
6322 runScript({
6323 .code = R"NKSP_CODE(
6324 on init
6325 declare $foo := 5
6326 dec($foo)
6327 dec($foo)
6328 dec($foo)
6329 exit($foo)
6330 end on
6331 )NKSP_CODE",
6332 .expectIntExitResult = 2
6333 });
6334
6335 runScript({
6336 .code = R"NKSP_CODE(
6337 on init
6338 declare $foo := 5
6339 dec($foo)
6340 exit( dec($foo) )
6341 end on
6342 )NKSP_CODE",
6343 .expectIntExitResult = 3
6344 });
6345
6346 // std unit tests ...
6347
6348 runScript({
6349 .code = R"NKSP_CODE(
6350 on init
6351 declare $foo := 53mdB
6352 dec($foo)
6353 exit( dec($foo) )
6354 end on
6355 )NKSP_CODE",
6356 .expectIntExitResult = 51,
6357 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
6358 .expectExitResultUnit = VM_BEL,
6359 .expectParseWarning = true // dec() warns if argument has a unit
6360 });
6361
6362 // 'final' ('!') operator tests ...
6363
6364 runScript({
6365 .code = R"NKSP_CODE(
6366 on init
6367 declare $foo := !53
6368 dec($foo)
6369 exit( dec($foo) )
6370 end on
6371 )NKSP_CODE",
6372 .expectIntExitResult = 51,
6373 .expectExitResultFinal = true
6374 });
6375
6376 runScript({
6377 .code = R"NKSP_CODE(
6378 on init
6379 declare $foo := 53
6380 dec($foo)
6381 exit( dec($foo) )
6382 end on
6383 )NKSP_CODE",
6384 .expectIntExitResult = 51,
6385 .expectExitResultFinal = false
6386 });
6387
6388 runScript({
6389 .code = R"NKSP_CODE(
6390 on init
6391 declare $foo := 53
6392 dec($foo)
6393 exit( !dec($foo) )
6394 end on
6395 )NKSP_CODE",
6396 .expectIntExitResult = 51,
6397 .expectExitResultFinal = true
6398 });
6399
6400 #if !SILENT_TEST
6401 std::cout << std::endl;
6402 #endif
6403 }
6404
6405 static void testBuiltInInRangeFunction() {
6406 #if !SILENT_TEST
6407 std::cout << "UNIT TEST: built-in in_range() function\n";
6408 #endif
6409
6410 // integer tests ...
6411
6412 runScript({
6413 .code = R"NKSP_CODE(
6414 on init
6415 exit( in_range(1,4,9) )
6416 end on
6417 )NKSP_CODE",
6418 .expectBoolExitResult = false
6419 });
6420
6421 runScript({
6422 .code = R"NKSP_CODE(
6423 on init
6424 exit( in_range(5,4,9) )
6425 end on
6426 )NKSP_CODE",
6427 .expectBoolExitResult = true
6428 });
6429
6430 runScript({
6431 .code = R"NKSP_CODE(
6432 on init
6433 exit( in_range(9,4,9) )
6434 end on
6435 )NKSP_CODE",
6436 .expectBoolExitResult = true
6437 });
6438
6439 runScript({
6440 .code = R"NKSP_CODE(
6441 on init
6442 exit( in_range(10,4,9) )
6443 end on
6444 )NKSP_CODE",
6445 .expectBoolExitResult = false
6446 });
6447
6448 runScript({
6449 .code = R"NKSP_CODE(
6450 on init
6451 exit( in_range(-6,-5,5) )
6452 end on
6453 )NKSP_CODE",
6454 .expectBoolExitResult = false
6455 });
6456
6457 runScript({
6458 .code = R"NKSP_CODE(
6459 on init
6460 exit( in_range(-5,-5,5) )
6461 end on
6462 )NKSP_CODE",
6463 .expectBoolExitResult = true
6464 });
6465
6466 runScript({
6467 .code = R"NKSP_CODE(
6468 on init
6469 exit( in_range(0,-5,5) )
6470 end on
6471 )NKSP_CODE",
6472 .expectBoolExitResult = true
6473 });
6474
6475 runScript({
6476 .code = R"NKSP_CODE(
6477 on init
6478 exit( in_range(5,-5,5) )
6479 end on
6480 )NKSP_CODE",
6481 .expectBoolExitResult = true
6482 });
6483
6484 runScript({
6485 .code = R"NKSP_CODE(
6486 on init
6487 exit( in_range(6,-5,5) )
6488 end on
6489 )NKSP_CODE",
6490 .expectBoolExitResult = false
6491 });
6492
6493 // real number tests ...
6494
6495 runScript({
6496 .code = R"NKSP_CODE(
6497 on init
6498 exit( in_range(12.2,12.1,12.9) )
6499 end on
6500 )NKSP_CODE",
6501 .expectBoolExitResult = true
6502 });
6503
6504 runScript({
6505 .code = R"NKSP_CODE(
6506 on init
6507 exit( in_range(12.2,12.9,12.1) )
6508 end on
6509 )NKSP_CODE",
6510 .expectBoolExitResult = true
6511 });
6512
6513 runScript({
6514 .code = R"NKSP_CODE(
6515 on init
6516 exit( in_range(12.0,12.1,12.9) )
6517 end on
6518 )NKSP_CODE",
6519 .expectBoolExitResult = false
6520 });
6521
6522 runScript({
6523 .code = R"NKSP_CODE(
6524 on init
6525 exit( in_range(12.0,12.9,12.1) )
6526 end on
6527 )NKSP_CODE",
6528 .expectBoolExitResult = false
6529 });
6530
6531 runScript({
6532 .code = R"NKSP_CODE(
6533 on init
6534 exit( in_range(0.0,-0.3,0.3) )
6535 end on
6536 )NKSP_CODE",
6537 .expectBoolExitResult = true
6538 });
6539
6540 runScript({
6541 .code = R"NKSP_CODE(
6542 on init
6543 exit( in_range(-0.34,-0.3,0.3) )
6544 end on
6545 )NKSP_CODE",
6546 .expectBoolExitResult = false
6547 });
6548
6549 runScript({
6550 .code = R"NKSP_CODE(
6551 on init
6552 exit( in_range(0.34,-0.3,0.3) )
6553 end on
6554 )NKSP_CODE",
6555 .expectBoolExitResult = false
6556 });
6557
6558 runScript({
6559 .code = R"NKSP_CODE(
6560 on init
6561 exit( in_range(-0.3,-0.3,0.3) )
6562 end on
6563 )NKSP_CODE",
6564 .expectBoolExitResult = true
6565 });
6566
6567 runScript({
6568 .code = R"NKSP_CODE(
6569 on init
6570 exit( in_range(0.3,-0.3,0.3) )
6571 end on
6572 )NKSP_CODE",
6573 .expectBoolExitResult = true
6574 });
6575
6576 // mixed type tests ...
6577
6578 runScript({
6579 .code = R"NKSP_CODE(
6580 on init
6581 exit( in_range(4.0,-5,5) )
6582 end on
6583 )NKSP_CODE",
6584 .expectBoolExitResult = true,
6585 .expectParseWarning = true // in_range() warns if not all arguments are of same type
6586 });
6587
6588 runScript({
6589 .code = R"NKSP_CODE(
6590 on init
6591 exit( in_range(5,-5,5.0) )
6592 end on
6593 )NKSP_CODE",
6594 .expectBoolExitResult = true,
6595 .expectParseWarning = true // in_range() warns if not all arguments are of same type
6596 });
6597
6598 runScript({
6599 .code = R"NKSP_CODE(
6600 on init
6601 exit( in_range(-5,-5.0,5) )
6602 end on
6603 )NKSP_CODE",
6604 .expectBoolExitResult = true,
6605 .expectParseWarning = true // in_range() warns if not all arguments are of same type
6606 });
6607
6608 // std unit tests ...
6609
6610 runScript({
6611 .code = R"NKSP_CODE(
6612 on init
6613 exit( in_range(4000Hz,3kHz,5kHz) )
6614 end on
6615 )NKSP_CODE",
6616 .expectBoolExitResult = true,
6617 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6618 .expectExitResultUnit = VM_NO_UNIT
6619 });
6620
6621 runScript({
6622 .code = R"NKSP_CODE(
6623 on init
6624 exit( in_range(5000Hz,3kHz,5kHz) )
6625 end on
6626 )NKSP_CODE",
6627 .expectBoolExitResult = true,
6628 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6629 .expectExitResultUnit = VM_NO_UNIT
6630 });
6631
6632 runScript({
6633 .code = R"NKSP_CODE(
6634 on init
6635 exit( in_range(5001Hz,3kHz,5kHz) )
6636 end on
6637 )NKSP_CODE",
6638 .expectBoolExitResult = false,
6639 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6640 .expectExitResultUnit = VM_NO_UNIT
6641 });
6642
6643 runScript({
6644 .code = R"NKSP_CODE(
6645 on init
6646 exit( in_range(3000Hz,3kHz,5kHz) )
6647 end on
6648 )NKSP_CODE",
6649 .expectBoolExitResult = true,
6650 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6651 .expectExitResultUnit = VM_NO_UNIT
6652 });
6653
6654 runScript({
6655 .code = R"NKSP_CODE(
6656 on init
6657 exit( in_range(2999Hz,3kHz,5kHz) )
6658 end on
6659 )NKSP_CODE",
6660 .expectBoolExitResult = false,
6661 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6662 .expectExitResultUnit = VM_NO_UNIT
6663 });
6664
6665 runScript({
6666 .code = R"NKSP_CODE(
6667 on init
6668 exit( in_range(0.003s,3000.0us,5ms) )
6669 end on
6670 )NKSP_CODE",
6671 .expectBoolExitResult = true,
6672 .expectParseWarning = true, // in_range() warns if not all arguments are of same type
6673 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6674 .expectExitResultUnit = VM_NO_UNIT
6675 });
6676
6677 runScript({
6678 .code = R"NKSP_CODE(
6679 on init
6680 exit( in_range(0.005s,3000.0us,5ms) )
6681 end on
6682 )NKSP_CODE",
6683 .expectBoolExitResult = true,
6684 .expectParseWarning = true, // in_range() warns if not all arguments are of same type,
6685 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6686 .expectExitResultUnit = VM_NO_UNIT
6687 });
6688
6689 runScript({
6690 .code = R"NKSP_CODE(
6691 on init
6692 exit( in_range(0.0051s,3000.0us,5ms) )
6693 end on
6694 )NKSP_CODE",
6695 .expectBoolExitResult = false,
6696 .expectParseWarning = true, // in_range() warns if not all arguments are of same type
6697 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6698 .expectExitResultUnit = VM_NO_UNIT
6699 });
6700
6701 runScript({
6702 .code = R"NKSP_CODE(
6703 on init
6704 exit( in_range(3s,2Hz,5Hz) )
6705 end on
6706 )NKSP_CODE",
6707 .expectParseError = true // in_range() throws error if not all arguments' unit types equal,
6708 });
6709
6710 runScript({
6711 .code = R"NKSP_CODE(
6712 on init
6713 exit( in_range(3Hz,2s,5Hz) )
6714 end on
6715 )NKSP_CODE",
6716 .expectParseError = true // in_range() throws error if not all arguments' unit types equal
6717 });
6718
6719 runScript({
6720 .code = R"NKSP_CODE(
6721 on init
6722 exit( in_range(3Hz,2Hz,5s) )
6723 end on
6724 )NKSP_CODE",
6725 .expectParseError = true // in_range() throws error if not all arguments' unit types equal
6726 });
6727
6728 // 'final' ('!') operator tests ...
6729 // (result should always be NOT final)
6730
6731 runScript({
6732 .code = R"NKSP_CODE(
6733 on init
6734 exit( in_range(!9,!4,!9) )
6735 end on
6736 )NKSP_CODE",
6737 .expectBoolExitResult = true,
6738 .expectExitResultFinal = false
6739 });
6740
6741 #if !SILENT_TEST
6742 std::cout << std::endl;
6743 #endif
6744 }
6745
6746 static void testBuiltInRandomFunction() {
6747 #if !SILENT_TEST
6748 std::cout << "UNIT TEST: built-in random() function\n";
6749 #endif
6750
6751 // integer tests ...
6752
6753 runScript({
6754 .code = R"NKSP_CODE(
6755 on init
6756 exit( random(-5,5) )
6757 end on
6758 )NKSP_CODE",
6759 .expectExitResultIsInt = true // only check type, exact value is irrelevant here
6760 });
6761
6762 for (int run = 0; run < 20; ++run) {
6763 runScript({
6764 .code = R"NKSP_CODE(
6765 on init
6766 declare $foo := random(-5,5)
6767 exit( in_range($foo,-5,5) )
6768 end on
6769 )NKSP_CODE",
6770 .expectBoolExitResult = true
6771 });
6772 }
6773
6774 // real number tests ...
6775
6776 runScript({
6777 .code = R"NKSP_CODE(
6778 on init
6779 exit( random(-0.5,0.5) )
6780 end on
6781 )NKSP_CODE",
6782 .expectExitResultIsReal = true // only check type, exact value is irrelevant here
6783 });
6784
6785 runScript({
6786 .code = R"NKSP_CODE(
6787 on init
6788 declare ~foo := random(-5.0,5.0)
6789 exit(~foo)
6790 end on
6791 )NKSP_CODE",
6792 .expectExitResultIsReal = true // only check type, exact value is irrelevant here
6793 });
6794
6795 for (int run = 0; run < 20; ++run) {
6796 runScript({
6797 .code = R"NKSP_CODE(
6798 on init
6799 declare ~foo := random(-0.5,0.5)
6800 exit( in_range(~foo,-0.5,0.5) )
6801 end on
6802 )NKSP_CODE",
6803 .expectBoolExitResult = true
6804 });
6805 }
6806
6807 for (int run = 0; run < 20; ++run) {
6808 runScript({
6809 .code = R"NKSP_CODE(
6810 on init
6811 declare ~foo := random(-5.0,12.0)
6812 exit( in_range(~foo,-5.0,12.0) )
6813 end on
6814 )NKSP_CODE",
6815 .expectBoolExitResult = true
6816 });
6817 }
6818
6819 for (int run = 0; run < 20; ++run) {
6820 runScript({
6821 .code = R"NKSP_CODE(
6822 on init
6823 declare ~foo := random(23.3,98.4)
6824 exit( in_range(~foo,23.3,98.4) )
6825 end on
6826 )NKSP_CODE",
6827 .expectBoolExitResult = true
6828 });
6829 }
6830
6831 // std unit tests ...
6832
6833 runScript({
6834 .code = R"NKSP_CODE(
6835 on init
6836 exit( random(-5Hz,5Hz) )
6837 end on
6838 )NKSP_CODE",
6839 .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
6840 .expectExitResultUnitPrefix = { VM_NO_PREFIX },
6841 .expectExitResultUnit = VM_HERTZ
6842 });
6843
6844 for (int run = 0; run < 20; ++run) {
6845 runScript({
6846 .code = R"NKSP_CODE(
6847 on init
6848 declare $foo := random(-5Hz,5Hz)
6849 exit( in_range($foo,-5Hz,5Hz) )
6850 end on
6851 )NKSP_CODE",
6852 .expectBoolExitResult = true
6853 });
6854 }
6855
6856 runScript({
6857 .code = R"NKSP_CODE(
6858 on init
6859 exit( random(5us,1ms) )
6860 end on
6861 )NKSP_CODE",
6862 .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
6863 .expectExitResultUnitPrefix = { VM_MICRO },
6864 .expectExitResultUnit = VM_SECOND
6865 });
6866
6867 for (int run = 0; run < 20; ++run) {
6868 runScript({
6869 .code = R"NKSP_CODE(
6870 on init
6871 declare $foo := random(5us,1ms)
6872 exit( in_range($foo,5us,1ms) )
6873 end on
6874 )NKSP_CODE",
6875 .expectBoolExitResult = true
6876 });
6877 }
6878
6879 runScript({
6880 .code = R"NKSP_CODE(
6881 on init
6882 exit( random(1ms,5000us) )
6883 end on
6884 )NKSP_CODE",
6885 .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
6886 .expectExitResultUnitPrefix = { VM_MICRO },
6887 .expectExitResultUnit = VM_SECOND
6888 });
6889
6890 for (int run = 0; run < 20; ++run) {
6891 runScript({
6892 .code = R"NKSP_CODE(
6893 on init
6894 declare $foo := random(1ms,5000us)
6895 exit( in_range($foo,1ms,5000us) )
6896 end on
6897 )NKSP_CODE",
6898 .expectBoolExitResult = true
6899 });
6900 }
6901
6902 runScript({
6903 .code = R"NKSP_CODE(
6904 on init
6905 exit( random(1kHz,20kHz) )
6906 end on
6907 )NKSP_CODE",
6908 .expectExitResultIsInt = true, // only check type, exact value is irrelevant here
6909 .expectExitResultUnitPrefix = { VM_KILO },
6910 .expectExitResultUnit = VM_HERTZ
6911 });
6912
6913 for (int run = 0; run < 20; ++run) {
6914 runScript({
6915 .code = R"NKSP_CODE(
6916 on init
6917 declare $foo := random(1kHz,20kHz)
6918 exit( in_range($foo,1kHz,20kHz) )
6919 end on
6920 )NKSP_CODE",
6921 .expectBoolExitResult = true
6922 });
6923 }
6924
6925 runScript({
6926 .code = R"NKSP_CODE(
6927 on init
6928 exit( random(1.2us,3.5us) )
6929 end on
6930 )NKSP_CODE",
6931 .expectExitResultIsReal = true, // only check type, exact value is irrelevant here
6932 .expectExitResultUnitPrefix = { VM_MICRO },
6933 .expectExitResultUnit = VM_SECOND
6934 });
6935
6936 for (int run = 0; run < 20; ++run) {
6937 runScript({
6938 .code = R"NKSP_CODE(
6939 on init
6940 declare ~foo := random(1.2us,3.5us)
6941 exit( in_range(~foo,1.2us,3.5us) )
6942 end on
6943 )NKSP_CODE",
6944 .expectBoolExitResult = true
6945 });
6946 }
6947
6948 runScript({
6949 .code = R"NKSP_CODE(
6950 on init
6951 exit( random(5.2us,1.1ms) )
6952 end on
6953 )NKSP_CODE",
6954 .expectExitResultIsReal = true, // only check type, exact value is irrelevant here
6955 .expectExitResultUnitPrefix = { VM_MICRO },
6956 .expectExitResultUnit = VM_SECOND
6957 });
6958
6959 for (int run = 0; run < 20; ++run) {
6960 runScript({
6961 .code = R"NKSP_CODE(
6962 on init
6963 declare ~foo := random(5.2us,1.1ms)
6964 exit( in_range(~foo,5.2us,1.1ms) )
6965 end on
6966 )NKSP_CODE",
6967 .expectBoolExitResult = true
6968 });
6969 }
6970
6971 runScript({
6972 .code = R"NKSP_CODE(
6973 on init
6974 exit( random(1Hz,12s) )
6975 end on
6976 )NKSP_CODE",
6977 .expectParseError = true // random() throws error if arguments' unit types don't match
6978 });
6979
6980 runScript({
6981 .code = R"NKSP_CODE(
6982 on init
6983 exit( random(1,12s) )
6984 end on
6985 )NKSP_CODE",
6986 .expectParseError = true // random() throws error if arguments' unit types don't match
6987 });
6988
6989 runScript({
6990 .code = R"NKSP_CODE(
6991 on init
6992 exit( random(1s,12) )
6993 end on
6994 )NKSP_CODE",
6995 .expectParseError = true // random() throws error if arguments' unit types don't match
6996 });
6997
6998 // 'final' ('!') operator tests ...
6999
7000 runScript({
7001 .code = R"NKSP_CODE(
7002 on init
7003 exit( random(!1,!12) )
7004 end on
7005 )NKSP_CODE",
7006 .expectExitResultFinal = true
7007 });
7008
7009 runScript({
7010 .code = R"NKSP_CODE(
7011 on init
7012 exit( random(1,12) )
7013 end on
7014 )NKSP_CODE",
7015 .expectExitResultFinal = false
7016 });
7017
7018 runScript({
7019 .code = R"NKSP_CODE(
7020 on init
7021 exit( random(!1,12) )
7022 end on
7023 )NKSP_CODE",
7024 .expectExitResultFinal = true,
7025 .expectParseWarning = true // random() warns if only one argument is 'final'
7026 });
7027
7028 runScript({
7029 .code = R"NKSP_CODE(
7030 on init
7031 exit( random(1,!12) )
7032 end on
7033 )NKSP_CODE",
7034 .expectExitResultFinal = true,
7035 .expectParseWarning = true // random() warns if only one argument is 'final'
7036 });
7037
7038 #if !SILENT_TEST
7039 std::cout << std::endl;
7040 #endif
7041 }
7042
7043 static void testBuiltInShiftLeftFunction() {
7044 #if !SILENT_TEST
7045 std::cout << "UNIT TEST: built-in sh_left() function\n";
7046 #endif
7047
7048 runScript({
7049 .code = R"NKSP_CODE(
7050 on init
7051 exit( sh_left(1,0) )
7052 end on
7053 )NKSP_CODE",
7054 .expectIntExitResult = 1
7055 });
7056
7057 runScript({
7058 .code = R"NKSP_CODE(
7059 on init
7060 exit( sh_left(1,1) )
7061 end on
7062 )NKSP_CODE",
7063 .expectIntExitResult = 2
7064 });
7065
7066 runScript({
7067 .code = R"NKSP_CODE(
7068 on init
7069 exit( sh_left(1,2) )
7070 end on
7071 )NKSP_CODE",
7072 .expectIntExitResult = 4
7073 });
7074
7075 runScript({
7076 .code = R"NKSP_CODE(
7077 on init
7078 exit( sh_left(1,3) )
7079 end on
7080 )NKSP_CODE",
7081 .expectIntExitResult = 8
7082 });
7083
7084 #if !SILENT_TEST
7085 std::cout << std::endl;
7086 #endif
7087 }
7088
7089 static void testBuiltInShiftRightFunction() {
7090 #if !SILENT_TEST
7091 std::cout << "UNIT TEST: built-in sh_right() function\n";
7092 #endif
7093
7094 runScript({
7095 .code = R"NKSP_CODE(
7096 on init
7097 exit( sh_right(8,0) )
7098 end on
7099 )NKSP_CODE",
7100 .expectIntExitResult = 8
7101 });
7102
7103 runScript({
7104 .code = R"NKSP_CODE(
7105 on init
7106 exit( sh_right(8,1) )
7107 end on
7108 )NKSP_CODE",
7109 .expectIntExitResult = 4
7110 });
7111
7112 runScript({
7113 .code = R"NKSP_CODE(
7114 on init
7115 exit( sh_right(8,2) )
7116 end on
7117 )NKSP_CODE",
7118 .expectIntExitResult = 2
7119 });
7120
7121 runScript({
7122 .code = R"NKSP_CODE(
7123 on init
7124 exit( sh_right(8,3) )
7125 end on
7126 )NKSP_CODE",
7127 .expectIntExitResult = 1
7128 });
7129
7130 runScript({
7131 .code = R"NKSP_CODE(
7132 on init
7133 exit( sh_right(8,4) )
7134 end on
7135 )NKSP_CODE",
7136 .expectIntExitResult = 0
7137 });
7138
7139 #if !SILENT_TEST
7140 std::cout << std::endl;
7141 #endif
7142 }
7143
7144 static void testBuiltInMsbFunction() {
7145 #if !SILENT_TEST
7146 std::cout << "UNIT TEST: built-in msb() function\n";
7147 #endif
7148
7149 runScript({
7150 .code = R"NKSP_CODE(
7151 on init
7152 exit( msb(0) )
7153 end on
7154 )NKSP_CODE",
7155 .expectIntExitResult = 0
7156 });
7157
7158 runScript({
7159 .code = R"NKSP_CODE(
7160 on init
7161 exit( msb(127) )
7162 end on
7163 )NKSP_CODE",
7164 .expectIntExitResult = 0
7165 });
7166
7167 runScript({
7168 .code = R"NKSP_CODE(
7169 on init
7170 exit( msb(128) )
7171 end on
7172 )NKSP_CODE",
7173 .expectIntExitResult = 1
7174 });
7175
7176 runScript({
7177 .code = R"NKSP_CODE(
7178 on init
7179 exit( msb(16255) )
7180 end on
7181 )NKSP_CODE",
7182 .expectIntExitResult = 126
7183 });
7184
7185 runScript({
7186 .code = R"NKSP_CODE(
7187 on init
7188 exit( msb(16256) )
7189 end on
7190 )NKSP_CODE",
7191 .expectIntExitResult = 127
7192 });
7193
7194 runScript({
7195 .code = R"NKSP_CODE(
7196 on init
7197 exit( msb(16383) )
7198 end on
7199 )NKSP_CODE",
7200 .expectIntExitResult = 127
7201 });
7202
7203 #if !SILENT_TEST
7204 std::cout << std::endl;
7205 #endif
7206 }
7207
7208 static void testBuiltInLsbFunction() {
7209 #if !SILENT_TEST
7210 std::cout << "UNIT TEST: built-in lsb() function\n";
7211 #endif
7212
7213 runScript({
7214 .code = R"NKSP_CODE(
7215 on init
7216 exit( lsb(0) )
7217 end on
7218 )NKSP_CODE",
7219 .expectIntExitResult = 0
7220 });
7221
7222 runScript({
7223 .code = R"NKSP_CODE(
7224 on init
7225 exit( lsb(1) )
7226 end on
7227 )NKSP_CODE",
7228 .expectIntExitResult = 1
7229 });
7230
7231 runScript({
7232 .code = R"NKSP_CODE(
7233 on init
7234 exit( lsb(126) )
7235 end on
7236 )NKSP_CODE",
7237 .expectIntExitResult = 126
7238 });
7239
7240 runScript({
7241 .code = R"NKSP_CODE(
7242 on init
7243 exit( lsb(127) )
7244 end on
7245 )NKSP_CODE",
7246 .expectIntExitResult = 127
7247 });
7248
7249 runScript({
7250 .code = R"NKSP_CODE(
7251 on init
7252 exit( lsb(128) )
7253 end on
7254 )NKSP_CODE",
7255 .expectIntExitResult = 0
7256 });
7257
7258 runScript({
7259 .code = R"NKSP_CODE(
7260 on init
7261 exit( lsb(16255) )
7262 end on
7263 )NKSP_CODE",
7264 .expectIntExitResult = 127
7265 });
7266
7267 runScript({
7268 .code = R"NKSP_CODE(
7269 on init
7270 exit( lsb(16256) )
7271 end on
7272 )NKSP_CODE",
7273 .expectIntExitResult = 0
7274 });
7275
7276 #if !SILENT_TEST
7277 std::cout << std::endl;
7278 #endif
7279 }
7280
7281 static void testBuiltInIntToRealFunction() {
7282 #if !SILENT_TEST
7283 std::cout << "UNIT TEST: built-in int_to_real() function\n";
7284 #endif
7285
7286 runScript({
7287 .code = R"NKSP_CODE(
7288 on init
7289 exit( int_to_real(8) )
7290 end on
7291 )NKSP_CODE",
7292 .expectRealExitResult = 8.0
7293 });
7294
7295 runScript({
7296 .code = R"NKSP_CODE(
7297 on init
7298 declare $foo := 23
7299 exit( int_to_real($foo) )
7300 end on
7301 )NKSP_CODE",
7302 .expectRealExitResult = 23.0
7303 });
7304
7305 // std unit tests ...
7306
7307 runScript({
7308 .code = R"NKSP_CODE(
7309 on init
7310 exit( int_to_real(-58mdB) )
7311 end on
7312 )NKSP_CODE",
7313 .expectRealExitResult = -58.0,
7314 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7315 .expectExitResultUnit = VM_BEL
7316 });
7317
7318 runScript({
7319 .code = R"NKSP_CODE(
7320 on init
7321 declare $foo := -58mdB
7322 exit( int_to_real($foo) )
7323 end on
7324 )NKSP_CODE",
7325 .expectRealExitResult = -58.0,
7326 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7327 .expectExitResultUnit = VM_BEL
7328 });
7329
7330 // 'final' ('!') operator tests ...
7331
7332 runScript({
7333 .code = R"NKSP_CODE(
7334 on init
7335 declare $foo := !-58
7336 exit( int_to_real($foo) )
7337 end on
7338 )NKSP_CODE",
7339 .expectRealExitResult = -58.0,
7340 .expectExitResultFinal = true
7341 });
7342
7343 runScript({
7344 .code = R"NKSP_CODE(
7345 on init
7346 declare $foo := -58
7347 exit( int_to_real($foo) )
7348 end on
7349 )NKSP_CODE",
7350 .expectRealExitResult = -58.0,
7351 .expectExitResultFinal = false
7352 });
7353
7354 #if !SILENT_TEST
7355 std::cout << std::endl;
7356 #endif
7357 }
7358
7359 static void testBuiltInRealFunction() {
7360 #if !SILENT_TEST
7361 std::cout << "UNIT TEST: built-in real() function\n";
7362 #endif
7363
7364 runScript({
7365 .code = R"NKSP_CODE(
7366 on init
7367 exit( real(8) )
7368 end on
7369 )NKSP_CODE",
7370 .expectRealExitResult = 8.0
7371 });
7372
7373 runScript({
7374 .code = R"NKSP_CODE(
7375 on init
7376 declare $foo := 23
7377 exit( real($foo) )
7378 end on
7379 )NKSP_CODE",
7380 .expectRealExitResult = 23.0
7381 });
7382
7383 // std unit tests ...
7384
7385 runScript({
7386 .code = R"NKSP_CODE(
7387 on init
7388 exit( real(-58mdB) )
7389 end on
7390 )NKSP_CODE",
7391 .expectRealExitResult = -58.0,
7392 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7393 .expectExitResultUnit = VM_BEL
7394 });
7395
7396 runScript({
7397 .code = R"NKSP_CODE(
7398 on init
7399 declare $foo := -58mdB
7400 exit( real($foo) )
7401 end on
7402 )NKSP_CODE",
7403 .expectRealExitResult = -58.0,
7404 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7405 .expectExitResultUnit = VM_BEL
7406 });
7407
7408 // 'final' ('!') operator tests ...
7409
7410 runScript({
7411 .code = R"NKSP_CODE(
7412 on init
7413 declare $foo := !-58
7414 exit( real($foo) )
7415 end on
7416 )NKSP_CODE",
7417 .expectRealExitResult = -58.0,
7418 .expectExitResultFinal = true
7419 });
7420
7421 runScript({
7422 .code = R"NKSP_CODE(
7423 on init
7424 declare $foo := -58
7425 exit( real($foo) )
7426 end on
7427 )NKSP_CODE",
7428 .expectRealExitResult = -58.0,
7429 .expectExitResultFinal = false
7430 });
7431
7432 #if !SILENT_TEST
7433 std::cout << std::endl;
7434 #endif
7435 }
7436
7437 static void testBuiltInRealToIntFunction() {
7438 #if !SILENT_TEST
7439 std::cout << "UNIT TEST: built-in real_to_int() function\n";
7440 #endif
7441
7442 runScript({
7443 .code = R"NKSP_CODE(
7444 on init
7445 exit( real_to_int(8.9) )
7446 end on
7447 )NKSP_CODE",
7448 .expectIntExitResult = 8
7449 });
7450
7451 runScript({
7452 .code = R"NKSP_CODE(
7453 on init
7454 declare ~foo := 8.9
7455 exit( real_to_int(~foo) )
7456 end on
7457 )NKSP_CODE",
7458 .expectIntExitResult = 8
7459 });
7460
7461 // std unit tests ...
7462
7463 runScript({
7464 .code = R"NKSP_CODE(
7465 on init
7466 declare ~foo := 8.9mdB
7467 exit( real_to_int(~foo) )
7468 end on
7469 )NKSP_CODE",
7470 .expectIntExitResult = 8,
7471 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7472 .expectExitResultUnit = VM_BEL
7473 });
7474
7475 // 'final' ('!') operator tests ...
7476
7477 runScript({
7478 .code = R"NKSP_CODE(
7479 on init
7480 declare ~foo := !8.9
7481 exit( real_to_int(~foo) )
7482 end on
7483 )NKSP_CODE",
7484 .expectIntExitResult = 8,
7485 .expectExitResultFinal = true
7486 });
7487
7488 runScript({
7489 .code = R"NKSP_CODE(
7490 on init
7491 declare ~foo := 8.9
7492 exit( real_to_int(~foo) )
7493 end on
7494 )NKSP_CODE",
7495 .expectIntExitResult = 8,
7496 .expectExitResultFinal = false
7497 });
7498
7499 #if !SILENT_TEST
7500 std::cout << std::endl;
7501 #endif
7502 }
7503
7504 static void testBuiltInIntFunction() {
7505 #if !SILENT_TEST
7506 std::cout << "UNIT TEST: built-in int() function\n";
7507 #endif
7508
7509 runScript({
7510 .code = R"NKSP_CODE(
7511 on init
7512 exit( int(8.9) )
7513 end on
7514 )NKSP_CODE",
7515 .expectIntExitResult = 8
7516 });
7517
7518 runScript({
7519 .code = R"NKSP_CODE(
7520 on init
7521 declare ~foo := 8.9
7522 exit( int(~foo) )
7523 end on
7524 )NKSP_CODE",
7525 .expectIntExitResult = 8
7526 });
7527
7528 // std unit tests ...
7529
7530 runScript({
7531 .code = R"NKSP_CODE(
7532 on init
7533 declare ~foo := 8.9mdB
7534 exit( int(~foo) )
7535 end on
7536 )NKSP_CODE",
7537 .expectIntExitResult = 8,
7538 .expectExitResultUnitPrefix = { VM_MILLI, VM_DECI },
7539 .expectExitResultUnit = VM_BEL
7540 });
7541
7542 // 'final' ('!') operator tests ...
7543
7544 runScript({
7545 .code = R"NKSP_CODE(
7546 on init
7547 declare ~foo := !8.9
7548 exit( int(~foo) )
7549 end on
7550 )NKSP_CODE",
7551 .expectIntExitResult = 8,
7552 .expectExitResultFinal = true
7553 });
7554
7555 runScript({
7556 .code = R"NKSP_CODE(
7557 on init
7558 declare ~foo := 8.9
7559 exit( int(~foo) )
7560 end on
7561 )NKSP_CODE",
7562 .expectIntExitResult = 8,
7563 .expectExitResultFinal = false
7564 });
7565
7566 #if !SILENT_TEST
7567 std::cout << std::endl;
7568 #endif
7569 }
7570
7571 static void testBuiltInArrayEqualFunction() {
7572 #if !SILENT_TEST
7573 std::cout << "UNIT TEST: built-in array_equal() function\n";
7574 #endif
7575
7576 // integer array tests ...
7577
7578 runScript({
7579 .code = R"NKSP_CODE(
7580 on init
7581 declare %foo[3] := ( 1, 2, 3 )
7582 declare %bar[3] := ( 1, 2, 3 )
7583 exit( array_equal(%foo, %bar) )
7584 end on
7585 )NKSP_CODE",
7586 .expectBoolExitResult = true
7587 });
7588
7589 runScript({
7590 .code = R"NKSP_CODE(
7591 on init
7592 declare %foo[1] := ( 1 )
7593 declare %bar[1] := ( 1 )
7594 exit( array_equal(%foo, %bar) )
7595 end on
7596 )NKSP_CODE",
7597 .expectBoolExitResult = true
7598 });
7599
7600 runScript({
7601 .code = R"NKSP_CODE(
7602 on init
7603 declare %foo[3] := ( 1, 2, 3 )
7604 declare %bar[3] := ( 0, 2, 3 )
7605 exit( array_equal(%foo, %bar) )
7606 end on
7607 )NKSP_CODE",
7608 .expectBoolExitResult = false
7609 });
7610
7611 runScript({
7612 .code = R"NKSP_CODE(
7613 on init
7614 declare %foo[3] := ( 1, 2, 3 )
7615 declare %bar[3] := ( 3, 2, 1 )
7616 exit( array_equal(%foo, %bar) )
7617 end on
7618 )NKSP_CODE",
7619 .expectBoolExitResult = false
7620 });
7621
7622 runScript({
7623 .code = R"NKSP_CODE(
7624 on init
7625 declare %foo[3] := ( 1, 2, 3 )
7626 declare %bar[2] := ( 1, 2 )
7627 exit( array_equal(%foo, %bar) )
7628 end on
7629 )NKSP_CODE",
7630 .expectBoolExitResult = false,
7631 .expectParseWarning = true // array_equal() warns if array sizes do not match
7632 });
7633
7634 // real number array tests ...
7635
7636 runScript({
7637 .code = R"NKSP_CODE(
7638 on init
7639 declare ?foo[3] := ( 1.0, 2.0, 3.0 )
7640 declare ?bar[3] := ( 1.0, 2.0, 3.0 )
7641 exit( array_equal(?foo, ?bar) )
7642 end on
7643 )NKSP_CODE",
7644 .expectBoolExitResult = true
7645 });
7646
7647 runScript({
7648 .code = R"NKSP_CODE(
7649 on init
7650 declare ?foo[3] := ( 1.0, 1.1, 3.4 )
7651 declare ?bar[3] := ( 1.0, 1.1, 3.4 )
7652 exit( array_equal(?foo, ?bar) )
7653 end on
7654 )NKSP_CODE",
7655 .expectBoolExitResult = true
7656 });
7657
7658 runScript({
7659 .code = R"NKSP_CODE(
7660 on init
7661 declare ?foo[3] := ( 1.0, 1.1, 3.4 )
7662 declare ?bar[3] := ( 1.0, 1.2, 3.4 )
7663 exit( array_equal(?foo, ?bar) )
7664 end on
7665 )NKSP_CODE",
7666 .expectBoolExitResult = false
7667 });
7668
7669 runScript({
7670 .code = R"NKSP_CODE(
7671 on init
7672 declare ?foo[3] := ( 1.0, 1.1, 3.4 )
7673 declare ?bar[2] := ( 1.0, 1.1 )
7674 exit( array_equal(?foo, ?bar) )
7675 end on
7676 )NKSP_CODE",
7677 .expectBoolExitResult = false,
7678 .expectParseWarning = true // array_equal() warns if array sizes do not match
7679 });
7680
7681 // std unit tests ...
7682 // (only metric prefixes allowed, unit types are prohibited for arrays ATM)
7683
7684 runScript({
7685 .code = R"NKSP_CODE(
7686 on init
7687 declare %foo[3] := ( 1, 1s, 1 )
7688 declare %bar[3] := ( 1, 1, 1 )
7689 exit( array_equal(%foo, %bar) )
7690 end on
7691 )NKSP_CODE",
7692 .expectParseError = true // see comment above
7693 });
7694
7695 runScript({
7696 .code = R"NKSP_CODE(
7697 on init
7698 declare %foo[3] := ( 1k, 1, 1m )
7699 declare %bar[3] := ( 1k, 1, 1m )
7700 exit( array_equal(%foo, %bar) )
7701 end on
7702 )NKSP_CODE",
7703 .expectBoolExitResult = true
7704 });
7705
7706 runScript({
7707 .code = R"NKSP_CODE(
7708 on init
7709 declare %foo[3] := ( 1m, 1, 1k )
7710 declare %bar[3] := ( 1k, 1, 1m )
7711 exit( array_equal(%foo, %bar) )
7712 end on
7713 )NKSP_CODE",
7714 .expectBoolExitResult = false
7715 });
7716
7717 runScript({
7718 .code = R"NKSP_CODE(
7719 on init
7720 declare %foo[3] := ( 1, 1k, 1 )
7721 declare %bar[3] := ( 1, 1, 1 )
7722 exit( array_equal(%foo, %bar) )
7723 end on
7724 )NKSP_CODE",
7725 .expectBoolExitResult = false
7726 });
7727
7728 runScript({
7729 .code = R"NKSP_CODE(
7730 on init
7731 declare %foo[3] := ( 1, 1k, 1 )
7732 declare %bar[3] := ( 1, 1000, 1 )
7733 exit( array_equal(%foo, %bar) )
7734 end on
7735 )NKSP_CODE",
7736 .expectBoolExitResult = true
7737 });
7738
7739 runScript({
7740 .code = R"NKSP_CODE(
7741 on init
7742 declare %foo[3] := ( 1, 2, 3000 )
7743 declare %bar[3] := ( 1, 2, 3k )
7744 exit( array_equal(%foo, %bar) )
7745 end on
7746 )NKSP_CODE",
7747 .expectBoolExitResult = true
7748 });
7749
7750 runScript({
7751 .code = R"NKSP_CODE(
7752 on init
7753 declare %foo[3] := ( 1, 2, 3m )
7754 declare %bar[3] := ( 1, 2, 3k )
7755 exit( array_equal(%foo, %bar) )
7756 end on
7757 )NKSP_CODE",
7758 .expectBoolExitResult = false
7759 });
7760
7761 runScript({
7762 .code = R"NKSP_CODE(
7763 on init
7764 declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
7765 declare ?bar[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
7766 exit( array_equal(?foo, ?bar) )
7767 end on
7768 )NKSP_CODE",
7769 .expectBoolExitResult = true
7770 });
7771
7772 runScript({
7773 .code = R"NKSP_CODE(
7774 on init
7775 declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
7776 declare ?bar[4] := ( 1.0, 1.0 , 1.1m, 3.4k )
7777 exit( array_equal(?foo, ?bar) )
7778 end on
7779 )NKSP_CODE",
7780 .expectBoolExitResult = false
7781 });
7782
7783 runScript({
7784 .code = R"NKSP_CODE(
7785 on init
7786 declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
7787 declare ?bar[4] := ( 1.0, 1.0m, 1.1k, 3.4k )
7788 exit( array_equal(?foo, ?bar) )
7789 end on
7790 )NKSP_CODE",
7791 .expectBoolExitResult = false
7792 });
7793
7794 runScript({
7795 .code = R"NKSP_CODE(
7796 on init
7797 declare ?foo[4] := ( 1.0, 1.0m, 1.1m, 3.4k )
7798 declare ?bar[4] := ( 1.0, 1.0m, 1.1m, 3.4u )
7799 exit( array_equal(?foo, ?bar) )
7800 end on
7801 )NKSP_CODE",
7802 .expectBoolExitResult = false
7803 });
7804
7805 runScript({
7806 .code = R"NKSP_CODE(
7807 on init
7808 declare ?foo[3] := ( 1.0, 1.0k, 1.1m )
7809 declare ?bar[3] := ( 1.0, 1000.0, 1.1m )
7810 exit( array_equal(?foo, ?bar) )
7811 end on
7812 )NKSP_CODE",
7813 .expectBoolExitResult = true
7814 });
7815
7816 runScript({
7817 .code = R"NKSP_CODE(
7818 on init
7819 declare ?foo[3] := ( 1.0, 1.0k, 1.1u )
7820 declare ?bar[3] := ( 1.0, 1000.0, 0.0011m )
7821 exit( array_equal(?foo, ?bar) )
7822 end on
7823 )NKSP_CODE",
7824 .expectBoolExitResult = true
7825 });
7826
7827 runScript({
7828 .code = R"NKSP_CODE(
7829 on init
7830 declare ?foo[3] := ( 1.0, 1.0k, 1.1u )
7831 declare ?bar[3] := ( 1.0, 1000.0, 0.0016m )
7832 exit( array_equal(?foo, ?bar) )
7833 end on
7834 )NKSP_CODE",
7835 .expectBoolExitResult = false
7836 });
7837
7838 // 'final' ('!') operator tests ...
7839 // (currently prohibited for arrays)
7840
7841 runScript({
7842 .code = R"NKSP_CODE(
7843 on init
7844 declare %foo[3] := ( !1, !1, !1 )
7845 declare %bar[3] := ( !1, !1, !1 )
7846 exit( array_equal(%foo, %bar) )
7847 end on
7848 )NKSP_CODE",
7849 .expectParseError = true // see comment above
7850 });
7851
7852 runScript({
7853 .code = R"NKSP_CODE(
7854 on init
7855 declare ?foo[3] := ( !1.0, !1.0, !1.0 )
7856 declare ?bar[3] := ( !1.0, !1.0, !1.0 )
7857 exit( array_equal(?foo, ?bar) )
7858 end on
7859 )NKSP_CODE",
7860 .expectParseError = true // see comment above
7861 });
7862
7863 #if !SILENT_TEST
7864 std::cout << std::endl;
7865 #endif
7866 }
7867
7868 static void testBuiltInSortFunction() {
7869 #if !SILENT_TEST
7870 std::cout << "UNIT TEST: built-in sort() function\n";
7871 #endif
7872
7873 // integer array tests ...
7874
7875 runScript({
7876 .code = R"NKSP_CODE(
7877 on init
7878 declare %input[3] := ( 19, 3, 6 )
7879 declare %expected[3] := ( 3, 6, 19 )
7880 sort(%input, 0)
7881 exit( array_equal(%input, %expected) )
7882 end on
7883 )NKSP_CODE",
7884 .expectBoolExitResult = true
7885 });
7886
7887 runScript({
7888 .code = R"NKSP_CODE(
7889 on init
7890 declare %input[3] := ( 19, 3, 6 )
7891 declare %expected[3] := ( 19, 6, 3 )
7892 sort(%input, 1)
7893 exit( array_equal(%input, %expected) )
7894 end on
7895 )NKSP_CODE",
7896 .expectBoolExitResult = true
7897 });
7898
7899 runScript({
7900 .code = R"NKSP_CODE(
7901 on init
7902 declare %input[6] := ( 1, 80, 120, 40, 3000, 20 )
7903 declare %expected[6] := ( 1, 20, 40, 80, 120, 3000 )
7904 sort(%input, 0)
7905 exit( array_equal(%input, %expected) )
7906 end on
7907 )NKSP_CODE",
7908 .expectBoolExitResult = true
7909 });
7910
7911 // real number array tests ...
7912
7913 runScript({
7914 .code = R"NKSP_CODE(
7915 on init
7916 declare ?input[4] := ( 1.4, 1.0, 13.4, 2.7 )
7917 declare ?expected[4] := ( 1.0, 1.4, 2.7, 13.4 )
7918 sort(?input, 0)
7919 exit( array_equal(?input, ?expected) )
7920 end on
7921 )NKSP_CODE",
7922 .expectBoolExitResult = true
7923 });
7924
7925 runScript({
7926 .code = R"NKSP_CODE(
7927 on init
7928 declare ?input[4] := ( 1.4, 1.0, 13.4, 2.7 )
7929 declare ?expected[4] := ( 13.4, 2.7, 1.4, 1.0 )
7930 sort(?input, 1)
7931 exit( array_equal(?input, ?expected) )
7932 end on
7933 )NKSP_CODE",
7934 .expectBoolExitResult = true
7935 });
7936
7937 // std unit tests ...
7938 // (only metric prefixes are allowed for arrays ATM)
7939
7940 runScript({
7941 .code = R"NKSP_CODE(
7942 on init
7943 declare %input[3] := ( 1k, 6, 900 )
7944 declare %expected[3] := ( 6, 900, 1k )
7945 sort(%input, 0)
7946 exit( array_equal(%input, %expected) )
7947 end on
7948 )NKSP_CODE",
7949 .expectBoolExitResult = true
7950 });
7951
7952 runScript({
7953 .code = R"NKSP_CODE(
7954 on init
7955 declare %input[3] := ( 900, 1k, 6 )
7956 declare %expected[3] := ( 1k, 900, 6 )
7957 sort(%input, 1)
7958 exit( array_equal(%input, %expected) )
7959 end on
7960 )NKSP_CODE",
7961 .expectBoolExitResult = true
7962 });
7963
7964 runScript({
7965 .code = R"NKSP_CODE(
7966 on init
7967 declare %input[6] := ( 1k, 8m, 4k, 12000u, 3000u, 1000u )
7968 declare %expected[6] := ( 1000u, 3000u, 8m, 12000u, 1k, 4k )
7969 sort(%input, 0)
7970 exit( array_equal(%input, %expected) )
7971 end on
7972 )NKSP_CODE",
7973 .expectBoolExitResult = true
7974 });
7975
7976 runScript({
7977 .code = R"NKSP_CODE(
7978 on init
7979 declare ?input[3] := ( 1.0k, 6.0, 900.0 )
7980 declare ?expected[3] := ( 6.0, 900.0, 1.0k )
7981 sort(?input, 0)
7982 exit( array_equal(?input, ?expected) )
7983 end on
7984 )NKSP_CODE",
7985 .expectBoolExitResult = true
7986 });
7987
7988 runScript({
7989 .code = R"NKSP_CODE(
7990 on init
7991 declare ?input[3] := ( 900.0, 1.0k, 6.0 )
7992 declare ?expected[3] := ( 1.0k, 900.0, 6.0 )
7993 sort(?input, 1)
7994 exit( array_equal(?input, ?expected) )
7995 end on
7996 )NKSP_CODE",
7997 .expectBoolExitResult = true
7998 });
7999
8000 runScript({
8001 .code = R"NKSP_CODE(
8002 on init
8003 declare ?input[3] := ( 1.0k, 0.9k, 1.1k )
8004 declare ?expected[3] := ( 0.9k, 1.0k, 1.1k )
8005 sort(?input, 0)
8006 exit( array_equal(?input, ?expected) )
8007 end on
8008 )NKSP_CODE",
8009 .expectBoolExitResult = true
8010 });
8011
8012 runScript({
8013 .code = R"NKSP_CODE(
8014 on init
8015 declare ?input[3] := ( 2.0m, 1000.1u, 1.0 )
8016 declare ?expected[3] := ( 1000.1u, 2.0m, 1.0 )
8017 sort(?input, 0)
8018 exit( array_equal(?input, ?expected) )
8019 end on
8020 )NKSP_CODE",
8021 .expectBoolExitResult = true
8022 });
8023
8024 runScript({
8025 .code = R"NKSP_CODE(
8026 on init
8027 declare ?input[4] := ( 2.0m, 1000.1u, 1.0, 1400.0u )
8028 declare ?expected[4] := ( 1000.1u, 1400.0u, 2.0m, 1.0 )
8029 sort(?input, 0)
8030 exit( array_equal(?input, ?expected) )
8031 end on
8032 )NKSP_CODE",
8033 .expectBoolExitResult = true
8034 });
8035
8036 runScript({
8037 .code = R"NKSP_CODE(
8038 on init
8039 declare ?input[4] := ( 2.0m, 1000.1u, 1.0, 1400.0u )
8040 declare ?expected[4] := ( 1.0, 2.0m, 1400.0u, 1000.1u )
8041 sort(?input, 1)
8042 exit( array_equal(?input, ?expected) )
8043 end on
8044 )NKSP_CODE",
8045 .expectBoolExitResult = true
8046 });
8047
8048 runScript({
8049 .code = R"NKSP_CODE(
8050 on init
8051 declare ?input[6] := ( 0.9k, 8.0m, 1.1k, 12000.0u, 3000.0u, 1000.0u )
8052 declare ?expected[6] := ( 1000.0u, 3000.0u, 8.0m, 12000.0u, 0.9k, 1.1k )
8053 sort(?input, 0)
8054 exit( array_equal(?input, ?expected) )
8055 end on
8056 )NKSP_CODE",
8057 .expectBoolExitResult = true
8058 });
8059
8060 runScript({
8061 .code = R"NKSP_CODE(
8062 on init
8063 declare ?input[6] := ( 0.9k, 8.0m, 1.1k, 12000.0u, 3000.0u, 1000.0u )
8064 declare ?expected[6] := ( 1.1k, 0.9k, 12000.0u, 8.0m, 3000.0u, 1000.0u )
8065 sort(?input, 1)
8066 exit( array_equal(?input, ?expected) )
8067 end on
8068 )NKSP_CODE",
8069 .expectBoolExitResult = true
8070 });
8071
8072 #if !SILENT_TEST
8073 std::cout << std::endl;
8074 #endif
8075 }
8076
8077 static void testBuiltInRoundFunction() {
8078 #if !SILENT_TEST
8079 std::cout << "UNIT TEST: built-in round() function\n";
8080 #endif
8081
8082 // integer tests ...
8083 // (ATM not allowed for this function)
8084
8085 runScript({
8086 .code = R"NKSP_CODE(
8087 on init
8088 declare $foo := 1
8089 exit( round($foo) )
8090 end on
8091 )NKSP_CODE",
8092 .expectParseError = true // integer not allowed for this function ATM
8093 });
8094
8095 // real number tests ...
8096
8097 runScript({
8098 .code = R"NKSP_CODE(
8099 on init
8100 exit( round(99.4) )
8101 end on
8102 )NKSP_CODE",
8103 .expectRealExitResult = 99.0
8104 });
8105
8106 runScript({
8107 .code = R"NKSP_CODE(
8108 on init
8109 exit( round(99.5) )
8110 end on
8111 )NKSP_CODE",
8112 .expectRealExitResult = 100.0
8113 });
8114
8115 // std unit tests ...
8116
8117 runScript({
8118 .code = R"NKSP_CODE(
8119 on init
8120 exit( round(2.4ms) )
8121 end on
8122 )NKSP_CODE",
8123 .expectRealExitResult = 2.0,
8124 .expectExitResultUnitPrefix = { VM_MILLI },
8125 .expectExitResultUnit = VM_SECOND
8126 });
8127
8128 runScript({
8129 .code = R"NKSP_CODE(
8130 on init
8131 exit( round(2.6kHz) )
8132 end on
8133 )NKSP_CODE",
8134 .expectRealExitResult = 3.0,
8135 .expectExitResultUnitPrefix = { VM_KILO },
8136 .expectExitResultUnit = VM_HERTZ
8137 });
8138
8139 // 'final' ('!') operator tests ...
8140
8141 runScript({
8142 .code = R"NKSP_CODE(
8143 on init
8144 exit( round(123.8) )
8145 end on
8146 )NKSP_CODE",
8147 .expectRealExitResult = 124.0,
8148 .expectExitResultFinal = false
8149 });
8150
8151 runScript({
8152 .code = R"NKSP_CODE(
8153 on init
8154 exit( round(!123.8) )
8155 end on
8156 )NKSP_CODE",
8157 .expectRealExitResult = 124.0,
8158 .expectExitResultFinal = true
8159 });
8160
8161 #if !SILENT_TEST
8162 std::cout << std::endl;
8163 #endif
8164 }
8165
8166 static void testBuiltInCeilFunction() {
8167 #if !SILENT_TEST
8168 std::cout << "UNIT TEST: built-in ceil() function\n";
8169 #endif
8170
8171 // integer tests ...
8172 // (ATM not allowed for this function)
8173
8174 runScript({
8175 .code = R"NKSP_CODE(
8176 on init
8177 declare $foo := 1
8178 exit( ceil($foo) )
8179 end on
8180 )NKSP_CODE",
8181 .expectParseError = true // integer not allowed for this function ATM
8182 });
8183
8184 // real number tests ...
8185
8186 runScript({
8187 .code = R"NKSP_CODE(
8188 on init
8189 exit( ceil(99.0) )
8190 end on
8191 )NKSP_CODE",
8192 .expectRealExitResult = 99.0
8193 });
8194
8195 runScript({
8196 .code = R"NKSP_CODE(
8197 on init
8198 exit( ceil(99.1) )
8199 end on
8200 )NKSP_CODE",
8201 .expectRealExitResult = 100.0
8202 });
8203
8204 runScript({
8205 .code = R"NKSP_CODE(
8206 on init
8207 exit( ceil(99.9) )
8208 end on
8209 )NKSP_CODE",
8210 .expectRealExitResult = 100.0
8211 });
8212
8213 // std unit tests ...
8214
8215 runScript({
8216 .code = R"NKSP_CODE(
8217 on init
8218 exit( ceil(2.4ms) )
8219 end on
8220 )NKSP_CODE",
8221 .expectRealExitResult = 3.0,
8222 .expectExitResultUnitPrefix = { VM_MILLI },
8223 .expectExitResultUnit = VM_SECOND
8224 });
8225
8226 runScript({
8227 .code = R"NKSP_CODE(
8228 on init
8229 exit( ceil(2.6kHz) )
8230 end on
8231 )NKSP_CODE",
8232 .expectRealExitResult = 3.0,
8233 .expectExitResultUnitPrefix = { VM_KILO },
8234 .expectExitResultUnit = VM_HERTZ
8235 });
8236
8237 // 'final' ('!') operator tests ...
8238
8239 runScript({
8240 .code = R"NKSP_CODE(
8241 on init
8242 exit( ceil(123.1) )
8243 end on
8244 )NKSP_CODE",
8245 .expectRealExitResult = 124.0,
8246 .expectExitResultFinal = false
8247 });
8248
8249 runScript({
8250 .code = R"NKSP_CODE(
8251 on init
8252 exit( ceil(!123.8) )
8253 end on
8254 )NKSP_CODE",
8255 .expectRealExitResult = 124.0,
8256 .expectExitResultFinal = true
8257 });
8258
8259 #if !SILENT_TEST
8260 std::cout << std::endl;
8261 #endif
8262 }
8263
8264 static void testBuiltInFloorFunction() {
8265 #if !SILENT_TEST
8266 std::cout << "UNIT TEST: built-in floor() function\n";
8267 #endif
8268
8269 // integer tests ...
8270 // (ATM not allowed for this function)
8271
8272 runScript({
8273 .code = R"NKSP_CODE(
8274 on init
8275 declare $foo := 1
8276 exit( floor($foo) )
8277 end on
8278 )NKSP_CODE",
8279 .expectParseError = true // integer not allowed for this function ATM
8280 });
8281
8282 // real number tests ...
8283
8284 runScript({
8285 .code = R"NKSP_CODE(
8286 on init
8287 exit( floor(99.0) )
8288 end on
8289 )NKSP_CODE",
8290 .expectRealExitResult = 99.0
8291 });
8292
8293 runScript({
8294 .code = R"NKSP_CODE(
8295 on init
8296 exit( floor(99.1) )
8297 end on
8298 )NKSP_CODE",
8299 .expectRealExitResult = 99.0
8300 });
8301
8302 runScript({
8303 .code = R"NKSP_CODE(
8304 on init
8305 exit( floor(99.9) )
8306 end on
8307 )NKSP_CODE",
8308 .expectRealExitResult = 99.0
8309 });
8310
8311 // std unit tests ...
8312
8313 runScript({
8314 .code = R"NKSP_CODE(
8315 on init
8316 exit( floor(2.4ms) )
8317 end on
8318 )NKSP_CODE",
8319 .expectRealExitResult = 2.0,
8320 .expectExitResultUnitPrefix = { VM_MILLI },
8321 .expectExitResultUnit = VM_SECOND
8322 });
8323
8324 runScript({
8325 .code = R"NKSP_CODE(
8326 on init
8327 exit( floor(2.6kHz) )
8328 end on
8329 )NKSP_CODE",
8330 .expectRealExitResult = 2.0,
8331 .expectExitResultUnitPrefix = { VM_KILO },
8332 .expectExitResultUnit = VM_HERTZ
8333 });
8334
8335 // 'final' ('!') operator tests ...
8336
8337 runScript({
8338 .code = R"NKSP_CODE(
8339 on init
8340 exit( floor(123.1) )
8341 end on
8342 )NKSP_CODE",
8343 .expectRealExitResult = 123.0,
8344 .expectExitResultFinal = false
8345 });
8346
8347 runScript({
8348 .code = R"NKSP_CODE(
8349 on init
8350 exit( floor(!123.8) )
8351 end on
8352 )NKSP_CODE",
8353 .expectRealExitResult = 123.0,
8354 .expectExitResultFinal = true
8355 });
8356
8357 #if !SILENT_TEST
8358 std::cout << std::endl;
8359 #endif
8360 }
8361
8362 static void testBuiltInSqrtFunction() {
8363 #if !SILENT_TEST
8364 std::cout << "UNIT TEST: built-in sqrt() function\n";
8365 #endif
8366
8367 // integer tests ...
8368 // (ATM not allowed for this function)
8369
8370 runScript({
8371 .code = R"NKSP_CODE(
8372 on init
8373 declare $foo := 1
8374 exit( sqrt($foo) )
8375 end on
8376 )NKSP_CODE",
8377 .expectParseError = true // integer not allowed for this function ATM
8378 });
8379
8380 // real number tests ...
8381
8382 runScript({
8383 .code = R"NKSP_CODE(
8384 on init
8385 exit( sqrt(36.0) )
8386 end on
8387 )NKSP_CODE",
8388 .expectRealExitResult = 6.0
8389 });
8390
8391 // std unit tests ...
8392
8393 runScript({
8394 .code = R"NKSP_CODE(
8395 on init
8396 exit( sqrt(100.0ms) )
8397 end on
8398 )NKSP_CODE",
8399 .expectRealExitResult = 10.0,
8400 .expectExitResultUnitPrefix = { VM_MILLI },
8401 .expectExitResultUnit = VM_SECOND
8402 });
8403
8404 runScript({
8405 .code = R"NKSP_CODE(
8406 on init
8407 exit( sqrt(5.76kHz) )
8408 end on
8409 )NKSP_CODE",
8410 .expectRealExitResult = 2.4,
8411 .expectExitResultUnitPrefix = { VM_KILO },
8412 .expectExitResultUnit = VM_HERTZ
8413 });
8414
8415 // 'final' ('!') operator tests ...
8416
8417 runScript({
8418 .code = R"NKSP_CODE(
8419 on init
8420 exit( sqrt(25.0) )
8421 end on
8422 )NKSP_CODE",
8423 .expectRealExitResult = 5.0,
8424 .expectExitResultFinal = false
8425 });
8426
8427 runScript({
8428 .code = R"NKSP_CODE(
8429 on init
8430 exit( sqrt(!25.0) )
8431 end on
8432 )NKSP_CODE",
8433 .expectRealExitResult = 5.0,
8434 .expectExitResultFinal = true
8435 });
8436
8437 #if !SILENT_TEST
8438 std::cout << std::endl;
8439 #endif
8440 }
8441
8442 static void testBuiltInLogFunction() {
8443 #if !SILENT_TEST
8444 std::cout << "UNIT TEST: built-in log() function\n";
8445 #endif
8446
8447 // integer tests ...
8448 // (ATM not allowed for this function)
8449
8450 runScript({
8451 .code = R"NKSP_CODE(
8452 on init
8453 declare $foo := 1
8454 exit( log($foo) )
8455 end on
8456 )NKSP_CODE",
8457 .expectParseError = true // integer not allowed for this function ATM
8458 });
8459
8460 // real number tests ...
8461
8462 runScript({
8463 .code = R"NKSP_CODE(
8464 on init
8465 exit( log(1.0) )
8466 end on
8467 )NKSP_CODE",
8468 .expectRealExitResult = 0.0
8469 });
8470
8471 runScript({
8472 .code = R"NKSP_CODE(
8473 on init
8474 exit( log(~NI_MATH_E) )
8475 end on
8476 )NKSP_CODE",
8477 .expectRealExitResult = 1.0
8478 });
8479
8480 // std unit tests ...
8481
8482 runScript({
8483 .code = R"NKSP_CODE(
8484 on init
8485 exit( log(~NI_MATH_E * 1.0ms) )
8486 end on
8487 )NKSP_CODE",
8488 .expectRealExitResult = 1.0,
8489 .expectExitResultUnitPrefix = { VM_MILLI },
8490 .expectExitResultUnit = VM_SECOND
8491 });
8492
8493 runScript({
8494 .code = R"NKSP_CODE(
8495 on init
8496 exit( log(~NI_MATH_E * 1.0kHz) )
8497 end on
8498 )NKSP_CODE",
8499 .expectRealExitResult = 1.0,
8500 .expectExitResultUnitPrefix = { VM_KILO },
8501 .expectExitResultUnit = VM_HERTZ
8502 });
8503
8504 // 'final' ('!') operator tests ...
8505
8506 runScript({
8507 .code = R"NKSP_CODE(
8508 on init
8509 exit( log(~NI_MATH_E * 1.0) )
8510 end on
8511 )NKSP_CODE",
8512 .expectRealExitResult = 1.0,
8513 .expectExitResultFinal = false
8514 });
8515
8516 runScript({
8517 .code = R"NKSP_CODE(
8518 on init
8519 exit( log(!(~NI_MATH_E * 1.0)) )
8520 end on
8521 )NKSP_CODE",
8522 .expectRealExitResult = 1.0,
8523 .expectExitResultFinal = true
8524 });
8525
8526 #if !SILENT_TEST
8527 std::cout << std::endl;
8528 #endif
8529 }
8530
8531 static void testBuiltInLog2Function() {
8532 #if !SILENT_TEST
8533 std::cout << "UNIT TEST: built-in log2() function\n";
8534 #endif
8535
8536 // integer tests ...
8537 // (ATM not allowed for this function)
8538
8539 runScript({
8540 .code = R"NKSP_CODE(
8541 on init
8542 declare $foo := 1
8543 exit( log2($foo) )
8544 end on
8545 )NKSP_CODE",
8546 .expectParseError = true // integer not allowed for this function ATM
8547 });
8548
8549 // real number tests ...
8550
8551 runScript({
8552 .code = R"NKSP_CODE(
8553 on init
8554 exit( log2(1.0) )
8555 end on
8556 )NKSP_CODE",
8557 .expectRealExitResult = 0.0
8558 });
8559
8560 runScript({
8561 .code = R"NKSP_CODE(
8562 on init
8563 exit( log2(32.0) )
8564 end on
8565 )NKSP_CODE",
8566 .expectRealExitResult = 5.0
8567 });
8568
8569 // std unit tests ...
8570
8571 runScript({
8572 .code = R"NKSP_CODE(
8573 on init
8574 exit( log2(32.0ms) )
8575 end on
8576 )NKSP_CODE",
8577 .expectRealExitResult = 5.0,
8578 .expectExitResultUnitPrefix = { VM_MILLI },
8579 .expectExitResultUnit = VM_SECOND
8580 });
8581
8582 runScript({
8583 .code = R"NKSP_CODE(
8584 on init
8585 exit( log2(32.0kHz) )
8586 end on
8587 )NKSP_CODE",
8588 .expectRealExitResult = 5.0,
8589 .expectExitResultUnitPrefix = { VM_KILO },
8590 .expectExitResultUnit = VM_HERTZ
8591 });
8592
8593 // 'final' ('!') operator tests ...
8594
8595 runScript({
8596 .code = R"NKSP_CODE(
8597 on init
8598 exit( log2(32.0) )
8599 end on
8600 )NKSP_CODE",
8601 .expectRealExitResult = 5.0,
8602 .expectExitResultFinal = false
8603 });
8604
8605 runScript({
8606 .code = R"NKSP_CODE(
8607 on init
8608 exit( log2(!32.0) )
8609 end on
8610 )NKSP_CODE",
8611 .expectRealExitResult = 5.0,
8612 .expectExitResultFinal = true
8613 });
8614
8615 #if !SILENT_TEST
8616 std::cout << std::endl;
8617 #endif
8618 }
8619
8620 static void testBuiltInLog10Function() {
8621 #if !SILENT_TEST
8622 std::cout << "UNIT TEST: built-in log10() function\n";
8623 #endif
8624
8625 // integer tests ...
8626 // (ATM not allowed for this function)
8627
8628 runScript({
8629 .code = R"NKSP_CODE(
8630 on init
8631 declare $foo := 1
8632 exit( log10($foo) )
8633 end on
8634 )NKSP_CODE",
8635 .expectParseError = true // integer not allowed for this function ATM
8636 });
8637
8638 // real number tests ...
8639
8640 runScript({
8641 .code = R"NKSP_CODE(
8642 on init
8643 exit( log10(1000.0) )
8644 end on
8645 )NKSP_CODE",
8646 .expectRealExitResult = 3.0
8647 });
8648
8649 runScript({
8650 .code = R"NKSP_CODE(
8651 on init
8652 exit( log10(1000.0) )
8653 end on
8654 )NKSP_CODE",
8655 .expectRealExitResult = 3.0
8656 });
8657
8658 // std unit tests ...
8659
8660 runScript({
8661 .code = R"NKSP_CODE(
8662 on init
8663 exit( log10(1000.0ms) )
8664 end on
8665 )NKSP_CODE",
8666 .expectRealExitResult = 3.0,
8667 .expectExitResultUnitPrefix = { VM_MILLI },
8668 .expectExitResultUnit = VM_SECOND
8669 });
8670
8671 runScript({
8672 .code = R"NKSP_CODE(
8673 on init
8674 exit( log10(1000.0kHz) )
8675 end on
8676 )NKSP_CODE",
8677 .expectRealExitResult = 3.0,
8678 .expectExitResultUnitPrefix = { VM_KILO },
8679 .expectExitResultUnit = VM_HERTZ
8680 });
8681
8682 // 'final' ('!') operator tests ...
8683
8684 runScript({
8685 .code = R"NKSP_CODE(
8686 on init
8687 exit( log10(1000.0) )
8688 end on
8689 )NKSP_CODE",
8690 .expectRealExitResult = 3.0,
8691 .expectExitResultFinal = false
8692 });
8693
8694 runScript({
8695 .code = R"NKSP_CODE(
8696 on init
8697 exit( log10(!1000.0) )
8698 end on
8699 )NKSP_CODE",
8700 .expectRealExitResult = 3.0,
8701 .expectExitResultFinal = true
8702 });
8703
8704 #if !SILENT_TEST
8705 std::cout << std::endl;
8706 #endif
8707 }
8708
8709 static void testBuiltInExpFunction() {
8710 #if !SILENT_TEST
8711 std::cout << "UNIT TEST: built-in exp() function\n";
8712 #endif
8713
8714 // integer tests ...
8715 // (ATM not allowed for this function)
8716
8717 runScript({
8718 .code = R"NKSP_CODE(
8719 on init
8720 declare $foo := 1
8721 exit( exp($foo) )
8722 end on
8723 )NKSP_CODE",
8724 .expectParseError = true // integer not allowed for this function ATM
8725 });
8726
8727 // real number tests ...
8728
8729 runScript({
8730 .code = R"NKSP_CODE(
8731 on init
8732 exit( exp(0.0) )
8733 end on
8734 )NKSP_CODE",
8735 .expectRealExitResult = 1.0
8736 });
8737
8738 runScript({
8739 .code = R"NKSP_CODE(
8740 on init
8741 exit( exp(1.0) )
8742 end on
8743 )NKSP_CODE",
8744 .expectRealExitResult = M_E
8745 });
8746
8747 // std unit tests ...
8748
8749 runScript({
8750 .code = R"NKSP_CODE(
8751 on init
8752 exit( exp(0.0ms) )
8753 end on
8754 )NKSP_CODE",
8755 .expectRealExitResult = 1.0,
8756 .expectExitResultUnitPrefix = { VM_MILLI },
8757 .expectExitResultUnit = VM_SECOND
8758 });
8759
8760 runScript({
8761 .code = R"NKSP_CODE(
8762 on init
8763 exit( exp(0.0kHz) )
8764 end on
8765 )NKSP_CODE",
8766 .expectRealExitResult = 1.0,
8767 .expectExitResultUnitPrefix = { VM_KILO },
8768 .expectExitResultUnit = VM_HERTZ
8769 });
8770
8771 // 'final' ('!') operator tests ...
8772
8773 runScript({
8774 .code = R"NKSP_CODE(
8775 on init
8776 exit( exp(0.0) )
8777 end on
8778 )NKSP_CODE",
8779 .expectRealExitResult = 1.0,
8780 .expectExitResultFinal = false
8781 });
8782
8783 runScript({
8784 .code = R"NKSP_CODE(
8785 on init
8786 exit( exp(!0.0) )
8787 end on
8788 )NKSP_CODE",
8789 .expectRealExitResult = 1.0,
8790 .expectExitResultFinal = true
8791 });
8792
8793 #if !SILENT_TEST
8794 std::cout << std::endl;
8795 #endif
8796 }
8797
8798 static void testBuiltInPowFunction() {
8799 #if !SILENT_TEST
8800 std::cout << "UNIT TEST: built-in pow() function\n";
8801 #endif
8802
8803 // integer tests ...
8804 // (ATM not allowed for this function)
8805
8806 runScript({
8807 .code = R"NKSP_CODE(
8808 on init
8809 declare $foo := 1
8810 exit( pow($foo,$foo) )
8811 end on
8812 )NKSP_CODE",
8813 .expectParseError = true // integer not allowed for this function ATM
8814 });
8815
8816 // real number tests ...
8817
8818 runScript({
8819 .code = R"NKSP_CODE(
8820 on init
8821 exit( pow(1.0) )
8822 end on
8823 )NKSP_CODE",
8824 .expectParseError = true // because pow() requires exactly 2 arguments
8825 });
8826
8827 runScript({
8828 .code = R"NKSP_CODE(
8829 on init
8830 exit( pow(3.0,4.0) )
8831 end on
8832 )NKSP_CODE",
8833 .expectRealExitResult = 81.0
8834 });
8835
8836 // std unit tests ...
8837
8838 runScript({
8839 .code = R"NKSP_CODE(
8840 on init
8841 exit( pow(3.0ms,4.0ms) )
8842 end on
8843 )NKSP_CODE",
8844 .expectParseError = true // because units are prohibited for 2nd argument
8845 });
8846
8847 runScript({
8848 .code = R"NKSP_CODE(
8849 on init
8850 exit( pow(3.0,4.0ms) )
8851 end on
8852 )NKSP_CODE",
8853 .expectParseError = true // because units are prohibited for 2nd argument
8854 });
8855
8856 runScript({
8857 .code = R"NKSP_CODE(
8858 on init
8859 exit( pow(3.0ms,4.0) )
8860 end on
8861 )NKSP_CODE",
8862 .expectRealExitResult = 81.0,
8863 .expectExitResultUnitPrefix = { VM_MILLI },
8864 .expectExitResultUnit = VM_SECOND
8865 });
8866
8867 runScript({
8868 .code = R"NKSP_CODE(
8869 on init
8870 exit( pow(3.0kHz,4.0) )
8871 end on
8872 )NKSP_CODE",
8873 .expectRealExitResult = 81.0,
8874 .expectExitResultUnitPrefix = { VM_KILO },
8875 .expectExitResultUnit = VM_HERTZ
8876 });
8877
8878 // 'final' ('!') operator tests ...
8879
8880 runScript({
8881 .code = R"NKSP_CODE(
8882 on init
8883 exit( pow(3.0,4.0) )
8884 end on
8885 )NKSP_CODE",
8886 .expectRealExitResult = 81.0,
8887 .expectExitResultFinal = false
8888 });
8889
8890 runScript({
8891 .code = R"NKSP_CODE(
8892 on init
8893 exit( pow(!3.0,4.0) )
8894 end on
8895 )NKSP_CODE",
8896 .expectRealExitResult = 81.0,
8897 .expectExitResultFinal = true
8898 });
8899
8900 runScript({
8901 .code = R"NKSP_CODE(
8902 on init
8903 exit( pow(3.0,!4.0) )
8904 end on
8905 )NKSP_CODE",
8906 .expectParseError = true // because 'final' is meaningless for 2nd argument
8907 });
8908
8909 #if !SILENT_TEST
8910 std::cout << std::endl;
8911 #endif
8912 }
8913
8914 static void testBuiltInSinFunction() {
8915 #if !SILENT_TEST
8916 std::cout << "UNIT TEST: built-in sin() function\n";
8917 #endif
8918
8919 // integer tests ...
8920 // (ATM not allowed for this function)
8921
8922 runScript({
8923 .code = R"NKSP_CODE(
8924 on init
8925 declare $foo := 1
8926 exit( sin($foo) )
8927 end on
8928 )NKSP_CODE",
8929 .expectParseError = true // integer not allowed for this function ATM
8930 });
8931
8932 // real number tests ...
8933
8934 runScript({
8935 .code = R"NKSP_CODE(
8936 on init
8937 exit( sin(0.0) )
8938 end on
8939 )NKSP_CODE",
8940 .expectRealExitResult = 0.0
8941 });
8942
8943 runScript({
8944 .code = R"NKSP_CODE(
8945 on init
8946 exit( sin(0.5 * ~NI_MATH_PI) )
8947 end on
8948 )NKSP_CODE",
8949 .expectRealExitResult = 1.0
8950 });
8951
8952 runScript({
8953 .code = R"NKSP_CODE(
8954 on init
8955 exit( sin(~NI_MATH_PI) )
8956 end on
8957 )NKSP_CODE",
8958 .expectRealExitResult = 0.0
8959 });
8960
8961 runScript({
8962 .code = R"NKSP_CODE(
8963 on init
8964 exit( sin(1.5 * ~NI_MATH_PI) )
8965 end on
8966 )NKSP_CODE",
8967 .expectRealExitResult = -1.0
8968 });
8969
8970 // std unit tests ...
8971
8972 runScript({
8973 .code = R"NKSP_CODE(
8974 on init
8975 exit( sin(0.0ms) )
8976 end on
8977 )NKSP_CODE",
8978 .expectRealExitResult = 0.0,
8979 .expectExitResultUnitPrefix = { VM_MILLI },
8980 .expectExitResultUnit = VM_SECOND
8981 });
8982
8983 runScript({
8984 .code = R"NKSP_CODE(
8985 on init
8986 exit( sin(0.0kHz) )
8987 end on
8988 )NKSP_CODE",
8989 .expectRealExitResult = 0.0,
8990 .expectExitResultUnitPrefix = { VM_KILO },
8991 .expectExitResultUnit = VM_HERTZ
8992 });
8993
8994 // 'final' ('!') operator tests ...
8995
8996 runScript({
8997 .code = R"NKSP_CODE(
8998 on init
8999 exit( sin(0.0) )
9000 end on
9001 )NKSP_CODE",
9002 .expectRealExitResult = 0.0,
9003 .expectExitResultFinal = false
9004 });
9005
9006 runScript({
9007 .code = R"NKSP_CODE(
9008 on init
9009 exit( sin(!0.0) )
9010 end on
9011 )NKSP_CODE",
9012 .expectRealExitResult = 0.0,
9013 .expectExitResultFinal = true
9014 });
9015
9016 #if !SILENT_TEST
9017 std::cout << std::endl;
9018 #endif
9019 }
9020
9021 static void testBuiltInCosFunction() {
9022 #if !SILENT_TEST
9023 std::cout << "UNIT TEST: built-in cos() function\n";
9024 #endif
9025
9026 // integer tests ...
9027 // (ATM not allowed for this function)
9028
9029 runScript({
9030 .code = R"NKSP_CODE(
9031 on init
9032 declare $foo := 1
9033 exit( cos($foo) )
9034 end on
9035 )NKSP_CODE",
9036 .expectParseError = true // integer not allowed for this function ATM
9037 });
9038
9039 // real number tests ...
9040
9041 runScript({
9042 .code = R"NKSP_CODE(
9043 on init
9044 exit( cos(0.0) )
9045 end on
9046 )NKSP_CODE",
9047 .expectRealExitResult = 1.0
9048 });
9049
9050 runScript({
9051 .code = R"NKSP_CODE(
9052 on init
9053 exit( cos(0.5 * ~NI_MATH_PI) )
9054 end on
9055 )NKSP_CODE",
9056 .expectRealExitResult = 0.0
9057 });
9058
9059 runScript({
9060 .code = R"NKSP_CODE(
9061 on init
9062 exit( cos(~NI_MATH_PI) )
9063 end on
9064 )NKSP_CODE",
9065 .expectRealExitResult = -1.0
9066 });
9067
9068 runScript({
9069 .code = R"NKSP_CODE(
9070 on init
9071 exit( cos(1.5 * ~NI_MATH_PI) )
9072 end on
9073 )NKSP_CODE",
9074 .expectRealExitResult = 0.0
9075 });
9076
9077 // std unit tests ...
9078
9079 runScript({
9080 .code = R"NKSP_CODE(
9081 on init
9082 exit( cos(0.0ms) )
9083 end on
9084 )NKSP_CODE",
9085 .expectRealExitResult = 1.0,
9086 .expectExitResultUnitPrefix = { VM_MILLI },
9087 .expectExitResultUnit = VM_SECOND
9088 });
9089
9090 runScript({
9091 .code = R"NKSP_CODE(
9092 on init
9093 exit( cos(0.0kHz) )
9094 end on
9095 )NKSP_CODE",
9096 .expectRealExitResult = 1.0,
9097 .expectExitResultUnitPrefix = { VM_KILO },
9098 .expectExitResultUnit = VM_HERTZ
9099 });
9100
9101 // 'final' ('!') operator tests ...
9102
9103 runScript({
9104 .code = R"NKSP_CODE(
9105 on init
9106 exit( cos(0.0) )
9107 end on
9108 )NKSP_CODE",
9109 .expectRealExitResult = 1.0,
9110 .expectExitResultFinal = false
9111 });
9112
9113 runScript({
9114 .code = R"NKSP_CODE(
9115 on init
9116 exit( cos(!0.0) )
9117 end on
9118 )NKSP_CODE",
9119 .expectRealExitResult = 1.0,
9120 .expectExitResultFinal = true
9121 });
9122
9123 #if !SILENT_TEST
9124 std::cout << std::endl;
9125 #endif
9126 }
9127
9128 static void testBuiltInTanFunction() {
9129 #if !SILENT_TEST
9130 std::cout << "UNIT TEST: built-in tan() function\n";
9131 #endif
9132
9133 // integer tests ...
9134 // (ATM not allowed for this function)
9135
9136 runScript({
9137 .code = R"NKSP_CODE(
9138 on init
9139 declare $foo := 1
9140 exit( tan($foo) )
9141 end on
9142 )NKSP_CODE",
9143 .expectParseError = true // integer not allowed for this function ATM
9144 });
9145
9146 // real number tests ...
9147
9148 runScript({
9149 .code = R"NKSP_CODE(
9150 on init
9151 exit( tan(0.0) )
9152 end on
9153 )NKSP_CODE",
9154 .expectRealExitResult = 0.0
9155 });
9156
9157 runScript({
9158 .code = R"NKSP_CODE(
9159 on init
9160 exit( tan(0.25 * ~NI_MATH_PI) )
9161 end on
9162 )NKSP_CODE",
9163 .expectRealExitResult = 1.0
9164 });
9165
9166 // std unit tests ...
9167
9168 runScript({
9169 .code = R"NKSP_CODE(
9170 on init
9171 exit( tan(0.0ms) )
9172 end on
9173 )NKSP_CODE",
9174 .expectRealExitResult = 0.0,
9175 .expectExitResultUnitPrefix = { VM_MILLI },
9176 .expectExitResultUnit = VM_SECOND
9177 });
9178
9179 runScript({
9180 .code = R"NKSP_CODE(
9181 on init
9182 exit( tan(0.0kHz) )
9183 end on
9184 )NKSP_CODE",
9185 .expectRealExitResult = 0.0,
9186 .expectExitResultUnitPrefix = { VM_KILO },
9187 .expectExitResultUnit = VM_HERTZ
9188 });
9189
9190 // 'final' ('!') operator tests ...
9191
9192 runScript({
9193 .code = R"NKSP_CODE(
9194 on init
9195 exit( tan(0.0) )
9196 end on
9197 )NKSP_CODE",
9198 .expectRealExitResult = 0.0,
9199 .expectExitResultFinal = false
9200 });
9201
9202 runScript({
9203 .code = R"NKSP_CODE(
9204 on init
9205 exit( tan(!0.0) )
9206 end on
9207 )NKSP_CODE",
9208 .expectRealExitResult = 0.0,
9209 .expectExitResultFinal = true
9210 });
9211
9212 #if !SILENT_TEST
9213 std::cout << std::endl;
9214 #endif
9215 }
9216
9217 static void testBuiltInAsinFunction() {
9218 #if !SILENT_TEST
9219 std::cout << "UNIT TEST: built-in asin() function\n";
9220 #endif
9221
9222 // integer tests ...
9223 // (ATM not allowed for this function)
9224
9225 runScript({
9226 .code = R"NKSP_CODE(
9227 on init
9228 declare $foo := 1
9229 exit( asin($foo) )
9230 end on
9231 )NKSP_CODE",
9232 .expectParseError = true // integer not allowed for this function ATM
9233 });
9234
9235 // real number tests ...
9236
9237 runScript({
9238 .code = R"NKSP_CODE(
9239 on init
9240 exit( asin(0.0) )
9241 end on
9242 )NKSP_CODE",
9243 .expectRealExitResult = 0.0
9244 });
9245
9246 runScript({
9247 .code = R"NKSP_CODE(
9248 on init
9249 exit( asin(1.0) )
9250 end on
9251 )NKSP_CODE",
9252 .expectRealExitResult = 0.5 * M_PI
9253 });
9254
9255 runScript({
9256 .code = R"NKSP_CODE(
9257 on init
9258 exit( asin(-1.0) )
9259 end on
9260 )NKSP_CODE",
9261 .expectRealExitResult = -0.5 * M_PI
9262 });
9263
9264 // std unit tests ...
9265
9266 runScript({
9267 .code = R"NKSP_CODE(
9268 on init
9269 exit( asin(0.0ms) )
9270 end on
9271 )NKSP_CODE",
9272 .expectRealExitResult = 0.0,
9273 .expectExitResultUnitPrefix = { VM_MILLI },
9274 .expectExitResultUnit = VM_SECOND
9275 });
9276
9277 runScript({
9278 .code = R"NKSP_CODE(
9279 on init
9280 exit( asin(0.0kHz) )
9281 end on
9282 )NKSP_CODE",
9283 .expectRealExitResult = 0.0,
9284 .expectExitResultUnitPrefix = { VM_KILO },
9285 .expectExitResultUnit = VM_HERTZ
9286 });
9287
9288 // 'final' ('!') operator tests ...
9289
9290 runScript({
9291 .code = R"NKSP_CODE(
9292 on init
9293 exit( asin(0.0) )
9294 end on
9295 )NKSP_CODE",
9296 .expectRealExitResult = 0.0,
9297 .expectExitResultFinal = false
9298 });
9299
9300 runScript({
9301 .code = R"NKSP_CODE(
9302 on init
9303 exit( asin(!0.0) )
9304 end on
9305 )NKSP_CODE",
9306 .expectRealExitResult = 0.0,
9307 .expectExitResultFinal = true
9308 });
9309
9310 #if !SILENT_TEST
9311 std::cout << std::endl;
9312 #endif
9313 }
9314
9315 static void testBuiltInAcosFunction() {
9316 #if !SILENT_TEST
9317 std::cout << "UNIT TEST: built-in acos() function\n";
9318 #endif
9319
9320 // integer tests ...
9321 // (ATM not allowed for this function)
9322
9323 runScript({
9324 .code = R"NKSP_CODE(
9325 on init
9326 declare $foo := 1
9327 exit( acos($foo) )
9328 end on
9329 )NKSP_CODE",
9330 .expectParseError = true // integer not allowed for this function ATM
9331 });
9332
9333 // real number tests ...
9334
9335 runScript({
9336 .code = R"NKSP_CODE(
9337 on init
9338 exit( acos(1.0) )
9339 end on
9340 )NKSP_CODE",
9341 .expectRealExitResult = 0.0
9342 });
9343
9344 runScript({
9345 .code = R"NKSP_CODE(
9346 on init
9347 exit( acos(0.0) )
9348 end on
9349 )NKSP_CODE",
9350 .expectRealExitResult = 0.5 * M_PI
9351 });
9352
9353 runScript({
9354 .code = R"NKSP_CODE(
9355 on init
9356 exit( acos(-1.0) )
9357 end on
9358 )NKSP_CODE",
9359 .expectRealExitResult = M_PI
9360 });
9361
9362 // std unit tests ...
9363
9364 runScript({
9365 .code = R"NKSP_CODE(
9366 on init
9367 exit( acos(1.0ms) )
9368 end on
9369 )NKSP_CODE",
9370 .expectRealExitResult = 0.0,
9371 .expectExitResultUnitPrefix = { VM_MILLI },
9372 .expectExitResultUnit = VM_SECOND
9373 });
9374
9375 runScript({
9376 .code = R"NKSP_CODE(
9377 on init
9378 exit( acos(1.0kHz) )
9379 end on
9380 )NKSP_CODE",
9381 .expectRealExitResult = 0.0,
9382 .expectExitResultUnitPrefix = { VM_KILO },
9383 .expectExitResultUnit = VM_HERTZ
9384 });
9385
9386 // 'final' ('!') operator tests ...
9387
9388 runScript({
9389 .code = R"NKSP_CODE(
9390 on init
9391 exit( acos(1.0) )
9392 end on
9393 )NKSP_CODE",
9394 .expectRealExitResult = 0.0,
9395 .expectExitResultFinal = false
9396 });
9397
9398 runScript({
9399 .code = R"NKSP_CODE(
9400 on init
9401 exit( acos(!1.0) )
9402 end on
9403 )NKSP_CODE",
9404 .expectRealExitResult = 0.0,
9405 .expectExitResultFinal = true
9406 });
9407
9408 #if !SILENT_TEST
9409 std::cout << std::endl;
9410 #endif
9411 }
9412
9413 static void testBuiltInAtanFunction() {
9414 #if !SILENT_TEST
9415 std::cout << "UNIT TEST: built-in atan() function\n";
9416 #endif
9417
9418 // integer tests ...
9419 // (ATM not allowed for this function)
9420
9421 runScript({
9422 .code = R"NKSP_CODE(
9423 on init
9424 declare $foo := 1
9425 exit( atan($foo) )
9426 end on
9427 )NKSP_CODE",
9428 .expectParseError = true // integer not allowed for this function ATM
9429 });
9430
9431 // real number tests ...
9432
9433 runScript({
9434 .code = R"NKSP_CODE(
9435 on init
9436 exit( atan(0.0) )
9437 end on
9438 )NKSP_CODE",
9439 .expectRealExitResult = 0.0
9440 });
9441
9442 runScript({
9443 .code = R"NKSP_CODE(
9444 on init
9445 exit( atan(1.0) )
9446 end on
9447 )NKSP_CODE",
9448 .expectRealExitResult = 0.25 * M_PI
9449 });
9450
9451 // std unit tests ...
9452
9453 runScript({
9454 .code = R"NKSP_CODE(
9455 on init
9456 exit( atan(0.0ms) )
9457 end on
9458 )NKSP_CODE",
9459 .expectRealExitResult = 0.0,
9460 .expectExitResultUnitPrefix = { VM_MILLI },
9461 .expectExitResultUnit = VM_SECOND
9462 });
9463
9464 runScript({
9465 .code = R"NKSP_CODE(
9466 on init
9467 exit( atan(0.0kHz) )
9468 end on
9469 )NKSP_CODE",
9470 .expectRealExitResult = 0.0,
9471 .expectExitResultUnitPrefix = { VM_KILO },
9472 .expectExitResultUnit = VM_HERTZ
9473 });
9474
9475 // 'final' ('!') operator tests ...
9476
9477 runScript({
9478 .code = R"NKSP_CODE(
9479 on init
9480 exit( atan(0.0) )
9481 end on
9482 )NKSP_CODE",
9483 .expectRealExitResult = 0.0,
9484 .expectExitResultFinal = false
9485 });
9486
9487 runScript({
9488 .code = R"NKSP_CODE(
9489 on init
9490 exit( atan(!0.0) )
9491 end on
9492 )NKSP_CODE",
9493 .expectRealExitResult = 0.0,
9494 .expectExitResultFinal = true
9495 });
9496
9497 #if !SILENT_TEST
9498 std::cout << std::endl;
9499 #endif
9500 }
9501
9502 static void testBuiltInNumElementsFunction() {
9503 #if !SILENT_TEST
9504 std::cout << "UNIT TEST: built-in num_elements() function\n";
9505 #endif
9506
9507 // integer array tests ...
9508
9509 runScript({
9510 .code = R"NKSP_CODE(
9511 on init
9512 declare %foo[3] := ( 19, 3, 6 )
9513 exit( num_elements(%foo) )
9514 end on
9515 )NKSP_CODE",
9516 .expectIntExitResult = 3
9517 });
9518
9519 runScript({
9520 .code = R"NKSP_CODE(
9521 on init
9522 declare %foo[1] := ( 19 )
9523 exit( num_elements(%foo) )
9524 end on
9525 )NKSP_CODE",
9526 .expectIntExitResult = 1
9527 });
9528
9529 runScript({
9530 .code = R"NKSP_CODE(
9531 on init
9532 declare %foo[5] := ( 1, 2, 3, 4, 5 )
9533 exit( num_elements(%foo) )
9534 end on
9535 )NKSP_CODE",
9536 .expectIntExitResult = 5
9537 });
9538
9539 // real array tests ...
9540
9541 runScript({
9542 .code = R"NKSP_CODE(
9543 on init
9544 declare ?foo[3] := ( 19.0, 3.2, 6.5 )
9545 exit( num_elements(?foo) )
9546 end on
9547 )NKSP_CODE",
9548 .expectIntExitResult = 3
9549 });
9550
9551 runScript({
9552 .code = R"NKSP_CODE(
9553 on init
9554 declare ?foo[1] := ( 19.0 )
9555 exit( num_elements(?foo) )
9556 end on
9557 )NKSP_CODE",
9558 .expectIntExitResult = 1
9559 });
9560
9561 runScript({
9562 .code = R"NKSP_CODE(
9563 on init
9564 declare ?foo[5] := ( 1.1, 2.2, 3.3, 4.4, 5.5 )
9565 exit( num_elements(?foo) )
9566 end on
9567 )NKSP_CODE",
9568 .expectIntExitResult = 5
9569 });
9570
9571 #if !SILENT_TEST
9572 std::cout << std::endl;
9573 #endif
9574 }
9575
9576 static void testBuiltInSearchFunction() {
9577 #if !SILENT_TEST
9578 std::cout << "UNIT TEST: built-in search() function\n";
9579 #endif
9580
9581 // integer array tests ...
9582
9583 runScript({
9584 .code = R"NKSP_CODE(
9585 on init
9586 declare %foo[3] := ( 19, 3, 6 )
9587 exit( search(%foo, 19) )
9588 end on
9589 )NKSP_CODE",
9590 .expectIntExitResult = 0
9591 });
9592
9593 runScript({
9594 .code = R"NKSP_CODE(
9595 on init
9596 declare %foo[3] := ( 19, 3, 6 )
9597 exit( search(%foo, 3) )
9598 end on
9599 )NKSP_CODE",
9600 .expectIntExitResult = 1
9601 });
9602
9603 runScript({
9604 .code = R"NKSP_CODE(
9605 on init
9606 declare %foo[3] := ( 19, 3, 6 )
9607 exit( search(%foo, 6) )
9608 end on
9609 )NKSP_CODE",
9610 .expectIntExitResult = 2
9611 });
9612
9613 runScript({
9614 .code = R"NKSP_CODE(
9615 on init
9616 declare %foo[3] := ( 19, 3, 6 )
9617 exit( search(%foo, 2) )
9618 end on
9619 )NKSP_CODE",
9620 .expectIntExitResult = -1
9621 });
9622
9623 // real array tests ...
9624
9625 runScript({
9626 .code = R"NKSP_CODE(
9627 on init
9628 declare ?foo[3] := ( 19.12, 3.45, 6.89 )
9629 exit( search(?foo, 19.12) )
9630 end on
9631 )NKSP_CODE",
9632 .expectIntExitResult = 0
9633 });
9634
9635 runScript({
9636 .code = R"NKSP_CODE(
9637 on init
9638 declare ?foo[3] := ( 19.12, 3.45, 6.89 )
9639 exit( search(?foo, 3.45) )
9640 end on
9641 )NKSP_CODE",
9642 .expectIntExitResult = 1
9643 });
9644
9645 runScript({
9646 .code = R"NKSP_CODE(
9647 on init
9648 declare ?foo[3] := ( 19.12, 3.45, 6.89 )
9649 exit( search(?foo, 6.89) )
9650 end on
9651 )NKSP_CODE",
9652 .expectIntExitResult = 2
9653 });
9654
9655 runScript({
9656 .code = R"NKSP_CODE(
9657 on init
9658 declare ?foo[3] := ( 19.12, 3.45, 6.89 )
9659 exit( search(?foo, 6.99) )
9660 end on
9661 )NKSP_CODE",
9662 .expectIntExitResult = -1
9663 });
9664
9665 #if !SILENT_TEST
9666 std::cout << std::endl;
9667 #endif
9668 }
9669
9670 static void testIfStatement() {
9671 #if !SILENT_TEST
9672 std::cout << "UNIT TEST: if statement\n";
9673 #endif
9674
9675 runScript({
9676 .code = R"NKSP_CODE(
9677 on init
9678 declare $foo := 1
9679 if ($foo)
9680 exit(42)
9681 end if
9682 end on
9683 )NKSP_CODE",
9684 .expectIntExitResult = 42
9685 });
9686
9687 runScript({
9688 .code = R"NKSP_CODE(
9689 on init
9690 declare $foo := 0
9691 if ($foo)
9692 exit(42)
9693 end if
9694 exit(3)
9695 end on
9696 )NKSP_CODE",
9697 .expectIntExitResult = 3
9698 });
9699
9700 runScript({
9701 .code = R"NKSP_CODE(
9702 on init
9703 declare $foo := 1
9704 if ($foo)
9705 exit(42)
9706 else
9707 exit(3)
9708 end if
9709 end on
9710 )NKSP_CODE",
9711 .expectIntExitResult = 42
9712 });
9713
9714 runScript({
9715 .code = R"NKSP_CODE(
9716 on init
9717 declare $foo := 0
9718 if ($foo)
9719 exit(42)
9720 else
9721 exit(3)
9722 end if
9723 end on
9724 )NKSP_CODE",
9725 .expectIntExitResult = 3
9726 });
9727
9728 #if !SILENT_TEST
9729 std::cout << std::endl;
9730 #endif
9731 }
9732
9733 static void testWhileStatement() {
9734 #if !SILENT_TEST
9735 std::cout << "UNIT TEST: while statement\n";
9736 #endif
9737
9738 runScript({
9739 .code = R"NKSP_CODE(
9740 on init
9741 declare $foo := 100
9742 declare $i := 50
9743 while ($i)
9744 $foo := $foo + 1
9745 $i := $i - 1
9746 end while
9747 exit($foo)
9748 end on
9749 )NKSP_CODE",
9750 .expectIntExitResult = 150
9751 });
9752
9753 #if !SILENT_TEST
9754 std::cout << std::endl;
9755 #endif
9756 }
9757
9758 #if !NO_MAIN
9759
9760 int main() {
9761 testBuiltInExitFunction();
9762 testStringConcatOperator();
9763 testNegOperator();
9764 testPlusOperator();
9765 testMinusOperator();
9766 testModuloOperator();
9767 testMultiplyOperator();
9768 testDivideOperator();
9769 testSmallerThanOperator();
9770 testGreaterThanOperator();
9771 testSmallerOrEqualOperator();
9772 testGreaterOrEqualOperator();
9773 testEqualOperator();
9774 testUnequalOperator();
9775 testLogicalAndOperator();
9776 testLogicalOrOperator();
9777 testLogicalNotOperator();
9778 testBitwiseAndOperator();
9779 testBitwiseOrOperator();
9780 testBitwiseNotOperator();
9781 testPrecedenceOfOperators();
9782 testBuiltInMinFunction();
9783 testBuiltInMaxFunction();
9784 testBuiltInAbsFunction();
9785 testBuiltInIncFunction();
9786 testBuiltInDecFunction();
9787 testBuiltInInRangeFunction();
9788 testBuiltInRandomFunction();
9789 testBuiltInShiftLeftFunction();
9790 testBuiltInShiftRightFunction();
9791 testBuiltInMsbFunction();
9792 testBuiltInLsbFunction();
9793 testBuiltInIntToRealFunction();
9794 testBuiltInRealFunction();
9795 testBuiltInRealToIntFunction();
9796 testBuiltInIntFunction();
9797 testBuiltInRoundFunction();
9798 testBuiltInCeilFunction();
9799 testBuiltInFloorFunction();
9800 testBuiltInSqrtFunction();
9801 testBuiltInLogFunction();
9802 testBuiltInLog2Function();
9803 testBuiltInLog10Function();
9804 testBuiltInExpFunction();
9805 testBuiltInPowFunction();
9806 testBuiltInSinFunction();
9807 testBuiltInCosFunction();
9808 testBuiltInTanFunction();
9809 testBuiltInAsinFunction();
9810 testBuiltInAcosFunction();
9811 testBuiltInAtanFunction();
9812 testBuiltInArrayEqualFunction();
9813 testBuiltInSortFunction();
9814 testBuiltInNumElementsFunction();
9815 testBuiltInSearchFunction();
9816 testIfStatement();
9817 testWhileStatement();
9818 std::cout << "\nAll tests passed successfully. :-)\n";
9819 return 0;
9820 }
9821
9822 #endif // !NO_MAIN

  ViewVC Help
Powered by ViewVC