@cloudglides/nox 1.1.4 → 1.1.6

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.
@@ -0,0 +1,49 @@
1
+ import { rng, deterministic, normal, exponential, uniform, shuffle, pick, sample } from '../src/index.js';
2
+
3
+ const test = (name, fn) => {
4
+ try {
5
+ fn();
6
+ console.log(`✗ ${name} - should have thrown`);
7
+ } catch (e) {
8
+ console.log(`✓ ${name}`);
9
+ }
10
+ };
11
+
12
+ console.log('=== ERROR HANDLING ===\n');
13
+
14
+ const r = rng();
15
+
16
+ // RNG methods
17
+ test('int() with non-number min', () => r.int('a', 100));
18
+ test('int() with non-number max', () => r.int(1, 'b'));
19
+ test('int() with non-integer min', () => r.int(1.5, 100));
20
+ test('bool() with invalid probability', () => r.bool(1.5));
21
+ test('bool() with negative probability', () => r.bool(-0.5));
22
+ test('range() with non-number min', () => r.range('a', 10, 1));
23
+ test('range() with negative step', () => r.range(1, 10, -1));
24
+ test('choice() with empty array', () => r.choice([]));
25
+ test('choice() with non-array', () => r.choice('notarray'));
26
+
27
+ // Batch operations
28
+ test('floats() with negative count', () => r.floats(-5));
29
+ test('ints() with non-integer count', () => r.ints(5.5, 100));
30
+ test('bools() with string count', () => r.bools('5'));
31
+ test('batch() with non-function', () => r.batch(5, 'notfn'));
32
+
33
+ // Distributions
34
+ test('normal() with invalid rng', () => normal({}, 0, 1));
35
+ test('exponential() with zero lambda', () => exponential(r, 0));
36
+ test('uniform() with min > max', () => uniform(r, 100, 10));
37
+
38
+ // Array operations
39
+ test('shuffle() with non-array', () => shuffle({}, r));
40
+ test('shuffle() with invalid rng', () => shuffle([1,2,3], {}));
41
+ test('pick() with empty array', () => pick([], r));
42
+ test('sample() with count > length', () => sample([1,2], 5, r));
43
+ test('sample() with zero count', () => sample([1,2], 0, r));
44
+
45
+ // Deterministic
46
+ test('deterministic() with no seed', () => deterministic());
47
+ test('deterministic() with null seed', () => deterministic(null));
48
+
49
+ console.log('\n✅ All error cases handled correctly\n');