-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
1680 lines (1618 loc) · 83.4 KB
/
Copy pathindex.html
File metadata and controls
1680 lines (1618 loc) · 83.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>gs-utils: tests</title>
<style>
body {
color-scheme: dark;
color: #fff;
background-color: #000;
}
#square1,
#square2 {
width: 32px;
height: 18px;
background-color: gray;
}
#square2 {
background-color: darkblue;
}
#square3 {
width: 50%;
height: 50%;
background-color: gray;
}
.circle1,
.circle2 {
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #00abff;
}
</style>
</head>
<body>
<!-- ....................................................................... -->
<div id="square1"></div><br/>
<div id="square2">
lorem
<div id="square3"></div>
<div class="circle1"></div>
</div><br/>
<div class="circle1" data-foo data-bar data-bar2></div><br/>
<div class="circle2" data-a="21" data-b="abc" data-c data-d="-3.14"></div>
<div id="classes"></div>
<div id="eljq_1">
<div class="a"></div>
<div class="b"></div>
<div class="b"></div>
</div>
<div id="eljq_2">
<div class="a"></div>
<div class="b"></div>
<div class="b"></div>
</div>
<!-- ....................................................................... -->
<script src="gs-utils.js"></script>
<script src="gs-utils-func.js"></script>
<script src="gs-utils-math.js"></script>
<script src="gs-utils-json.js"></script>
<script src="gs-utils-audio.js"></script>
<script src="gs-utils-jquery.js"></script>
<!-- ....................................................................... -->
<script>
function qS( el, sel ) {
return sel
? el.querySelector( sel )
: document.querySelector( el );
}
function qSA( el, sel ) {
return sel
? el.querySelectorAll( sel )
: document.querySelectorAll( el );
}
let nbGroups = 0;
let nbTests = 0;
let nbTestsOk = 0;
let toWait = 0;
async function tests( name, fn ) {
++toWait;
++nbGroups;
await fn( name );
--toWait;
}
function test( id, val, expected ) {
++nbTests;
if ( GSUisEqual( val, expected ) ) {
++nbTestsOk;
} else {
console.log( `test:${ id }`, val, "!==", expected );
}
}
function testStrict( id, val, expected ) {
++nbTests;
if ( Object.is( val, expected ) ) {
++nbTestsOk;
} else {
console.log( `testStrict:${ id }`, val, "!==", expected );
}
}
</script>
<!-- ....................................................................... -->
<!-- ..... gs-utils-math ................................................... -->
<!-- ....................................................................... -->
<script>
tests( "GSUmathFloatReadable", () => {
test( "mathFloatReadable_0", GSUmathFloatReadable( NaN ), [ 0, "" ] );
test( "mathFloatReadable_1", GSUmathFloatReadable( null ), [ 0, "" ] );
test( "mathFloatReadable_2", GSUmathFloatReadable( true ), [ 0, "" ] );
test( "mathFloatReadable_3", GSUmathFloatReadable( false ), [ 0, "" ] );
test( "mathFloatReadable_4", GSUmathFloatReadable( undefined ), [ 0, "" ] );
test( "mathFloatReadable_5", GSUmathFloatReadable( '' ), [ 0, "" ] );
test( "mathFloatReadable_6", GSUmathFloatReadable( '21' ), [ 0, "" ] );
test( "mathFloatReadable_7", GSUmathFloatReadable( 0 ), [ 0, "" ] );
test( "mathFloatReadable_8", GSUmathFloatReadable( 1 ), [ 1, "" ] );
test( "mathFloatReadable_9", GSUmathFloatReadable( 999 ), [ 999, "" ] );
test( "mathFloatReadable_a", GSUmathFloatReadable( 1_000 ), [ 1, "K" ] );
test( "mathFloatReadable_b", GSUmathFloatReadable( 1_001 ), [ 1.001, "K" ] );
test( "mathFloatReadable_c", GSUmathFloatReadable( 1_999 ), [ 1.999, "K" ] );
test( "mathFloatReadable_d", GSUmathFloatReadable( 21_000 ), [ 21, "K" ] );
test( "mathFloatReadable_e", GSUmathFloatReadable( 21_001 ), [ 21.001, "K" ] );
test( "mathFloatReadable_f", GSUmathFloatReadable( 21_995 ), [ 21.995, "K" ] );
test( "mathFloatReadable_g", GSUmathFloatReadable( 999_999 ), [ 999.999, "K" ] );
test( "mathFloatReadable_h", GSUmathFloatReadable( 1_000_000 ), [ 1, "M" ] );
test( "mathFloatReadable_i", GSUmathFloatReadable( 1_000_001 ), [ 1, "M" ] );
test( "mathFloatReadable_j", GSUmathFloatReadable( 1_000_010 ), [ 1, "M" ] );
test( "mathFloatReadable_k", GSUmathFloatReadable( 1_000_100 ), [ 1, "M" ] );
test( "mathFloatReadable_l", GSUmathFloatReadable( 1_000_500 ), [ 1.001, "M" ] );
test( "mathFloatReadable_m", GSUmathFloatReadable( 100_000_000 ), [ 100, "M" ] );
test( "mathFloatReadable_n", GSUmathFloatReadable( 999_999_499 ), [ 999.999, "M" ] );
test( "mathFloatReadable_o", GSUmathFloatReadable( 999_999_500 ), [ 1, "G" ] );
test( "mathFloatReadable_p", GSUmathFloatReadable( 1_000_000_000 ), [ 1, "G" ] );
test( "mathFloatReadable_q", GSUmathFloatReadable( 1_234_000_000 ), [ 1.234, "G" ] );
} );
tests( "GSUmathPrec", () => {
test( "mathPrec_0", GSUmathPrec( 0 ), 0 );
test( "mathPrec_1", GSUmathPrec( .1 + .2 ), .3 );
test( "mathPrec_2", GSUmathPrec( .001 + .002 ), .003 );
test( "mathPrec_3", GSUmathPrec( .0001 + .0002 ), .0003 );
test( "mathPrec_4", GSUmathPrec( .00001 + .00002 ), .00003 );
test( "mathPrec_5", GSUmathPrec( .000001 + .000002 ), .000003 );
test( "mathPrec_6", GSUmathPrec( .0000001 + .0000002 ), .0000003 );
test( "mathPrec_7", GSUmathPrec( .00000001 + .00000002 ), .00000003 );
test( "mathPrec_8", GSUmathPrec( .000000001 + .000000002 ), .000000003 );
test( "mathPrec_9", GSUmathPrec( .0000000001 + .0000000002 ), .0000000003 );
test( "mathPrec_a", .001 + .002, .003 );
test( "mathPrec_b", .0001 + .0002, 0.00030000000000000003 );
test( "mathPrec_c", .00001 + .00002, 0.000030000000000000004 );
test( "mathPrec_d", .000001 + .000002, .000003 );
test( "mathPrec_e", .0000001 + .0000002, .0000003 );
test( "mathPrec_f", .00000001 + .00000002, 3.0000000000000004e-8 );
test( "mathPrec_g", .000000001 + .000000002, 3.0000000000000004e-9 );
test( "mathPrec_h", .0000000001 + .0000000002, .0000000003 );
test( "mathPrec_i", GSUmathPrec( .57 * .1 ), .057 );
} );
tests( "GSUmathApprox", () => {
test( "mathApprox_0", GSUmathApprox( 0, 0, 0 ), true );
test( "mathApprox_1", GSUmathApprox( -0, -0, 0 ), true );
test( "mathApprox_2", GSUmathApprox( 21, 21, 0 ), true );
test( "mathApprox_3", GSUmathApprox( 20.9, 21, .1 ), true );
test( "mathApprox_4", GSUmathApprox( 21.1, 21, .1 ), true );
test( "mathApprox_5", GSUmathApprox( 80, 100, 20 ), true );
test( "mathApprox_6", GSUmathApprox( 120, 100, 20 ), true );
test( "mathApprox_7", GSUmathApprox( 120.1, 100, 20 ), false );
test( "mathApprox_8", GSUmathApprox( 79.9, 100, 20 ), false );
test( "mathApprox_9", GSUmathApprox( 21.1, 21, 0 ), false );
test( "mathApprox_a", GSUmathApprox( 20.8, 21, .1 ), false );
test( "mathApprox_b", GSUmathApprox( 21.2, 21, .1 ), false );
test( "mathApprox_c", GSUmathApprox( -21, -21, 0 ), true );
test( "mathApprox_d", GSUmathApprox( -20.9, -21, .1 ), true );
test( "mathApprox_e", GSUmathApprox( -21.1, -21, .1 ), true );
test( "mathApprox_f", GSUmathApprox( -80, -100, 20 ), true );
test( "mathApprox_g", GSUmathApprox( -120, -100, 20 ), true );
test( "mathApprox_h", GSUmathApprox( -120.1, -100, 20 ), false );
test( "mathApprox_i", GSUmathApprox( -79.9, -100, 20 ), false );
test( "mathApprox_j", GSUmathApprox( -21.1, -21, 0 ), false );
test( "mathApprox_k", GSUmathApprox( -20.8, -21, .1 ), false );
test( "mathApprox_l", GSUmathApprox( -21.2, -21, .1 ), false );
} );
tests( "GSUmathMod", () => {
test( "mathMod_0", GSUmathMod( 0, 10 ), 0 );
test( "mathMod_1", GSUmathMod( 1, 10 ), 1 );
test( "mathMod_2", GSUmathMod( 9, 10 ), 9 );
test( "mathMod_3", GSUmathMod( 10, 10 ), 0 );
test( "mathMod_4", GSUmathMod( 100, 10 ), 0 );
test( "mathMod_5", GSUmathMod( 999, 10 ), 9 );
test( "mathMod_6", GSUmathMod( 1000, 10 ), 0 );
test( "mathMod_7", GSUmathMod( 1001, 10 ), 1 );
test( "mathMod_8", GSUmathMod( -1, 10 ), 9 );
test( "mathMod_9", GSUmathMod( -2, 10 ), 8 );
test( "mathMod_a", GSUmathMod( -9, 10 ), 1 );
test( "mathMod_b", GSUmathMod( -10, 10 ), 0 );
test( "mathMod_c", GSUmathMod( -11, 10 ), 9 );
test( "mathMod_d", GSUmathMod( -100, 10 ), 0 );
test( "mathMod_e", GSUmathMod( -1, 1 ), 0 );
test( "mathMod_f", GSUmathMod( 0, 1 ), 0 );
test( "mathMod_g", GSUmathMod( 1, 1 ), 0 );
test( "mathMod_h", GSUmathMod( -1, -1 ), -0 );
test( "mathMod_i", GSUmathMod( -5, -10 ), -5 );
test( "mathMod_j", GSUmathMod( -10, -10 ), -0 );
test( "mathMod_k", GSUmathMod( -11, -10 ), -1 );
} );
tests( "GSUmathFix", () => {
test( "mathFix_0", GSUmathFix( null ), 0 );
test( "mathFix_1", GSUmathFix( true ), 1 );
test( "mathFix_2", GSUmathFix( false ), 0 );
test( "mathFix_3", GSUmathFix( undefined ), 0 );
test( "mathFix_4", GSUmathFix( GSUnoop ), 0 );
test( "mathFix_5", GSUmathFix( 0 ), 0 );
test( "mathFix_6", GSUmathFix( 21 ), 21 );
test( "mathFix_7", GSUmathFix( 21.1 ), 21 );
test( "mathFix_8", GSUmathFix( 21.9 ), 22 );
test( "mathFix_9", GSUmathFix( -21.9 ), -22 );
test( "mathFix_a", GSUmathFix( -21.1 ), -21 );
test( "mathFix_b", GSUmathFix( Math.PI, 1 ), 3.1 );
test( "mathFix_c", GSUmathFix( Math.PI, 3 ), 3.142 );
test( "mathFix_d", GSUmathFix( Math.PI, 6 ), 3.141593 );
test( "mathFix_e", GSUmathFix( [] ), [] );
test( "mathFix_f", GSUmathFix( [], 1 ), [] );
test( "mathFix_g", GSUmathFix( [ Math.PI ] ), [ 3 ] );
test( "mathFix_h", GSUmathFix( [ Math.PI ], 0 ), [ 3 ] );
test( "mathFix_i", GSUmathFix( [ Math.PI ], 1 ), [ 3.1 ] );
test( "mathFix_j", GSUmathFix( [ Math.PI ], 6 ), [ 3.141593 ] );
test( "mathFix_k", GSUmathFix( [ Math.PI, .123456 ], 2 ), [ 3.14, .12 ] );
} );
tests( "GSUmathRound", () => {
test( "mathRound_0", GSUmathRound(), NaN );
test( "mathRound_1", GSUmathRound( 0, 0 ), NaN );
test( "mathRound_2", GSUmathRound( 1, 0 ), NaN );
test( "mathRound_3", GSUmathRound( 0 ), 0 );
test( "mathRound_4", GSUmathRound( Math.PI ), 3 );
test( "mathRound_5", GSUmathRound( Math.PI, 1 ), 3 );
test( "mathRound_6", GSUmathRound( Math.PI, 2 ), 4 );
test( "mathRound_7", GSUmathRound( Math.PI, 3 ), 3 );
test( "mathRound_8", GSUmathRound( 1.10, .25 ), 1 );
test( "mathRound_9", GSUmathRound( 1.25, .25 ), 1.25 );
test( "mathRound_a", GSUmathRound( 1.26, .25 ), 1.25 );
test( "mathRound_b", GSUmathRound( 1.24, .25 ), 1.25 );
test( "mathRound_c", GSUmathRound( -1.10, .25 ), -1 );
test( "mathRound_d", GSUmathRound( -1.25, .25 ), -1.25 );
test( "mathRound_e", GSUmathRound( -1.26, .25 ), -1.25 );
test( "mathRound_f", GSUmathRound( -1.24, .25 ), -1.25 );
} );
tests( "GSUmathFloor", () => {
test( "mathFloor_0", GSUmathFloor(), NaN );
test( "mathFloor_1", GSUmathFloor( 0, 0 ), NaN );
test( "mathFloor_2", GSUmathFloor( 1, 0 ), NaN );
test( "mathFloor_3", GSUmathFloor( 0 ), 0 );
test( "mathFloor_4", GSUmathFloor( Math.PI ), 3 );
test( "mathFloor_5", GSUmathFloor( Math.PI, 1 ), 3 );
test( "mathFloor_6", GSUmathFloor( Math.PI, 2 ), 2 );
test( "mathFloor_7", GSUmathFloor( Math.PI, 3 ), 3 );
test( "mathFloor_8", GSUmathFloor( 1.10, .25 ), 1 );
test( "mathFloor_9", GSUmathFloor( 1.25, .25 ), 1.25 );
test( "mathFloor_a", GSUmathFloor( 1.26, .25 ), 1.25 );
test( "mathFloor_b", GSUmathFloor( 1.24, .25 ), 1 );
test( "mathFloor_c", GSUmathFloor( -1.10, .25 ), -1.25 );
test( "mathFloor_d", GSUmathFloor( -1.25, .25 ), -1.25 );
test( "mathFloor_e", GSUmathFloor( -1.26, .25 ), -1.50 );
test( "mathFloor_f", GSUmathFloor( -1.24, .25 ), -1.25 );
} );
tests( "GSUmathCeil", () => {
test( "mathCeil_0", GSUmathCeil(), NaN );
test( "mathCeil_1", GSUmathCeil( 0, 0 ), NaN );
test( "mathCeil_2", GSUmathCeil( 1, 0 ), NaN );
test( "mathCeil_3", GSUmathCeil( 0 ), 0 );
test( "mathCeil_4", GSUmathCeil( Math.PI ), 4 );
test( "mathCeil_5", GSUmathCeil( Math.PI, 1 ), 4 );
test( "mathCeil_6", GSUmathCeil( Math.PI, 2 ), 4 );
test( "mathCeil_7", GSUmathCeil( Math.PI, 3 ), 6 );
test( "mathCeil_8", GSUmathCeil( 1.10, .25 ), 1.25 );
test( "mathCeil_9", GSUmathCeil( 1.25, .25 ), 1.25 );
test( "mathCeil_a", GSUmathCeil( 1.26, .25 ), 1.50 );
test( "mathCeil_b", GSUmathCeil( 1.24, .25 ), 1.25 );
test( "mathCeil_c", GSUmathCeil( -1.10, .25 ), -1 );
test( "mathCeil_d", GSUmathCeil( -1.25, .25 ), -1.25 );
test( "mathCeil_e", GSUmathCeil( -1.26, .25 ), -1.25 );
test( "mathCeil_f", GSUmathCeil( -1.24, .25 ), -1 );
} );
tests( "GSUmathLogN", () => {
test( "mathLogN_0", GSUmathFix( GSUmathLogN( 10, 1000 ), 8 ), 3 );
test( "mathLogN_1", GSUmathFix( GSUmathLogN( 2, 1024 ), 8 ), 10 );
} );
tests( "GSUmathSum", () => {
test( "mathSum_0", GSUmathSum(), 0 );
test( "mathSum_1", GSUmathSum( NaN ), 0 );
test( "mathSum_2", GSUmathSum( 0 ), 0 );
test( "mathSum_3", GSUmathSum( 7 ), 7 );
test( "mathSum_4", GSUmathSum( 1, 2, 3, 4, 5, 6 ), 21 );
} );
tests( "GSUmathAvg", () => {
test( "mathAvg_0", GSUmathAvg(), 0 );
test( "mathAvg_1", GSUmathAvg( NaN ), 0 );
test( "mathAvg_2", GSUmathAvg( null ), 0 );
test( "mathAvg_3", GSUmathAvg( undefined ), 0 );
test( "mathAvg_4", GSUmathAvg( 21 ), 21 );
test( "mathAvg_5", GSUmathAvg( 21, NaN ), 0 );
test( "mathAvg_6", GSUmathAvg( 0, "42" ), 21 );
test( "mathAvg_7", GSUmathAvg( "21", "63" ), 42 );
test( "mathAvg_8", GSUmathAvg( -10, 15 ), 2.5 );
test( "mathAvg_9", GSUmathAvg( 10, 20 ), 15 );
test( "mathAvg_a", GSUmathAvg( 10, 20, 30 ), 20 );
} );
tests( "GSUmathStack", () => {
test( "mathStack_0", GSUmathSum( ...GSUmathStack( [ 5 ], 2 ) ), 2 );
test( "mathStack_1", GSUmathSum( ...GSUmathStack( [ 2, 5 ], 7 ) ), 9 );
test( "mathStack_2", GSUmathSum( ...GSUmathStack( [ 5, 7 ], 3 ) ), 8 );
test( "mathStack_3", GSUmathSum( ...GSUmathStack( [ 1, 2, 3 ], 4 ) ), 7 );
} );
tests( "GSUmathSign", () => {
test( "mathSign_0", GSUmathSign( +0 ), "+0" );
test( "mathSign_1", GSUmathSign( -0 ), "+0" );
test( "mathSign_2", GSUmathSign( 1 ), "+1" );
test( "mathSign_3", GSUmathSign( -1 ), "-1" );
test( "mathSign_4", GSUmathSign( .009 ), "+0.009" );
test( "mathSign_5", GSUmathSign( -.009 ), "-0.009" );
} );
tests( "GSUmathInRange", () => {
test( "mathInRange_0", GSUmathInRange( 0, 0, 1 ), true );
test( "mathInRange_1", GSUmathInRange( 20, 20, 22 ), true );
test( "mathInRange_2", GSUmathInRange( 21, 20, 22 ), true );
test( "mathInRange_3", GSUmathInRange( 22, 20, 22 ), true );
test( "mathInRange_4", GSUmathInRange( 20, 22, 20 ), true );
test( "mathInRange_5", GSUmathInRange( 21, 22, 20 ), true );
test( "mathInRange_6", GSUmathInRange( 22, 22, 20 ), true );
test( "mathInRange_7", GSUmathInRange( -20, -20, -22 ), true );
test( "mathInRange_8", GSUmathInRange( -21, -20, -22 ), true );
test( "mathInRange_9", GSUmathInRange( -22, -20, -22 ), true );
test( "mathInRange_a", GSUmathInRange( -20, -22, -20 ), true );
test( "mathInRange_b", GSUmathInRange( -21, -22, -20 ), true );
test( "mathInRange_c", GSUmathInRange( -22, -22, -20 ), true );
test( "mathInRange_d", GSUmathInRange( .1, 0, 0 ), false );
test( "mathInRange_e", GSUmathInRange( -.1, 0, 0 ), false );
test( "mathInRange_f", GSUmathInRange( 2, 0, 1 ), false );
test( "mathInRange_g", GSUmathInRange( -1, 0, 1 ), false );
test( "mathInRange_h", GSUmathInRange( -.001, 0, 1 ), false );
test( "mathInRange_i", GSUmathInRange( 1.001, 0, 1 ), false );
test( "mathInRange_j", GSUmathInRange( undefined, -Infinity, Infinity ), false );
test( "mathInRange_k", GSUmathInRange( NaN, -Infinity, Infinity ), false );
test( "mathInRange_l", GSUmathInRange( null, -Infinity, Infinity ), false );
test( "mathInRange_m", GSUmathInRange( "-0.5", -Infinity, Infinity ), true );
test( "mathInRange_n", GSUmathInRange( "0", -Infinity, Infinity ), true );
test( "mathInRange_o", GSUmathInRange( "21", -Infinity, Infinity ), true );
test( "mathInRange_p", GSUmathInRange( "a", -Infinity, Infinity ), false );
test( "mathInRange_q", GSUmathInRange( "", -Infinity, Infinity ), false );
test( "mathInRange_r", GSUmathInRange( false, -Infinity, Infinity ), false );
test( "mathInRange_s", GSUmathInRange( true, -Infinity, Infinity ), false );
} );
tests( "GSUmathClamp", () => {
test( "mathClamp_0", GSUmathClamp( 19, 20, 30 ), 20 );
test( "mathClamp_1", GSUmathClamp( 20, 20, 30 ), 20 );
test( "mathClamp_2", GSUmathClamp( 21, 20, 30 ), 21 );
test( "mathClamp_3", GSUmathClamp( 29, 20, 30 ), 29 );
test( "mathClamp_4", GSUmathClamp( 30, 20, 30 ), 30 );
test( "mathClamp_5", GSUmathClamp( 31, 20, 30 ), 30 );
test( "mathClamp_6", GSUmathClamp( -19, -20, -30 ), -20 );
test( "mathClamp_7", GSUmathClamp( -20, -20, -30 ), -20 );
test( "mathClamp_8", GSUmathClamp( -21, -20, -30 ), -21 );
test( "mathClamp_9", GSUmathClamp( -29, -20, -30 ), -29 );
test( "mathClamp_a", GSUmathClamp( -30, -20, -30 ), -30 );
test( "mathClamp_b", GSUmathClamp( -31, -20, -30 ), -30 );
} );
tests( "GSUmathEaseInCirc", () => {
test( "mathEaseInCirc_0", GSUmathEaseInCirc( 0 ), 0 );
test( "mathEaseInCirc_1", GSUmathEaseInCirc( 1 ), 1 );
test( "mathEaseInCirc_2", GSUmathEaseInCirc( .25 ), .031754163448145745 );
test( "mathEaseInCirc_3", GSUmathEaseInCirc( .5 ), .1339745962155614 );
test( "mathEaseInCirc_4", GSUmathEaseInCirc( .75 ), .3385621722338523 );
test( "mathEaseInCirc_5", GSUmathEaseInCirc( .25, 2 ), .031754163448145745 );
test( "mathEaseInCirc_6", GSUmathEaseInCirc( .25, 3 ), .007843258350778481 );
test( "mathEaseInCirc_7", GSUmathEaseInCirc( .25, 4 ), .001955036083043038 );
} );
tests( "GSUmathEaseOutCirc", () => {
test( "mathEaseOutCirc_0", GSUmathEaseOutCirc( 0 ), 0 );
test( "mathEaseOutCirc_1", GSUmathEaseOutCirc( 1 ), 1 );
test( "mathEaseOutCirc_2", GSUmathEaseOutCirc( .25 ), .6614378277661477 );
test( "mathEaseOutCirc_3", GSUmathEaseOutCirc( .5 ), .8660254037844386 );
test( "mathEaseOutCirc_4", GSUmathEaseOutCirc( .75 ), .9682458365518543 );
test( "mathEaseOutCirc_5", GSUmathEaseOutCirc( .25, 2 ), .6614378277661477 );
test( "mathEaseOutCirc_6", GSUmathEaseOutCirc( .25, 3 ), 1.192424001771182 ); // ???
test( "mathEaseOutCirc_7", GSUmathEaseOutCirc( .25, 4 ), .8267972847076845 );
} );
tests( "GSUmathLineFindY", () => {
test( "mathLineFindY_0", GSUmathLineFindY( { x: 10, y: 1 }, { x: 20, y: 2 }, 15 ), 1.5 );
test( "mathLineFindY_1", GSUmathLineFindY( { x: 20, y: 2 }, { x: 10, y: 1 }, 15 ), 1.5 );
test( "mathLineFindY_2", GSUmathLineFindY( { x: 10, y: 1 }, { x: 20, y: 2 }, 10 ), 1 );
test( "mathLineFindY_3", GSUmathLineFindY( { x: 10, y: 1 }, { x: 20, y: 2 }, 20 ), 2 );
test( "mathLineFindY_4", GSUmathLineFindY( { x: 10, y: 1 }, { x: 20, y: 2 }, 5 ), .5 );
test( "mathLineFindY_5", GSUmathLineFindY( { x: 10, y: 1 }, { x: 20, y: 2 }, 25 ), 2.5 );
test( "mathLineFindY_6", GSUmathLineFindY( { x: -10, y: 1 }, { x: 10, y: 2 }, 0 ), 1.5 );
test( "mathLineFindY_7", GSUmathLineFindY( { x: -10, y: -1 }, { x: 10, y: 1 }, 0 ), 0 );
} );
tests( "GSUmathSampleDotLine", () => {
test( "mathSampleDotLine_0", GSUmathSampleDotLine( [ { x: 0, y: 0 }, { x: 1, y: 1 } ], 2 ), [ [ 0, 0 ], [ 1, 1 ] ] );
test( "mathSampleDotLine_1", GSUmathSampleDotLine( [ { x: -1, y: -1 }, { x: 1, y: 1 } ], 2 ), [ [ -1, -1 ], [ 1, 1 ] ] );
test( "mathSampleDotLine_2", GSUmathSampleDotLine( [ { x: 0, y: 0 }, { x: 1, y: 1 } ], 3 ), [ [ 0, 0 ], [ .5, .5 ], [ 1, 1 ] ] );
test( "mathSampleDotLine_3", GSUmathSampleDotLine( [ { x: 0, y: 0 }, { x: 1, y: 1 } ], 4 ), [ [ 0, 0 ], [ 1 / 3, 1 / 3 ], [ 2 / 3, 2 / 3 ], [ 1, 1 ] ] );
test( "mathSampleDotLine_4", GSUmathSampleDotLine( [ { x: 0, y: 0 }, { x: .5, y: 3 }, { x: 1, y: 0 } ], 2 ), [ [ 0, 0 ], [ 1, 0 ] ] );
test( "mathSampleDotLine_5", GSUmathSampleDotLine( [ { x: 0, y: 0 }, { x: .5, y: 3 }, { x: 1, y: 0 } ], 3 ), [ [ 0, 0 ], [ .5, 3 ], [ 1, 0 ] ] );
test( "mathSampleDotLine_6", GSUmathSampleDotLine( [ { x: 0, y: 0 }, { x: .5, y: 3 }, { x: 1, y: 0 } ], 4 ), [ [ 0, 0 ], [ 1 / 3, 2 ], [ 2 / 3, 2 ], [ 1, 0 ] ] );
test( "mathSampleDotLine_7", GSUmathSampleDotLine( [ { x: -3, y: 0 }, { x: 0, y: 3 }, { x: 3, y: 0 } ], 4 ), [ [ -3, 0 ], [ -1, 2 ], [ 1, 2 ], [ 3, 0 ] ] );
test( "mathSampleDotLine_8", GSUmathSampleDotLine( [ { x: 0, y: 0 }, { x: 1, y: 1 } ], 2, 0 ), [ [ 0, 0 ], [ 1, 1 ] ] );
test( "mathSampleDotLine_9", GSUmathSampleDotLine( [ { x: 0, y: 0 }, { x: 1, y: 1 } ], 2, 0, 1 ), [ [ 0, 0 ], [ 1, 1 ] ] );
test( "mathSampleDotLine_a", GSUmathSampleDotLine( [ { x: 0, y: 0 }, { x: 1, y: 1 } ], 2, .5, 1 ), [ [ .5, .5 ], [ 1, 1 ] ] );
test( "mathSampleDotLine_b", GSUmathSampleDotLine( [ { x: 0, y: 0 }, { x: 1, y: 1 } ], 2, 0, .5 ), [ [ 0, 0 ], [ .5, .5 ] ] );
test( "mathSampleDotLine_c", GSUmathSampleDotLine( [ { x: 0, y: 0 }, { x: 1, y: 1 } ], 2, .25, .75 ), [ [ .25, .25 ], [ .75, .75 ] ] );
} );
</script>
<!-- ....................................................................... -->
<!-- ..... gs-utils-func ................................................... -->
<!-- ....................................................................... -->
<script>
tests( "GSUnoop", () => {
test( "noop_0", GSUnoop(), undefined );
test( "noop_1", GSUnoop( 1 ), undefined );
test( "noopFalse_0", GSUnoopFalse(), false );
test( "noopFalse_1", GSUnoopFalse( true ), false );
} );
tests( "GSUsetIntervalLimit", () => {
test( "setIntervalLimit_0", _GSUsetInterval_minMs, 0 );
test( "setIntervalLimit_1", GSUsetIntervalLimit( 1 ), 1_000 );
test( "setIntervalLimit_6", _GSUsetInterval_minMs, 1_000 );
} );
tests( "GSUsetTimeout", async () => {
let timeoutId = null;
let timeoutInc = 0;
const fn = () => ++timeoutInc;
timeoutId = GSUsetTimeout( fn, .05 );
test( "setTimeout_0", GSUisInt( timeoutId ) && timeoutId > 0, true );
test( "setTimeout_1", timeoutInc, 0 ); await GSUwait( .045 );
test( "setTimeout_2", timeoutInc, 0 ); await GSUwait( .005 + .02 );
test( "setTimeout_3", timeoutInc, 1 );
timeoutId = GSUsetTimeout( fn, 0 );
test( "setTimeout_4", timeoutId, null );
test( "setTimeout_5", timeoutInc, 2 );
timeoutId = GSUsetTimeout( fn, .01 );
GSUclearTimeout( timeoutId ); await GSUwait( .02 );
test( "setTimeout_6", timeoutInc, 2 );
} );
</script>
<!-- ....................................................................... -->
<!-- ..... gs-utils-json ................................................... -->
<!-- ....................................................................... -->
<script>
tests( "GSUgetNewId", () => {
test( "getNewId_0", GSUgetNewId( {} ), "0" );
test( "getNewId_1", GSUgetNewId( { 0: true } ), "1" );
test( "getNewId_2", GSUgetNewId( { 0: false } ), "1" );
test( "getNewId_3", GSUgetNewId( { 0: false, 1: null } ), "2" );
test( "getNewId_4", GSUgetNewId( { 2: false, 1: null } ), "0" );
test( "getNewId_5", GSUgetNewId( { 0: false, 2: null } ), "1" );
} );
tests( "GSUgetNewIds", () => {
test( "getNewIds_0", GSUgetNewIds( {}, 1 ), [ "0" ] );
test( "getNewIds_1", GSUgetNewIds( {}, 2 ), [ "0", "1" ] );
test( "getNewIds_2", GSUgetNewIds( {}, 3 ), [ "0", "1", "2" ] );
test( "getNewIds_3", GSUgetNewIds( { 0: 0, 1: 1, 3: 3, 4: 4 }, 2 ), [ "2", "5" ] );
} );
tests( "GSUgetLastOrder", () => {
test( "getLastOrder_0", GSUgetLastOrder( {} ), 0 );
test( "getLastOrder_1", GSUgetLastOrder( [] ), 0 );
test( "getLastOrder_2", GSUgetLastOrder( { 0: { order: 0 } } ), 1 );
test( "getLastOrder_3", GSUgetLastOrder( { 0: { order: 5 } } ), 6 );
test( "getLastOrder_4", GSUgetLastOrder( { 1: { order: 9 }, 2: { order: 3 } } ), 10 );
test( "getLastOrder_5", GSUgetLastOrder( { 1: {}, 2: {} } ), 1 );
test( "getLastOrder_6", GSUgetLastOrder( { 1: { order: 9 }, 2: {} } ), 10 );
} );
tests( "GSUdeepCopy", () => {
test( "deepCopy_0", GSUdeepCopy( 0 ), 0 );
test( "deepCopy_1", GSUdeepCopy( 21 ), 21 );
test( "deepCopy_2", GSUdeepCopy( NaN ), NaN );
test( "deepCopy_3", GSUdeepCopy( null ), null );
test( "deepCopy_4", GSUdeepCopy( true ), true );
test( "deepCopy_5", GSUdeepCopy( false ), false );
test( "deepCopy_6", GSUdeepCopy( undefined ), undefined );
const obj1 = {};
const obj2 = GSUdeepCopy( obj1 );
obj2.foo = 21;
test( "deepCopy_7", obj1.foo, undefined );
test( "deepCopy_8", obj1 !== obj2, true );
const obj3 = { a: 5, b: { c: 10 }, d: undefined };
const obj4 = GSUdeepCopy( obj3 );
obj3.b.c = 20;
test( "deepCopy_9", obj4.b.c, 10 );
test( "deepCopy_a", obj4.d, undefined );
test( "deepCopy_b", "d" in obj4, true );
test( "deepCopy_c", GSUdeepCopy( [] ), [] );
test( "deepCopy_d", GSUdeepCopy( [ 21 ] ), [ 21 ] );
const obj5 = { a: 21, b: [ 21, 33, { c: 42 } ] };
const obj6 = GSUdeepCopy( obj5 );
test( "deepCopy_e", obj5, obj6 );
obj5.b[ 2 ].c = 43;
test( "deepCopy_f", obj5.b[ 2 ].c, 43 );
test( "deepCopy_g", obj6.b[ 2 ].c, 42 );
} );
tests( "GSUdeepAssign", () => {
test( "deepAssign_0", GSUdeepAssign(), undefined );
test( "deepAssign_1", GSUdeepAssign( 0 ), 0 );
test( "deepAssign_2", GSUdeepAssign( null ), null );
test( "deepAssign_3", GSUdeepAssign( undefined ), undefined );
const obj1 = {};
testStrict( "deepAssign_4", GSUdeepAssign( obj1, false ), obj1 );
testStrict( "deepAssign_5", GSUdeepAssign( obj1, { foo: 21 } ), obj1 );
test( "deepAssign_6", obj1.foo, 21 );
GSUdeepAssign( obj1, { foo: undefined, bar: undefined } );
test( "deepAssign_7", obj1.foo, undefined );
test( "deepAssign_8", obj1.bar, undefined );
test( "deepAssign_9", "foo" in obj1, true );
test( "deepAssign_a", "bar" in obj1, true );
const obj2 = { x: { y: { z: "z" } } };
GSUdeepAssign( obj1, obj2 );
test( "deepAssign_b", obj1.x.y.z, "z" );
obj2.x.y.z = "o";
test( "deepAssign_c", obj1.x.y.z, "z" );
} );
tests( "GSUdeepFreeze", () => {
test( "deepFreeze_0", GSUdeepFreeze( NaN ), NaN );
test( "deepFreeze_1", GSUdeepFreeze( null ), null );
test( "deepFreeze_2", GSUdeepFreeze( true ), true );
test( "deepFreeze_3", GSUdeepFreeze( false ), false );
test( "deepFreeze_4", GSUdeepFreeze( undefined ), undefined );
const obj1 = {};
const arr1 = [];
testStrict( "deepFreeze_5", GSUdeepFreeze( obj1 ), obj1 );
testStrict( "deepFreeze_6", GSUdeepFreeze( arr1 ), arr1 );
obj1.foo = 21;
try { arr1.push( "a" ); } catch ( e ) {}
testStrict( "deepFreeze_7", "foo" in obj1, false );
testStrict( "deepFreeze_8", arr1.length, 0 );
const obj2 = { a: 21, b: { c: 42 } };
testStrict( "deepFreeze_9", GSUdeepFreeze( obj2 ), obj2 );
obj2.a = 22;
test( "deepFreeze_a", obj2.a, 21 );
obj2.b.c = 43;
test( "deepFreeze_b", obj2.b.c, 42 );
const obj3 = { a: { b: 21 }, c: { d: 42 } };
testStrict( "deepFreeze_c", GSUdeepFreeze( obj3 ), obj3 );
obj3.zzz = 666;
obj3.a.b = 666;
obj3.c.d = 666;
test( "deepFreeze_d", "zzz" in obj3, false );
test( "deepFreeze_e", obj3.a.b, 21 );
test( "deepFreeze_f", obj3.c.d, 42 );
delete obj3.c;
test( "deepFreeze_g", obj3.c.d, 42 );
} );
tests( "GSUdiffObjects", () => {
test( "diffObjects_0", GSUdiffObjects( 0, 0 ), undefined );
test( "diffObjects_1", GSUdiffObjects( 1, 1 ), undefined );
test( "diffObjects_2", GSUdiffObjects( {}, {} ), undefined );
test( "diffObjects_3", GSUdiffObjects( [], [] ), undefined );
test( "diffObjects_4", GSUdiffObjects( true, true ), undefined );
test( "diffObjects_5", GSUdiffObjects( false, false ), undefined );
test( "diffObjects_6", GSUdiffObjects( [ 1 ], [ 1 ] ), undefined );
test( "diffObjects_7", GSUdiffObjects( [ 1, 2 ], [ 1, 2 ] ), undefined );
test( "diffObjects_8", GSUdiffObjects( { a: 1 }, { a: 1 } ), undefined );
test( "diffObjects_9", GSUdiffObjects( { a: 1, b: 2 }, { a: 1, b: 2 } ), undefined );
test( "diffObjects_a", GSUdiffObjects( { a: 1, b: { c: 2 } }, { a: 1, b: { c: 2 } } ), undefined );
test( "diffObjects_b", GSUdiffObjects( { a: 1 }, {} ), { a: undefined } );
test( "diffObjects_c", GSUdiffObjects( { a: 1, b: 2 }, {} ), { a: undefined, b: undefined } );
test( "diffObjects_d", GSUdiffObjects( {}, { a: 1 } ), { a: 1 } );
test( "diffObjects_e", GSUdiffObjects( {}, { a: 1, b: 2 } ), { a: 1, b: 2 } );
test( "diffObjects_f", GSUdiffObjects( { a: 1 }, { a: 1, b: 2 } ), { b: 2 } );
test( "diffObjects_g", GSUdiffObjects( { a: 1, b: 2 }, { a: 1 } ), { b: undefined } );
test( "diffObjects_h", GSUdiffObjects( { a: 1, b: { c: 2 } }, { a: 2, b: { c: 2 } } ), { a: 2 } );
test( "diffObjects_i", GSUdiffObjects( { a: 1, b: { c: 2 } }, { a: 1, b: { c: 3 } } ), { b: { c: 3 } } );
test( "diffObjects_j", GSUdiffObjects( { a: 1, b: { c: 2, d: 2 } }, { a: 1, b: { c: 3, d: 3 } } ), { b: { c: 3, d: 3 } } );
test( "diffObjects_k", GSUdiffObjects( { a: 1, b: { c: 2, d: 2 } }, { a: 4, b: { c: 2, d: 3 } } ), { a: 4, b: { d: 3 } } );
test( "diffObjects_l", GSUdiffObjects( { a: 1, b: { c: 2 } }, { a: 1, B: { c: 2 } } ), { b: undefined, B: { c: 2 } } );
test( "diffObjects_m", GSUdiffObjects( { a: [ 5, 7 ] }, { a: [ 5, 8 ] } ), { a: [ 5, 8 ] } );
test( "diffObjects_n", GSUdiffObjects( { a: [ 5, 7 ] }, { a: [ 5, 7 ] } ), undefined );
} );
tests( "GSUdiffAssign", () => {
test( "diffAssign_0", GSUdiffAssign( 0 ), 0 );
test( "diffAssign_1", GSUdiffAssign( 1 ), 1 );
test( "diffAssign_2", GSUdiffAssign( NaN ), NaN );
test( "diffAssign_3", GSUdiffAssign( null ), null );
test( "diffAssign_4", GSUdiffAssign( true ), true );
test( "diffAssign_5", GSUdiffAssign( false ), false );
test( "diffAssign_6", GSUdiffAssign( undefined ), undefined );
test( "diffAssign_7", GSUdiffAssign(), undefined );
const obj1 = {};
testStrict( "diffAssign_8", GSUdiffAssign( obj1 ), obj1 );
testStrict( "diffAssign_9", GSUdiffAssign( obj1, { a: 21 } ), obj1 );
test( "diffAssign_a", obj1.a, 21 );
GSUdiffAssign( obj1, { a: 0 } ); test( "diffAssign_b", obj1.a, 0 );
GSUdiffAssign( obj1, { a: null } ); test( "diffAssign_c", obj1.a, null );
GSUdiffAssign( obj1, { a: undefined } ); test( "diffAssign_d", "a" in obj1, false );
const obj2 = { a: 1 };
GSUdiffAssign( obj2, { b: 2 } ); test( "diffAssign_e", obj2, { a: 1, b: 2 } );
GSUdiffAssign( obj2, { a: undefined, b: undefined } ); test( "diffAssign_f", obj2, {} );
GSUdiffAssign( obj2, { aa: { b: undefined, c: 1 } } ); test( "diffAssign_g", obj2, { aa: { c: 1 } } );
GSUdiffAssign( obj2, { aa: { c: { d: [ 1, 2 ] } } } ); test( "diffAssign_h", obj2, { aa: { c: { d: [ 1, 2 ] } } } );
GSUdiffAssign( obj2, { aa: { c: { d: [ 3 ] } } } ); test( "diffAssign_i", obj2, { aa: { c: { d: [ 3 ] } } } );
GSUdiffAssign( obj2, { aa: undefined } ); test( "diffAssign_j", obj2, {} );
const obj3 = { a: [ 4, 5, 6, 7, 8, 9 ] };
const obj4 = { a: [ 1, 2, 3 ] };
GSUdiffAssign( obj3, obj4 );
obj4.a.push( 4 );
test( "diffAssign_k", obj3.a, [ 1, 2, 3 ] );
test( "diffAssign_l", obj3.a.length, 3 );
} );
tests( "GSUcomposeUndo", () => {
const src = {
a: { aa: 1, ab: 2, ac: 3 },
b: { ba: 1, bb: 2, bc: 3 },
c: { ca: 1, cb: 2, cc: 3 },
};
test( "composeUndo_0", GSUcomposeUndo( src, {} ), {} );
test( "composeUndo_1", GSUcomposeUndo( { }, { a: 1 } ), { a: undefined } );
test( "composeUndo_2", GSUcomposeUndo( { a: 1 }, { a: undefined } ), { a: 1 } );
test( "composeUndo_3", GSUcomposeUndo( { a: 1 }, { a: 2, b: 3 } ), { a: 1, b: undefined } );
test( "composeUndo_4", GSUcomposeUndo( { a: 1, c: 4 }, { a: 2, b: 3, c: undefined } ), { a: 1, b: undefined, c: 4 } );
test( "composeUndo_5", GSUcomposeUndo( src, { a: { aa: undefined } } ), { a: { aa: 1 } } );
test( "composeUndo_6", GSUcomposeUndo( src, { a: { ad: 4 } } ), { a: { ad: undefined } } );
test( "composeUndo_7", GSUcomposeUndo( src, { a: undefined } ), { a: { aa: 1, ab: 2, ac: 3 } } );
const src2 = {
a: { aa: 1, ab: 2, ac: 3 },
b: { aa: [ 0, 1, 2, 3, 1000 ] },
};
test( "composeUndo_8", GSUcomposeUndo( src2, {} ), {} );
const undo = GSUcomposeUndo( src2, { b: { aa: [ 21 ] } } );
test( "composeUndo_9", undo, { b: { aa: [ 0, 1, 2, 3, 1000 ] } } );
test( "composeUndo_a", GSUisArr( undo.b.aa ), true );
undo.b.aa[ 4 ] = 5555;
test( "composeUndo_b", undo.b.aa[ 4 ], 1000 );
} );
</script>
<!-- ....................................................................... -->
<!-- ..... gs-utils-audio .................................................. -->
<!-- ....................................................................... -->
<script>
tests( "GSUaudioDelayDuration", () => {
test( "audioDelayDuration_0", GSUaudioDelayDuration( -1, -1 ), 0 );
test( "audioDelayDuration_1", GSUaudioDelayDuration( -1, 0 ), 0 );
test( "audioDelayDuration_2", GSUaudioDelayDuration( 0, -1 ), 0 );
test( "audioDelayDuration_3", GSUaudioDelayDuration( 0, 0 ), 0 );
test( "audioDelayDuration_4", GSUaudioDelayDuration( 1, 1 ), Infinity );
test( "audioDelayDuration_5", GSUaudioDelayDuration( 1, .5 ), 4 );
test( "audioDelayDuration_6", GSUaudioDelayDuration( 1, .5, .1 ), 4 );
test( "audioDelayDuration_7", GSUaudioDelayDuration( 1, .5, .2 ), 3 );
test( "audioDelayDuration_8", GSUaudioDelayDuration( 1, .5, .25 ), 2 );
test( "audioDelayDuration_9", GSUaudioDelayDuration( 1, .5, .26 ), 2 );
test( "audioDelayDuration_a", GSUaudioDelayDuration( 1, .5, .01 ), 7 );
test( "audioDelayDuration_b", GSUaudioDelayDuration( 1, .9993605 ), 3600 );
} );
</script>
<!-- ....................................................................... -->
<!-- ..... GSUxxxx ......................................................... -->
<!-- ....................................................................... -->
<script>
tests( "GSUisObj", () => {
test( "isObj.0", GSUisObj(), false );
test( "isObj.1", GSUisObj( NaN ), false );
test( "isObj.2", GSUisObj( null ), false );
test( "isObj.3", GSUisObj( true ), false );
test( "isObj.4", GSUisObj( false ), false );
test( "isObj.5", GSUisObj( undefined ), false );
test( "isObj.6", GSUisObj( GSUnoop ), false );
test( "isObj.7", GSUisObj( {} ), true );
test( "isObj.8", GSUisObj( [] ), true );
test( "isObj.9", GSUisObj( 21 ), false );
test( "isObj.a", GSUisObj( "abc" ), false );
} );
tests( "GSUisArr", () => {
test( "isArr.0", GSUisArr( [] ), true );
test( "isArr.1", GSUisArr( [ 0 ] ), true );
test( "isArr.2", GSUisArr( {} ), false );
test( "isArr.3", GSUisArr( "abc" ), false );
test( "isArr.4", GSUisArr( "" ), false );
test( "isArr.5", GSUisArr( null ), false );
test( "isArr.6", GSUisArr( undefined ), false );
test( "isArr.7", GSUisArr( true ), false );
test( "isArr.8", GSUisArr( GSUnoop ), false );
} );
tests( "GSUisStr", () => {
test( "isStr.0", GSUisStr(), false );
test( "isStr.1", GSUisStr( NaN ), false );
test( "isStr.2", GSUisStr( null ), false );
test( "isStr.3", GSUisStr( true ), false );
test( "isStr.4", GSUisStr( false ), false );
test( "isStr.5", GSUisStr( undefined ), false );
test( "isStr.7", GSUisStr( GSUnoop ), false );
test( "isStr.8", GSUisStr( {} ), false );
test( "isStr.9", GSUisStr( [] ), false );
test( "isStr.a", GSUisStr( "" ), true );
test( "isStr.b", GSUisStr( "0" ), true );
} );
tests( "GSUisNaN", () => {
test( "isNaN.0", GSUisNaN( NaN ), true );
test( "isNaN.1", GSUisNaN( 0/0 ), true );
test( "isNaN.2", GSUisNaN(), false );
test( "isNaN.3", GSUisNaN( null ), false );
test( "isNaN.4", GSUisNaN( undefined ), false );
test( "isNaN.5", GSUisNaN( GSUnoop ), false );
test( "isNaN.6", GSUisNaN( 0 ), false );
test( "isNaN.7", GSUisNaN( 1 ), false );
test( "isNaN.8", GSUisNaN( "a" ), false );
test( "isNaN.9", GSUisNaN( "21" ), false );
test( "isNaN.a", GSUisNaN( true ), false );
test( "isNaN.b", GSUisNaN( false ), false );
} );
tests( "GSUisNum", () => {
test( "isNum.0", GSUisNum(), false );
test( "isNum.1", GSUisNum( NaN ), false );
test( "isNum.2", GSUisNum( null ), false );
test( "isNum.3", GSUisNum( true ), false );
test( "isNum.4", GSUisNum( false ), false );
test( "isNum.5", GSUisNum( undefined ), false );
test( "isNum.6", GSUisNum( GSUnoop ), false );
test( "isNum.7", GSUisNum( {} ), false );
test( "isNum.8", GSUisNum( [] ), false );
test( "isNum.9", GSUisNum( "" ), false );
test( "isNum.a", GSUisNum( 0 ), true );
test( "isNum.b", GSUisNum( 21 ), true );
test( "isNum.c", GSUisNum( 21.5 ), true );
test( "isNum.d", GSUisNum( "21" ), false );
test( "isNum.e", GSUisNum( "abc" ), false );
} );
tests( "GSUisInt", () => {
test( "isInt.0", GSUisInt(), false );
test( "isInt.1", GSUisInt( NaN ), false );
test( "isInt.2", GSUisInt( null ), false );
test( "isInt.3", GSUisInt( true ), false );
test( "isInt.4", GSUisInt( false ), false );
test( "isInt.5", GSUisInt( undefined ), false );
test( "isInt.6", GSUisInt( GSUnoop ), false );
test( "isInt.7", GSUisInt( {} ), false );
test( "isInt.8", GSUisInt( [] ), false );
test( "isInt.9", GSUisInt( "" ), false );
test( "isInt.a", GSUisInt( 0 ), true );
test( "isInt.b", GSUisInt( 21 ), true );
test( "isInt.c", GSUisInt( 21.5 ), false );
test( "isInt.d", GSUisInt( "21" ), false );
test( "isInt.e", GSUisInt( "abc" ), false );
} );
tests( "GSUisBoo", () => {
test( "isBoo.0", GSUisBoo( true ), true );
test( "isBoo.1", GSUisBoo( false ), true );
test( "isBoo.2", GSUisBoo( {} ), false );
test( "isBoo.3", GSUisBoo( [] ), false );
test( "isBoo.4", GSUisBoo( "" ), false );
test( "isBoo.5", GSUisBoo( 0 ), false );
test( "isBoo.6", GSUisBoo( 21 ), false );
test( "isBoo.7", GSUisBoo( NaN ), false );
test( "isBoo.8", GSUisBoo( null ), false );
test( "isBoo.9", GSUisBoo( undefined ), false );
test( "isBoo.a", GSUisBoo( GSUnoop ), false );
} );
tests( "GSUisFun", () => {
test( "isFun.0", GSUisFun(), false );
test( "isFun.1", GSUisFun( NaN ), false );
test( "isFun.2", GSUisFun( null ), false );
test( "isFun.3", GSUisFun( true ), false );
test( "isFun.4", GSUisFun( false ), false );
test( "isFun.5", GSUisFun( undefined ), false );
test( "isFun.6", GSUisFun( {} ), false );
test( "isFun.7", GSUisFun( [] ), false );
test( "isFun.8", GSUisFun( "" ), false );
test( "isFun.9", GSUisFun( "21" ), false );
test( "isFun.a", GSUisFun( 0 ), false );
test( "isFun.b", GSUisFun( GSUnoop ), true );
test( "isFun.c", GSUisFun( () => {} ), true );
} );
tests( "GSUisEqual", () => {
test( "isEqual.0", GSUisEqual( 0, 0 ), true );
test( "isEqual.1", GSUisEqual( 1, 1 ), true );
test( "isEqual.2", GSUisEqual( true, true ), true );
test( "isEqual.3", GSUisEqual( false, false ), true );
test( "isEqual.4", GSUisEqual( NaN, NaN ), true );
test( "isEqual.5", GSUisEqual( null, null ), true );
test( "isEqual.6", GSUisEqual( undefined, undefined ), true );
test( "isEqual.7", GSUisEqual( GSUnoop, GSUnoop ), true );
test( "isEqual.8", GSUisEqual( {}, {} ), true );
test( "isEqual.9", GSUisEqual( [], [] ), true );
test( "isEqual.a", GSUisEqual( [ 0 ], [ 0 ] ), true );
test( "isEqual.b", GSUisEqual( [ 0, 1 ], [ 0, 1 ] ), true );
test( "isEqual.c", GSUisEqual( [ 0, [ 1 ] ], [ 0, [ 1 ] ] ), true );
test( "isEqual.d", GSUisEqual( [ [ 0 ], [ [ 1 ] ] ], [ [ 0 ], [ [ 1 ] ] ] ), true );
test( "isEqual.e", GSUisEqual( [ 0, [ 1, {} ] ], [ 0, [ 1, {} ] ] ), true );
test( "isEqual.f", GSUisEqual( { a: 21 }, { a: 21 } ), true );
test( "isEqual.g", GSUisEqual( { a: 21, b: NaN, c: 42 }, { a: 21, b: NaN, c: 42 } ), true );
test( "isEqual.h", GSUisEqual( { a: [ 0, 1 ], b: NaN, c: 42 }, { a: [ 0, 1 ], b: NaN, c: 42 } ), true );
test( "isEqual.i", GSUisEqual( { a: [ 0, 1 ], b: NaN, c: { aa: 42 } }, { a: [ 0, 1 ], b: NaN, c: { aa: 42 } } ), true );
test( "isEqual.j", GSUisEqual( 0, "0" ), false );
test( "isEqual.k", GSUisEqual( 1, "1" ), false );
test( "isEqual.l", GSUisEqual( true, false ), false );
test( "isEqual.m", GSUisEqual( false, undefined ), false );
test( "isEqual.n", GSUisEqual( NaN, null ), false );
test( "isEqual.o", GSUisEqual( null, {} ), false );
test( "isEqual.p", GSUisEqual( undefined, null ), false );
test( "isEqual.q", GSUisEqual( {}, [] ), false );
test( "isEqual.r", GSUisEqual( [], "" ), false );
test( "isEqual.s", GSUisEqual( () => {}, () => {} ), false );
test( "isEqual.t", GSUisEqual( [], [ 0 ] ), false );
test( "isEqual.u", GSUisEqual( [ 0 ], [] ), false );
test( "isEqual.v", GSUisEqual( {}, { a: 0 } ), false );
test( "isEqual.w", GSUisEqual( { a: 0 }, {} ), false );
test( "isEqual.x", GSUisEqual( [ 0, 1, 2 ], [ 0, 1, 3 ] ), false );
test( "isEqual.y", GSUisEqual( [ 0, [ 1, 2 ] ], [ 0, [ 1, 3 ] ] ), false );
test( "isEqual.z", GSUisEqual( [ 0, [ 1, { a: 2 } ] ], [ 0, [ 1, { a: 3 } ] ] ), false );
test( "isEqual.A", GSUisEqual( [ 0, [ 1, { a: 2 } ] ], [ 0, [ 1, { b: 2 } ] ] ), false );
test( "isEqual.B", GSUisEqual( new Map(), new Map() ), true );
// test( "isEqual.C", GSUisEqual( new Map( [ 21 ] ), new Map( [ 21 ] ) ), true );
} );
tests( "GSUdotProp", () => {
const objDotProp = {};
testStrict( "dotProp.0", GSUdotProp( objDotProp ), objDotProp );
testStrict( "dotProp.1", GSUdotProp( objDotProp, "" ), objDotProp );
test( "dotProp.2", GSUdotProp( null, "" ), null );
test( "dotProp.3", GSUdotProp( true, "" ), true );
test( "dotProp.4", GSUdotProp( null, "a" ), undefined );
test( "dotProp.5", GSUdotProp( undefined, "" ), undefined );
test( "dotProp.6", GSUdotProp( true, "a" ), undefined );
test( "dotProp.7", GSUdotProp( true, "a.b" ), undefined );
test( "dotProp.8", GSUdotProp( false, "a" ), undefined );
test( "dotProp.9", GSUdotProp( {}, "a" ), undefined );
test( "dotProp.a", GSUdotProp( {}, "a.b" ), undefined );
test( "dotProp.b", GSUdotProp( {}, "a.b.c" ), undefined );
test( "dotProp.c", GSUdotProp( { a: 1 }, "a" ), 1 );
test( "dotProp.d", GSUdotProp( { a: 1 }, "b" ), undefined );
test( "dotProp.e", GSUdotProp( { a: 1 }, "b.c" ), undefined );
test( "dotProp.f", GSUdotProp( { a: { b: 2 } }, "a.b" ), 2 );
test( "dotProp.g", GSUdotProp( { a: { b: 2 } }, "a.c" ), undefined );
test( "dotProp.h", GSUdotProp( { a: { b: 2 } }, "a.c.d" ), undefined );
test( "dotProp.i", GSUdotProp( { a: { b: [ 3 ] } }, "a.b.0" ), 3 );
test( "dotProp.j", GSUdotProp( { a: { b: [ 3, 4 ] } }, "a.b.1" ), 4 );
test( "dotProp.k", GSUdotProp( { a: { b: [ 3, 4 ] } }, "a.b.2" ), undefined );
test( "dotProp.l", GSUdotProp( {}, "a" ), undefined );
test( "dotProp.m", GSUdotProp( { a: undefined }, "a" ), GSUdotProp.$undefined );
test( "dotProp.n", GSUdotProp( { a: 1 }, ".a" ), 1 );
} );
tests( "GSUforEach", () => {
const objFE = { a: 10, b: 20 };
const arrFE = [ 10, 20 ];
let resFE;
testStrict( "forEach.0", GSUforEach( objFE, GSUnoop ), objFE );
testStrict( "forEach.1", GSUforEach( arrFE, GSUnoop ), arrFE );
testStrict( "forEach.2", GSUforEach( null, null ), null );
testStrict( "forEach.3", GSUforEach( false, null ), false );
testStrict( "forEach.4", GSUforEach( undefined, null ), undefined );
testStrict( "forEach.5", GSUforEach( true, null ), true );
testStrict( "forEach.6", GSUforEach( 21, null ), 21 );
resFE = "";
GSUforEach( objFE, ( val, key, obj ) => { resFE += `${ key }:${ val }:${ obj === objFE }:` } );
test( "forEach.7", resFE, "a:10:true:b:20:true:" );
resFE = "";
GSUforEach( arrFE, ( val, key, obj ) => { resFE += `${ key }:${ val }:${ obj === arrFE }:` } );
test( "forEach.8", resFE, "0:10:true:1:20:true:" );
} );
tests( "GSUreduce", () => {
const fnSum = ( sum, n, i ) => sum + n + i;
test( "reduce.0", GSUreduce( NaN, null, 0 ), 0 );
test( "reduce.1", GSUreduce( null, null, 0 ), 0 );
test( "reduce.2", GSUreduce( true, null, 0 ), 0 );
test( "reduce.3", GSUreduce( false, null, 0 ), 0 );
test( "reduce.4", GSUreduce( undefined, null, 0 ), 0 );
test( "reduce.5", GSUreduce( GSUnoop, null, 0 ), 0 );
test( "reduce.6", GSUreduce( [], fnSum, 0 ), 0 );
test( "reduce.7", GSUreduce( {}, fnSum, 0 ), 0 );
test( "reduce.8", GSUreduce( [ 10, 20, 30 ], fnSum, 0 ), 63 );
test( "reduce.9", GSUreduce( { a: 10, b: 20, c: 30 }, fnSum, 0 ), "10a20b30c" );
} );
tests( "GSUmap", () => {
const dbl = n => n * 2;
const a = [ 0, 1, 2 ];
testStrict( "map.0", GSUmap( NaN, null ), NaN );
testStrict( "map.1", GSUmap( null, null ), null );
testStrict( "map.2", GSUmap( true, null ), true );
testStrict( "map.3", GSUmap( false, null ), false );
testStrict( "map.4", GSUmap( undefined, null ), undefined );
testStrict( "map.5", GSUmap( GSUnoop, null ), GSUnoop );
test( "map.6", GSUmap( [], GSUnoop ), [] );
test( "map.7", GSUmap( {}, GSUnoop ), {} );
test( "map.8", GSUmap( [ 1, 2, 3 ], dbl ), [ 2, 4, 6 ] );
test( "map.9", GSUmap( { a: 1, b: 2, c: 3 }, dbl ), { a: 2, b: 4, c: 6 } );
} );
tests( "GSUfind", () => {
const dbl = n => n * 2;
const a123 = [ 1, 2, 3 ];
const a456 = { a: 4, b: 5, c: 6 };
testStrict( "find_0", GSUfind( NaN, null ), undefined );
testStrict( "find_1", GSUfind( null, null ), undefined );
testStrict( "find_2", GSUfind( true, null ), undefined );
testStrict( "find_3", GSUfind( false, null ), undefined );
testStrict( "find_4", GSUfind( undefined, null ), undefined );
testStrict( "find_5", GSUfind( GSUnoop, null ), undefined );
testStrict( "find_6", GSUfind( [], GSUnoop ), undefined );
testStrict( "find_7", GSUfind( {}, GSUnoop ), undefined );
testStrict( "find_8", GSUfind( [ 21 ], GSUnoop ), undefined );
testStrict( "find_9", GSUfind( { a: 21 }, GSUnoop ), undefined );
testStrict( "find_a", GSUfind( a123, ( n, i, a ) => n === 1 && i === 0 && a === a123 ), 1 );
testStrict( "find_b", GSUfind( a123, ( n, i, a ) => n === 2 && i === 1 && a === a123 ), 2 );
testStrict( "find_c", GSUfind( a123, ( n, i, a ) => n === 3 && i === 2 && a === a123 ), 3 );
testStrict( "find_d", GSUfind( a456, ( n, k, a ) => n === 4 && k === "a" && a === a456 ), 4 );
testStrict( "find_e", GSUfind( a456, ( n, k, a ) => n === 5 && k === "b" && a === a456 ), 5 );
testStrict( "find_f", GSUfind( a456, ( n, k, a ) => n === 6 && k === "c" && a === a456 ), 6 );
testStrict( "find_g", GSUfind( a123, n => n === 4 ), undefined );
testStrict( "find_h", GSUfind( a456, n => n === 7 ), undefined );
} );
tests( "GSUfindIndex", () => {
const dbl = n => n * 2;
const a123 = [ 1, 2, 3 ];
const a456 = { a: 4, b: 5, c: 6 };
testStrict( "findIndex_0", GSUfindIndex( NaN, null ), -1 );
testStrict( "findIndex_1", GSUfindIndex( null, null ), -1 );
testStrict( "findIndex_2", GSUfindIndex( true, null ), -1 );
testStrict( "findIndex_3", GSUfindIndex( false, null ), -1 );
testStrict( "findIndex_4", GSUfindIndex( undefined, null ), -1 );
testStrict( "findIndex_5", GSUfindIndex( GSUnoop, null ), -1 );
testStrict( "findIndex_6", GSUfindIndex( [], GSUnoop ), -1 );
testStrict( "findIndex_7", GSUfindIndex( {}, GSUnoop ), -1 );
testStrict( "findIndex_8", GSUfindIndex( [ 21 ], GSUnoop ), -1 );
testStrict( "findIndex_9", GSUfindIndex( { a: 21 }, GSUnoop ), -1 );
testStrict( "findIndex_a", GSUfindIndex( a123, ( n, i, a ) => n === 1 && i === 0 && a === a123 ), 0 );
testStrict( "findIndex_b", GSUfindIndex( a123, ( n, i, a ) => n === 2 && i === 1 && a === a123 ), 1 );
testStrict( "findIndex_c", GSUfindIndex( a123, ( n, i, a ) => n === 3 && i === 2 && a === a123 ), 2 );
testStrict( "findIndex_d", GSUfindIndex( a456, ( n, k, a ) => n === 4 && k === "a" && a === a456 ), "a" );
testStrict( "findIndex_e", GSUfindIndex( a456, ( n, k, a ) => n === 5 && k === "b" && a === a456 ), "b" );
testStrict( "findIndex_f", GSUfindIndex( a456, ( n, k, a ) => n === 6 && k === "c" && a === a456 ), "c" );
testStrict( "findIndex_g", GSUfindIndex( a123, n => n === 4 ), -1 );
testStrict( "findIndex_h", GSUfindIndex( a456, n => n === 7 ), -1 );
} );
tests( "GSUsome", () => {
const fnSome21 = n => n === 21;
test( "some_0", GSUsome( NaN, null ), false );
test( "some_1", GSUsome( null, null ), false );
test( "some_2", GSUsome( true, null ), false );
test( "some_3", GSUsome( false, null ), false );
test( "some_4", GSUsome( undefined, null ), false );
test( "some_5", GSUsome( GSUnoop, null ), false );
test( "some_6", GSUsome( [], fnSome21 ), false );
test( "some_7", GSUsome( {}, fnSome21 ), false );
test( "some_8", GSUsome( [ 0, 1, 2 ], fnSome21 ), false );
test( "some_9", GSUsome( { a: 0, b: 1 }, fnSome21 ), false );
test( "some_a", GSUsome( [ 21 ], fnSome21 ), true );
test( "some_b", GSUsome( [ 0, 1, 21 ], fnSome21 ), true );
test( "some_c", GSUsome( { a: 0, b: 21 }, fnSome21 ), true );
test( "some_d", GSUsome( [], () => true ), false );
test( "some_e", GSUsome( [ 1 ], () => true ), true );
test( "some_f", GSUsome( [ 0 ], () => true ), true );
test( "some_g", GSUsome( [], () => false ), false );
test( "some_h", GSUsome( [ 1 ], () => false ), false );
test( "some_i", GSUsome( [ 0 ], () => false ), false );
} );
tests( "GSUHztoX", () => {
test( "HztoX.0", GSUmathFix( GSUHztoX( GSUXtoHz( .5 ) ), 8 ), .5 );
test( "HztoX.1", GSUHztoX( 1 ), 1 );
test( "HztoX.2", GSUXtoHz( 1 ), 1 );
} );
tests( "GSUnewArray", () => {
test( "newArray.0", GSUnewArray( 0 ), [] );
test( "newArray.1", GSUnewArray( 1 ).length, 1 );
test( "newArray.2", GSUnewArray( 2 ).length, 2 );
test( "newArray.3", GSUnewArray( 3, 7 ), [ 7, 7, 7 ] );
test( "newArray.4", GSUnewArray( 3, i => i ), [ 0, 1, 2 ] );
} );
tests( "GSUarrayEq", () => {
test( "arrayEq_0", GSUarrayEq( [], [] ), true );
test( "arrayEq_1", GSUarrayEq( [ 0 ], [ 0 ] ), true );
test( "arrayEq_2", GSUarrayEq( [ 0, 0 ], [ 0, 0 ] ), true );
test( "arrayEq_3", GSUarrayEq( [ .1 + .2 ], [ .1 + .2 ] ), true );
test( "arrayEq_4", GSUarrayEq( [ -1 ], [ -1 ] ), true );
test( "arrayEq_5", GSUarrayEq( [ 0 ], [ 1 ], 1 ), true );
test( "arrayEq_6", GSUarrayEq( [ 0, 0 ], [ 0, 0.01 ], .01 ), true );
test( "arrayEq_7", GSUarrayEq( [ 0, 1 ], [ 0, 1.01 ], .01 ), true );
test( "arrayEq_8", GSUarrayEq( [ 0 ], [ 1 ] ), false );
test( "arrayEq_9", GSUarrayEq( [ 0 ], [ 0, 0 ], 1 ), false );
test( "arrayEq_a", GSUarrayEq( [ 0 ], [ 0.0101 ], .01 ), false );