cno-bedrock 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/package.json +116 -116
- package/scripts/generate-docs.js +0 -0
- package/src/cno-assert.js +222 -15
- package/src/cno-assert.test.js +331 -0
- package/src/cno-base64.js +230 -0
- package/src/cno-base64.test.js +262 -0
- package/src/cno-bytes.js +387 -0
- package/src/cno-bytes.test.js +222 -0
- package/src/cno-constants.js +121 -0
- package/src/cno-files.js +2135 -0
- package/src/cno-files.test.js +939 -0
- package/src/cno-math.js +407 -0
- package/src/cno-math.test.js +249 -0
- package/src/cno-noop.js +6 -2
- package/src/cno-options.js +73 -4
- package/src/cno-options.test.js +65 -0
- package/src/cno-sha2-256.js +831 -0
- package/src/cno-sha2-256.test.js +697 -0
- package/src/cno-test-matrix.js +709 -0
- package/src/cno-test-matrix.test.js +199 -0
- package/src/cno-timed-cache-map.js +103 -0
- package/src/cno-timed-cache-map.test.js +113 -0
- package/src/cno-tree.js +365 -0
- package/src/cno-tree.test.js +147 -0
- package/src/cno-utility.js +545 -2
- package/src/cno-utility.test.js +276 -0
- package/src/cno-vector.js +1053 -0
- package/src/cno-vector.test.js +523 -0
- package/src/lib.js +5 -138
- package/src/lib.test.js +19 -7
- package/src/stream-test.js +116 -0
- package/test/big-lorem.txt +29 -0
package/src/cno-math.js
ADDED
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
# [cno-math.js](src/cno-math.js)
|
|
4
|
+
> Missing math library functions.
|
|
5
|
+
|
|
6
|
+
Author: Anadian
|
|
7
|
+
|
|
8
|
+
Code license: MIT
|
|
9
|
+
```
|
|
10
|
+
Copyright 2025 Anadian
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
12
|
+
software and associated documentation files (the "Software"), to deal in the Software
|
|
13
|
+
without restriction, including without limitation the rights to use, copy, modify,
|
|
14
|
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
15
|
+
permit persons to whom the Software is furnished to do so, subject to the following
|
|
16
|
+
conditions:
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all copies
|
|
18
|
+
or substantial portions of the Software.
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
20
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
21
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
22
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
23
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
24
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
```
|
|
26
|
+
Documentation License: [](http://creativecommons.org/licenses/by-sa/4.0/)
|
|
27
|
+
> The source-code comments and documentation are written in [GitHub Flavored Markdown](https://github.github.com/gfm/).
|
|
28
|
+
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
//# Dependencies
|
|
32
|
+
//## Internal
|
|
33
|
+
import CONSTANTS from './cno-constants.js';
|
|
34
|
+
import Vector from './cno-vector.js';
|
|
35
|
+
import { removeFromArrayAt } from './cno-utility.js';
|
|
36
|
+
import { assertInstanceof } from './cno-assert.js';
|
|
37
|
+
import { returnNull } from './cno-noop.js';
|
|
38
|
+
//## Standard
|
|
39
|
+
//## External
|
|
40
|
+
//import { _.clamp, _.inRange, eq, gte, gt, lte, lt } from 'lodash';
|
|
41
|
+
import _ from 'lodash';
|
|
42
|
+
import * as MathJS from 'mathjs';
|
|
43
|
+
|
|
44
|
+
//# Constants
|
|
45
|
+
const FILENAME = 'cno-math.js';
|
|
46
|
+
|
|
47
|
+
const COMPARISON_PRIMITIVES = {};
|
|
48
|
+
Object.defineProperties( COMPARISON_PRIMITIVES, {
|
|
49
|
+
equal: {
|
|
50
|
+
value: _.eq,
|
|
51
|
+
enumerable: true
|
|
52
|
+
},
|
|
53
|
+
greaterOrEqual: {
|
|
54
|
+
value: _.gte,
|
|
55
|
+
enumerable: true
|
|
56
|
+
},
|
|
57
|
+
greater: {
|
|
58
|
+
value: _.gt,
|
|
59
|
+
enumerable: true
|
|
60
|
+
},
|
|
61
|
+
lesserOrEqual: {
|
|
62
|
+
value: _.lte,
|
|
63
|
+
enumerable: true
|
|
64
|
+
},
|
|
65
|
+
lesser: {
|
|
66
|
+
value: _.lt,
|
|
67
|
+
enumerable: true
|
|
68
|
+
}
|
|
69
|
+
} );
|
|
70
|
+
const BOUND_TYPE = {};
|
|
71
|
+
Object.defineProperties( BOUND_TYPE, {
|
|
72
|
+
NORMAL: {
|
|
73
|
+
value: 0, // Inclusive on lower bound, exclusive on upper bound.
|
|
74
|
+
enumerable: true
|
|
75
|
+
},
|
|
76
|
+
INCLUSIVE: {
|
|
77
|
+
value: 1, // Inclusive on both
|
|
78
|
+
enumerable: true
|
|
79
|
+
},
|
|
80
|
+
EXCLUSIVE: {
|
|
81
|
+
value: 2, // Exclusive on both
|
|
82
|
+
enumerable: true
|
|
83
|
+
}
|
|
84
|
+
} );
|
|
85
|
+
//## Errors
|
|
86
|
+
|
|
87
|
+
//# Global Variables
|
|
88
|
+
/**## Functions*/
|
|
89
|
+
|
|
90
|
+
function bitRotateLeft( bitsize, x, places ){
|
|
91
|
+
const bitmask = 2**bitsize - 1; // Needed for javascript because all numbers are 64-bit.
|
|
92
|
+
return ( ( x << places | x >> ( bitsize - places ) ) & bitmask );
|
|
93
|
+
}
|
|
94
|
+
function bitRotateRight( bitsize, x, places ){
|
|
95
|
+
const bitmask = 2**bitsize - 1; // Needed for javascript because all numbers are 64-bit.
|
|
96
|
+
return ( ( x >> places | x << ( bitsize - places ) ) & bitmask );
|
|
97
|
+
}
|
|
98
|
+
function clamp( input, min, max ){
|
|
99
|
+
return _.clamp( input, min, max );
|
|
100
|
+
} // use _.clamp
|
|
101
|
+
function overflow( input, min, max ){
|
|
102
|
+
var _return = 0.0;
|
|
103
|
+
const range = ( max - min );
|
|
104
|
+
if( input < min ){
|
|
105
|
+
_return = ( max - ( ( min - input ) % range ) );
|
|
106
|
+
} else if( input > max ){
|
|
107
|
+
_return = ( min + ( ( input - max ) % range ) );
|
|
108
|
+
} else{
|
|
109
|
+
_return = input;
|
|
110
|
+
}
|
|
111
|
+
return _return;
|
|
112
|
+
}
|
|
113
|
+
function inRange( input, min, max ){
|
|
114
|
+
return _.inRange( input, min, max );
|
|
115
|
+
} // use _.inRange
|
|
116
|
+
// InRange: use _._.inRange
|
|
117
|
+
function normalisePolarAngle( angle_deg ){
|
|
118
|
+
return overflow( angle_deg, 0, 360 );
|
|
119
|
+
}
|
|
120
|
+
function Bound( min, max, mode = BOUND_TYPE.NORMAL ){
|
|
121
|
+
if( !new.target ){
|
|
122
|
+
return new Bound( min, max, mode );
|
|
123
|
+
}
|
|
124
|
+
Object.defineProperties( this, {
|
|
125
|
+
mode: {
|
|
126
|
+
value: mode,
|
|
127
|
+
writable: true,
|
|
128
|
+
enumerable: true
|
|
129
|
+
},
|
|
130
|
+
lower: {
|
|
131
|
+
value: min,
|
|
132
|
+
writable: true,
|
|
133
|
+
enumerable: true
|
|
134
|
+
},
|
|
135
|
+
upper: {
|
|
136
|
+
value: max,
|
|
137
|
+
writable: true,
|
|
138
|
+
enumerable: true
|
|
139
|
+
},
|
|
140
|
+
higher: {
|
|
141
|
+
get(){
|
|
142
|
+
return this.upper;
|
|
143
|
+
},
|
|
144
|
+
enumerable: false
|
|
145
|
+
},
|
|
146
|
+
size: {
|
|
147
|
+
get(){
|
|
148
|
+
return this.upper - this.lower;
|
|
149
|
+
},
|
|
150
|
+
enumerable: true
|
|
151
|
+
},
|
|
152
|
+
inNormal: {
|
|
153
|
+
value: ( x ) => { return inRange( x, this.lower, this.upper ); },
|
|
154
|
+
enumerable: false
|
|
155
|
+
},
|
|
156
|
+
inInclusive: {
|
|
157
|
+
value: ( x ) => { return COMPARISON_PRIMITIVES.greaterOrEqual( x, this.lower ) && COMPARISON_PRIMITIVES.lesserOrEqual( x, this.upper ); },
|
|
158
|
+
enumerable: false
|
|
159
|
+
},
|
|
160
|
+
inExclusive: {
|
|
161
|
+
value: ( x ) => { return COMPARISON_PRIMITIVES.greater( x, this.lower ) && COMPARISON_PRIMITIVES.lesser( x, this.upper ); },
|
|
162
|
+
enumerable: false
|
|
163
|
+
},
|
|
164
|
+
isIn: {
|
|
165
|
+
value: ( x ) => {
|
|
166
|
+
var _return = false;
|
|
167
|
+
switch( this.mode ){
|
|
168
|
+
case BOUND_TYPE.INCLUSIVE: _return = this.inInclusive( x ); break;
|
|
169
|
+
case BOUND_TYPE.EXCLUSIVE: _return = this.inExclusive( x ); break;
|
|
170
|
+
default: _return = this.inNormal( x ); break;
|
|
171
|
+
}
|
|
172
|
+
return _return;
|
|
173
|
+
},
|
|
174
|
+
enumerable: false
|
|
175
|
+
},
|
|
176
|
+
overlap: {
|
|
177
|
+
value: ( bound ) => {
|
|
178
|
+
var _return = 0;
|
|
179
|
+
if( this.isIn( bound.lower ) ){
|
|
180
|
+
_return |= 0b01;
|
|
181
|
+
}
|
|
182
|
+
if( this.isIn( bound.upper ) ){
|
|
183
|
+
_return |= 0b10;
|
|
184
|
+
}
|
|
185
|
+
if( bound.isIn( this.lower ) ){
|
|
186
|
+
_return |= 0b0100;
|
|
187
|
+
}
|
|
188
|
+
if( bound.isIn( this.upper ) ){
|
|
189
|
+
_return |= 0b1000;
|
|
190
|
+
}
|
|
191
|
+
return _return;
|
|
192
|
+
},
|
|
193
|
+
enumerable: false
|
|
194
|
+
},
|
|
195
|
+
min: {
|
|
196
|
+
value: ( x ) => {
|
|
197
|
+
if( COMPARISON_PRIMITIVES.lesserOrEqual( x, this.upper ) ) return x;
|
|
198
|
+
else return this.upper;
|
|
199
|
+
},
|
|
200
|
+
enumerable: false
|
|
201
|
+
},
|
|
202
|
+
max: {
|
|
203
|
+
value: ( x ) => {
|
|
204
|
+
if( COMPARISON_PRIMITIVES.greaterOrEqual( x, this.lower ) ) return x;
|
|
205
|
+
else return this.lower;
|
|
206
|
+
},
|
|
207
|
+
enumerable: false
|
|
208
|
+
},
|
|
209
|
+
clamp: {
|
|
210
|
+
value: ( x ) => {
|
|
211
|
+
return this.min( this.max( x ) );
|
|
212
|
+
},
|
|
213
|
+
enumerable: false
|
|
214
|
+
},
|
|
215
|
+
merge: {
|
|
216
|
+
value: ( bound ) => {
|
|
217
|
+
this.lower = Math.min( this.lower, bound.lower );
|
|
218
|
+
this.upper = Math.max( this.upper, bound.upper );
|
|
219
|
+
},
|
|
220
|
+
enumerable: false
|
|
221
|
+
},
|
|
222
|
+
toString: {
|
|
223
|
+
value: () => {
|
|
224
|
+
return `${this.mode === BOUND_TYPE.EXCLUSIVE ? '(' : '['}${this.lower},${this.upper}${this.mode === BOUND_TYPE.INCLUSIVE ? ']' : ')'}`;
|
|
225
|
+
},
|
|
226
|
+
enumerable: false
|
|
227
|
+
}
|
|
228
|
+
} );
|
|
229
|
+
return this;
|
|
230
|
+
} // Bound
|
|
231
|
+
Bound.assertBound = function( bound ){
|
|
232
|
+
assertInstanceof( bound, Bound );
|
|
233
|
+
}
|
|
234
|
+
Bound.isBound = function( bound, log_function = returnNull ){
|
|
235
|
+
var _return = false;
|
|
236
|
+
try{
|
|
237
|
+
Bound.assertBound( bound );
|
|
238
|
+
_return = true;
|
|
239
|
+
} catch( error ){
|
|
240
|
+
log_function( error );
|
|
241
|
+
_return = false;
|
|
242
|
+
}
|
|
243
|
+
return _return;
|
|
244
|
+
}
|
|
245
|
+
Object.defineProperties( Bound, {
|
|
246
|
+
sortLowestFirst: {
|
|
247
|
+
value: function( bound_a, bound_b ){
|
|
248
|
+
return bound_a.lower - bound_b.lower;
|
|
249
|
+
},
|
|
250
|
+
writable: false,
|
|
251
|
+
enumerable: true
|
|
252
|
+
},
|
|
253
|
+
MODES: {
|
|
254
|
+
value: BOUND_TYPE,
|
|
255
|
+
writable: false,
|
|
256
|
+
enumerable: true
|
|
257
|
+
}
|
|
258
|
+
} );
|
|
259
|
+
function BoundList(){
|
|
260
|
+
if( !new.target ){
|
|
261
|
+
return new BoundList();
|
|
262
|
+
}
|
|
263
|
+
Object.defineProperties( this, {
|
|
264
|
+
boundsArray: {
|
|
265
|
+
value: [],
|
|
266
|
+
writable: true,
|
|
267
|
+
enumerable: true
|
|
268
|
+
},
|
|
269
|
+
bounds: {
|
|
270
|
+
get(){
|
|
271
|
+
return this.boundsArray.length;
|
|
272
|
+
},
|
|
273
|
+
enumerable: true
|
|
274
|
+
},
|
|
275
|
+
lowest: {
|
|
276
|
+
get(){
|
|
277
|
+
return this.boundsArray[0].lower;
|
|
278
|
+
},
|
|
279
|
+
enumerable: true
|
|
280
|
+
},
|
|
281
|
+
highest: {
|
|
282
|
+
get(){
|
|
283
|
+
return this.boundsArray[this.bounds - 1].upper;
|
|
284
|
+
},
|
|
285
|
+
enumerable: true
|
|
286
|
+
},
|
|
287
|
+
sortLowestFirst: {
|
|
288
|
+
value: () => {
|
|
289
|
+
this.boundsArray.sort( Bound.sortLowestFirst );
|
|
290
|
+
},
|
|
291
|
+
enumerable: false
|
|
292
|
+
},
|
|
293
|
+
reduce: {
|
|
294
|
+
value: () => {
|
|
295
|
+
var need_repeat = false;
|
|
296
|
+
do{
|
|
297
|
+
need_repeat = false;
|
|
298
|
+
for( var i = 0; i < ( this.bounds - 1 ); i++ ){
|
|
299
|
+
var bound_a = this.boundsArray[i];
|
|
300
|
+
for( var j = (i + 1); j < this.bounds; ){
|
|
301
|
+
var bound_b = this.boundsArray[j];
|
|
302
|
+
var overlap_report = bound_a.overlap( bound_b );
|
|
303
|
+
if( overlap_report != 0 ){
|
|
304
|
+
// Remove bound_b
|
|
305
|
+
bound_a.merge( bound_b );
|
|
306
|
+
this.boundsArray[i] = bound_a;
|
|
307
|
+
this.boundsArray = removeFromArrayAt( this.boundsArray, j );
|
|
308
|
+
need_repeat = true;
|
|
309
|
+
} else{
|
|
310
|
+
j++;
|
|
311
|
+
}
|
|
312
|
+
} // for j
|
|
313
|
+
} // for i
|
|
314
|
+
} while( need_repeat );
|
|
315
|
+
this.sortLowestFirst();
|
|
316
|
+
},
|
|
317
|
+
enumerable: false
|
|
318
|
+
},
|
|
319
|
+
mergeAdd: {
|
|
320
|
+
value: ( new_bound ) => {
|
|
321
|
+
var merged = false;
|
|
322
|
+
for( var i = 0; i < this.bounds; i++ ){
|
|
323
|
+
var overlap_report = this.boundsArray[i].overlap( new_bound );
|
|
324
|
+
if( overlap_report != 0 ){
|
|
325
|
+
this.boundsArray[i].merge( new_bound );
|
|
326
|
+
merged = true;
|
|
327
|
+
i = this.bounds;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if( merged === false ){
|
|
331
|
+
this.boundsArray.push( new_bound );
|
|
332
|
+
this.reduce();
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
enumerable: false
|
|
336
|
+
},
|
|
337
|
+
isIn: {
|
|
338
|
+
value: ( x ) => {
|
|
339
|
+
var _return = false;
|
|
340
|
+
for( const bound of this.boundsArray ){
|
|
341
|
+
if( bound.isIn( x ) ){
|
|
342
|
+
_return = true;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return _return;
|
|
347
|
+
},
|
|
348
|
+
enumerable: false
|
|
349
|
+
}
|
|
350
|
+
} );
|
|
351
|
+
} // BoundList
|
|
352
|
+
|
|
353
|
+
const NAMESPACE = { ...MathJS, ...CONSTANTS, ...COMPARISON_PRIMITIVES };
|
|
354
|
+
Object.defineProperties( NAMESPACE, {
|
|
355
|
+
Vector: {
|
|
356
|
+
value: Vector,
|
|
357
|
+
enumerable: true
|
|
358
|
+
},
|
|
359
|
+
bitRotateLeft: {
|
|
360
|
+
value: bitRotateLeft,
|
|
361
|
+
enumerable: true
|
|
362
|
+
},
|
|
363
|
+
bitRotateRight: {
|
|
364
|
+
value: bitRotateRight,
|
|
365
|
+
enumerable: true
|
|
366
|
+
},
|
|
367
|
+
clamp: {
|
|
368
|
+
value: clamp,
|
|
369
|
+
enumerable: true
|
|
370
|
+
},
|
|
371
|
+
inRange: {
|
|
372
|
+
value: inRange,
|
|
373
|
+
enumerable: true
|
|
374
|
+
},
|
|
375
|
+
overflow: {
|
|
376
|
+
value: overflow,
|
|
377
|
+
enumerable: true
|
|
378
|
+
},
|
|
379
|
+
normalisePolarAngle: {
|
|
380
|
+
value: normalisePolarAngle,
|
|
381
|
+
enumerable: true
|
|
382
|
+
},
|
|
383
|
+
Bound: {
|
|
384
|
+
value: Bound,
|
|
385
|
+
enumerable: true
|
|
386
|
+
},
|
|
387
|
+
BoundList: {
|
|
388
|
+
value: BoundList,
|
|
389
|
+
enumerable: true
|
|
390
|
+
}
|
|
391
|
+
} );
|
|
392
|
+
|
|
393
|
+
/*for( const key of Object.keys( MathJS ) ){
|
|
394
|
+
export { MathJS[key] as key };
|
|
395
|
+
}
|
|
396
|
+
for( const key of Object.keys( CONSTANTS ) ){
|
|
397
|
+
export { CONSTANS[key] as key };
|
|
398
|
+
}
|
|
399
|
+
for( const key of Object.keys( COMPARISON_PRIMITIVES ) ){
|
|
400
|
+
export { COMPARISON_PRIMITIVES[key] as key };
|
|
401
|
+
}*/
|
|
402
|
+
export * from 'mathjs';
|
|
403
|
+
export * from './cno-constants.js';
|
|
404
|
+
export { NAMESPACE as default, /*...MathJS, ...CONSTANTS, ...COMPARISON_PRIMITIVES,*/ Vector as vector, CONSTANTS, bitRotateLeft, bitRotateRight, clamp, inRange, overflow, normalisePolarAngle, Bound, BoundList };
|
|
405
|
+
|
|
406
|
+
// cno-math.js EOF
|
|
407
|
+
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
# [cno-math.test.js](src/cno-math.test.js)
|
|
4
|
+
> Tests for [`cno-math`](src/cno-math.js).
|
|
5
|
+
|
|
6
|
+
Author: Anadian
|
|
7
|
+
|
|
8
|
+
Code license: MIT
|
|
9
|
+
```
|
|
10
|
+
Copyright 2025 Anadian
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
12
|
+
software and associated documentation files (the "Software"), to deal in the Software
|
|
13
|
+
without restriction, including without limitation the rights to use, copy, modify,
|
|
14
|
+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
15
|
+
permit persons to whom the Software is furnished to do so, subject to the following
|
|
16
|
+
conditions:
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all copies
|
|
18
|
+
or substantial portions of the Software.
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
20
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
21
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
22
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
23
|
+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
24
|
+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
25
|
+
```
|
|
26
|
+
Documentation License: [](http://creativecommons.org/licenses/by-sa/4.0/)
|
|
27
|
+
> The source-code comments and documentation are written in [GitHub Flavored Markdown](https://github.github.com/gfm/).
|
|
28
|
+
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
//# Dependencies
|
|
32
|
+
//## Internal
|
|
33
|
+
import defaultExport from './cno-math.js';
|
|
34
|
+
import * as namespaceExport from './cno-math.js';
|
|
35
|
+
import TestNS from './cno-test-matrix.js';
|
|
36
|
+
import AssertNS from './cno-assert.js';
|
|
37
|
+
import { inspThis } from './cno-utility.js';
|
|
38
|
+
//## Standard
|
|
39
|
+
//## External
|
|
40
|
+
|
|
41
|
+
//# Constants
|
|
42
|
+
const FILENAME = 'cno-math.test.js';
|
|
43
|
+
|
|
44
|
+
//## Errors
|
|
45
|
+
|
|
46
|
+
//# Global Variables
|
|
47
|
+
/**## Functions*/
|
|
48
|
+
TestNS.test( 'bitRotateLeft', async function( t ){
|
|
49
|
+
//console.error( inspThis.call( defaultExport ) );
|
|
50
|
+
var tm = new TestNS.TestMatrix( { testContext: t } );
|
|
51
|
+
tm.addFunction( { name: 'defaultExport', func: defaultExport.bitRotateLeft } );
|
|
52
|
+
tm.addFunction( { name: 'namespaceExport', func: namespaceExport.bitRotateLeft } );
|
|
53
|
+
tm.addCondition( {
|
|
54
|
+
name: '8-bit-shift',
|
|
55
|
+
success: true,
|
|
56
|
+
args: [ 8, 0b1000_0001, 1 ],
|
|
57
|
+
expected: 0b0000_0011
|
|
58
|
+
} );
|
|
59
|
+
await tm.run();
|
|
60
|
+
} );
|
|
61
|
+
TestNS.test( 'bitRotateRight', async function( t ){
|
|
62
|
+
//console.error( inspThis.call( defaultExport ) );
|
|
63
|
+
var tm = new TestNS.TestMatrix( { testContext: t } );
|
|
64
|
+
tm.addFunction( { name: 'defaultExport', func: defaultExport.bitRotateRight } );
|
|
65
|
+
tm.addFunction( { name: 'namespaceExport', func: namespaceExport.bitRotateRight } );
|
|
66
|
+
tm.addCondition( {
|
|
67
|
+
name: '8-bit-shift',
|
|
68
|
+
success: true,
|
|
69
|
+
args: [ 8, 0b1000_0001, 1 ],
|
|
70
|
+
expected: 0b1100_0000
|
|
71
|
+
} );
|
|
72
|
+
await tm.run();
|
|
73
|
+
} );
|
|
74
|
+
TestNS.test( 'clamp', async function( t ){
|
|
75
|
+
//console.error( inspThis.call( defaultExport ) );
|
|
76
|
+
var tm = new TestNS.TestMatrix( { testContext: t } );
|
|
77
|
+
tm.addFunction( { name: 'defaultExport', func: defaultExport.clamp } );
|
|
78
|
+
tm.addFunction( { name: 'namespaceExport', func: namespaceExport.clamp } );
|
|
79
|
+
tm.addCondition( {
|
|
80
|
+
name: 'safe',
|
|
81
|
+
success: true,
|
|
82
|
+
args: [ 3, 1, 5 ],
|
|
83
|
+
expected: 3
|
|
84
|
+
} );
|
|
85
|
+
tm.addCondition( {
|
|
86
|
+
name: 'over',
|
|
87
|
+
success: true,
|
|
88
|
+
args: [ 6, 1, 5 ],
|
|
89
|
+
expected: 5
|
|
90
|
+
} );
|
|
91
|
+
tm.addCondition( {
|
|
92
|
+
name: 'under',
|
|
93
|
+
success: true,
|
|
94
|
+
args: [ -1, 1, 5 ],
|
|
95
|
+
expected: 1
|
|
96
|
+
} );
|
|
97
|
+
await tm.run();
|
|
98
|
+
} );
|
|
99
|
+
TestNS.test( 'overflow', async function( t ){
|
|
100
|
+
//console.error( inspThis.call( defaultExport ) );
|
|
101
|
+
var tm = new TestNS.TestMatrix( { testContext: t } );
|
|
102
|
+
tm.addFunction( { name: 'defaultExport', func: defaultExport.overflow } );
|
|
103
|
+
tm.addFunction( { name: 'namespaceExport', func: namespaceExport.overflow } );
|
|
104
|
+
tm.addCondition( {
|
|
105
|
+
name: 'safe',
|
|
106
|
+
success: true,
|
|
107
|
+
args: [ 5, 1, 5 ],
|
|
108
|
+
expected: 5
|
|
109
|
+
} );
|
|
110
|
+
tm.addCondition( {
|
|
111
|
+
name: 'over',
|
|
112
|
+
success: true,
|
|
113
|
+
args: [ 5.25, 1, 5 ],
|
|
114
|
+
expected: 1.25
|
|
115
|
+
} );
|
|
116
|
+
tm.addCondition( {
|
|
117
|
+
name: 'under',
|
|
118
|
+
success: true,
|
|
119
|
+
args: [ -1.5, 1, 5 ],
|
|
120
|
+
expected: 2.5
|
|
121
|
+
} );
|
|
122
|
+
await tm.run();
|
|
123
|
+
} );
|
|
124
|
+
TestNS.test( 'inRange', async function( t ){
|
|
125
|
+
//console.error( inspThis.call( defaultExport ) );
|
|
126
|
+
var tm = new TestNS.TestMatrix( { testContext: t } );
|
|
127
|
+
tm.addFunction( { name: 'defaultExport', func: defaultExport.inRange } );
|
|
128
|
+
tm.addFunction( { name: 'namespaceExport', func: namespaceExport.inRange } );
|
|
129
|
+
tm.addCondition( {
|
|
130
|
+
name: 'safe',
|
|
131
|
+
success: true,
|
|
132
|
+
args: [ 3, 1, 5 ],
|
|
133
|
+
expected: true
|
|
134
|
+
} );
|
|
135
|
+
tm.addCondition( {
|
|
136
|
+
name: 'over',
|
|
137
|
+
success: true,
|
|
138
|
+
args: [ 5, 1, 5 ],
|
|
139
|
+
expected: false
|
|
140
|
+
} );
|
|
141
|
+
tm.addCondition( {
|
|
142
|
+
name: 'under',
|
|
143
|
+
success: true,
|
|
144
|
+
args: [ -1, 1, 5 ],
|
|
145
|
+
expected: false
|
|
146
|
+
} );
|
|
147
|
+
await tm.run();
|
|
148
|
+
} );
|
|
149
|
+
TestNS.test( 'normalisePolarAngle', async function( t ){
|
|
150
|
+
//console.error( inspThis.call( defaultExport ) );
|
|
151
|
+
var tm = new TestNS.TestMatrix( { testContext: t } );
|
|
152
|
+
tm.addFunction( { name: 'defaultExport', func: defaultExport.normalisePolarAngle } );
|
|
153
|
+
tm.addFunction( { name: 'namespaceExport', func: namespaceExport.normalisePolarAngle } );
|
|
154
|
+
tm.addCondition( {
|
|
155
|
+
name: 'safe',
|
|
156
|
+
success: true,
|
|
157
|
+
args: [ 240 ],
|
|
158
|
+
expected: 240
|
|
159
|
+
} );
|
|
160
|
+
tm.addCondition( {
|
|
161
|
+
name: 'over',
|
|
162
|
+
success: true,
|
|
163
|
+
args: [ 721 ],
|
|
164
|
+
expected: 1
|
|
165
|
+
} );
|
|
166
|
+
tm.addCondition( {
|
|
167
|
+
name: 'under',
|
|
168
|
+
success: true,
|
|
169
|
+
args: [ -45 ],
|
|
170
|
+
expected: 315
|
|
171
|
+
} );
|
|
172
|
+
await tm.run();
|
|
173
|
+
} );
|
|
174
|
+
TestNS.test( 'Bound', async function( t ){
|
|
175
|
+
var tm = new TestNS.TestMatrix( { testContext: t } );
|
|
176
|
+
var bound = defaultExport.Bound( 1, 5 );
|
|
177
|
+
AssertNS.deepStrictEqual( namespaceExport.Bound.isBound( bound ), true );
|
|
178
|
+
AssertNS.deepStrictEqual( defaultExport.Bound.isBound( { lower: 1, upper: 1 } ), false );
|
|
179
|
+
AssertNS.deepStrictEqual( bound.lower, 1 );
|
|
180
|
+
AssertNS.deepStrictEqual( bound.upper, 5 );
|
|
181
|
+
AssertNS.deepStrictEqual( bound.higher, 5 );
|
|
182
|
+
AssertNS.deepStrictEqual( bound.mode, namespaceExport.Bound.MODES.NORMAL );
|
|
183
|
+
AssertNS.deepStrictEqual( bound.size, 4 );
|
|
184
|
+
AssertNS.deepStrictEqual( bound.inNormal( 4 ), true );
|
|
185
|
+
AssertNS.deepStrictEqual( bound.inNormal( 5 ), false );
|
|
186
|
+
AssertNS.deepStrictEqual( bound.inInclusive( 5 ), true );
|
|
187
|
+
AssertNS.deepStrictEqual( bound.inInclusive( 0 ), false );
|
|
188
|
+
AssertNS.deepStrictEqual( bound.inExclusive( 2 ), true );
|
|
189
|
+
AssertNS.deepStrictEqual( bound.inExclusive( 1 ), false );
|
|
190
|
+
AssertNS.deepStrictEqual( bound.isIn( 1 ), true );
|
|
191
|
+
AssertNS.deepStrictEqual( bound.isIn( 5 ), false );
|
|
192
|
+
AssertNS.deepStrictEqual( bound.min( 0 ), 0 );
|
|
193
|
+
AssertNS.deepStrictEqual( bound.min( 6 ), 5 );
|
|
194
|
+
AssertNS.deepStrictEqual( bound.max( 0 ), 1 );
|
|
195
|
+
AssertNS.deepStrictEqual( bound.max( 6 ), 6 );
|
|
196
|
+
AssertNS.deepStrictEqual( bound.clamp( 0 ), 1 );
|
|
197
|
+
AssertNS.deepStrictEqual( bound.clamp( 6 ), 5 );
|
|
198
|
+
AssertNS.deepStrictEqual( bound.clamp( 3 ), 3 );
|
|
199
|
+
AssertNS.deepStrictEqual( bound.toString(), '[1,5)' );
|
|
200
|
+
var bound2 = new namespaceExport.Bound( -1, 1, defaultExport.Bound.MODES.INCLUSIVE );
|
|
201
|
+
AssertNS.deepStrictEqual( bound2.mode, defaultExport.Bound.MODES.INCLUSIVE );
|
|
202
|
+
AssertNS.deepStrictEqual( bound2.size, 2 );
|
|
203
|
+
AssertNS.deepStrictEqual( bound2.isIn( -1 ), true );
|
|
204
|
+
AssertNS.deepStrictEqual( bound2.isIn( 5 ), false );
|
|
205
|
+
AssertNS.deepStrictEqual( bound2.toString(), '[-1,1]' );
|
|
206
|
+
var bound3 = new defaultExport.Bound( 3, 20, namespaceExport.Bound.MODES.EXCLUSIVE );
|
|
207
|
+
AssertNS.deepStrictEqual( bound3.mode, namespaceExport.Bound.MODES.EXCLUSIVE );
|
|
208
|
+
AssertNS.deepStrictEqual( bound3.size, 17 );
|
|
209
|
+
AssertNS.deepStrictEqual( bound3.isIn( 19 ), true );
|
|
210
|
+
AssertNS.deepStrictEqual( bound3.isIn( 20 ), false );
|
|
211
|
+
AssertNS.deepStrictEqual( bound3.toString(), '(3,20)' );
|
|
212
|
+
AssertNS.deepStrictEqual( bound.overlap( bound2 ), 0b0110 );
|
|
213
|
+
AssertNS.deepStrictEqual( bound.overlap( bound3 ), 0b1001 );
|
|
214
|
+
AssertNS.deepStrictEqual( bound2.overlap( bound3 ), 0 );
|
|
215
|
+
AssertNS.deepStrictEqual( defaultExport.Bound.sortLowestFirst( bound, bound2 ) > 0, true );
|
|
216
|
+
AssertNS.deepStrictEqual( defaultExport.Bound.sortLowestFirst( bound, bound3 ) < 0, true );
|
|
217
|
+
AssertNS.deepStrictEqual( defaultExport.Bound.sortLowestFirst( bound, bound ) == 0, true );
|
|
218
|
+
var bound_list = defaultExport.BoundList();
|
|
219
|
+
AssertNS.deepStrictEqual( bound_list.bounds, 0 );
|
|
220
|
+
bound_list.mergeAdd( bound );
|
|
221
|
+
bound_list.mergeAdd( bound2 );
|
|
222
|
+
bound_list.mergeAdd( bound3 );
|
|
223
|
+
//console.error( '%o', bound_list );
|
|
224
|
+
AssertNS.deepStrictEqual( bound_list.bounds, 1 );
|
|
225
|
+
AssertNS.deepStrictEqual( bound_list.isIn( -1 ), true );
|
|
226
|
+
AssertNS.deepStrictEqual( bound_list.isIn( 21 ), false );
|
|
227
|
+
AssertNS.deepStrictEqual( bound_list.lowest, -1 );
|
|
228
|
+
AssertNS.deepStrictEqual( bound_list.highest, 20 );
|
|
229
|
+
var bound_list2 = new namespaceExport.BoundList();
|
|
230
|
+
bound_list2.mergeAdd( bound2 );
|
|
231
|
+
bound_list2.mergeAdd( bound3 );
|
|
232
|
+
AssertNS.deepStrictEqual( bound_list2.bounds, 2 );
|
|
233
|
+
AssertNS.deepStrictEqual( bound_list2.isIn( -1 ), true );
|
|
234
|
+
AssertNS.deepStrictEqual( bound_list2.isIn( 20 ), false );
|
|
235
|
+
AssertNS.deepStrictEqual( bound_list2.isIn( 2 ), false );
|
|
236
|
+
AssertNS.deepStrictEqual( bound_list2.lowest, -1 );
|
|
237
|
+
AssertNS.deepStrictEqual( bound_list2.highest, 20 );
|
|
238
|
+
var bound_list3 = namespaceExport.BoundList();
|
|
239
|
+
bound_list3.boundsArray.push( bound, bound2, bound3 );
|
|
240
|
+
bound_list3.reduce();
|
|
241
|
+
AssertNS.deepStrictEqual( bound_list3.bounds, 1 );
|
|
242
|
+
AssertNS.deepStrictEqual( bound_list3.isIn( -1 ), true );
|
|
243
|
+
AssertNS.deepStrictEqual( bound_list3.isIn( 21 ), false );
|
|
244
|
+
AssertNS.deepStrictEqual( bound_list3.lowest, -1 );
|
|
245
|
+
AssertNS.deepStrictEqual( bound_list3.highest, 20 );
|
|
246
|
+
} );
|
|
247
|
+
|
|
248
|
+
// cno-math.test.js EOF
|
|
249
|
+
|
package/src/cno-noop.js
CHANGED
|
@@ -35,7 +35,7 @@ Documentation License: [;
|
|
71
75
|
|
|
72
|
-
export { NAMESPACE as default, returnTrue, returnFalse, returnNull, noop as returnUndefined };
|
|
76
|
+
export { NAMESPACE as default, returnTrue, returnFalse, returnNull, noop as returnUndefined, identity as returnReceived };
|
|
73
77
|
|
|
74
78
|
// cno-noop.js EOF
|
|
75
79
|
|