|
1 | 1 | /**
|
2 | 2 | * @license Apache-2.0
|
3 | 3 | *
|
4 |
| -* Copyright (c) 2018 The Stdlib Authors. |
| 4 | +* Copyright (c) 2023 The Stdlib Authors. |
5 | 5 | *
|
6 | 6 | * Licensed under the Apache License, Version 2.0 (the "License");
|
7 | 7 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | // MODULES //
|
22 | 22 |
|
23 | 23 | var tape = require( 'tape' );
|
24 |
| -var Int8Array = require( '@stdlib/array-int8' ); |
25 |
| -var Uint8Array = require( '@stdlib/array-uint8' ); |
26 |
| -var Uint8ClampedArray = require( '@stdlib/array-uint8c' ); |
27 |
| -var Int16Array = require( '@stdlib/array-int16' ); |
28 |
| -var Uint16Array = require( '@stdlib/array-uint16' ); |
29 |
| -var Int32Array = require( '@stdlib/array-int32' ); |
30 |
| -var Uint32Array = require( '@stdlib/array-uint32' ); |
31 |
| -var Float32Array = require( '@stdlib/array-float32' ); |
32 |
| -var Float64Array = require( '@stdlib/array-float64' ); |
33 |
| -var array2buffer = require( '@stdlib/buffer-from-array' ); |
34 |
| -var isUnityProbabilityArray = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
35 | 25 |
|
36 | 26 |
|
37 | 27 | // TESTS //
|
38 | 28 |
|
39 |
| -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
40 | 30 | t.ok( true, __filename );
|
41 |
| - t.strictEqual( typeof isUnityProbabilityArray, 'function', 'main export is a function' ); |
42 |
| - t.end(); |
43 |
| -}); |
44 |
| - |
45 |
| -tape( 'the function returns `true` if provided an array of probabilities that sum to one', function test( t ) { |
46 |
| - var values; |
47 |
| - var i; |
48 |
| - |
49 |
| - values = [ |
50 |
| - new Int8Array( [ 0, 0, 1 ] ), |
51 |
| - new Uint8Array( [ 1, 0, 0 ] ), |
52 |
| - new Uint8ClampedArray( [ 0, 1 ] ), |
53 |
| - new Int16Array( [ 0, 0, 1, 0 ] ), |
54 |
| - new Uint16Array( [ 1 ] ), |
55 |
| - new Int32Array( [ 1, 0, 0 ] ), |
56 |
| - new Uint32Array( [ 0, 1, 0 ] ), |
57 |
| - new Float32Array( [ 0.0, 0.5, 0.5 ] ), |
58 |
| - new Float64Array( [ 0.25, 0.25, 0.5 ] ), |
59 |
| - [ 0.5, 0.25, 0.25 ] |
60 |
| - ]; |
61 |
| - |
62 |
| - for ( i = 0; i < values.length; i++ ) { |
63 |
| - t.strictEqual( isUnityProbabilityArray( values[i] ), true, 'returns true when provided '+values[i] ); |
64 |
| - } |
65 |
| - t.end(); |
66 |
| -}); |
67 |
| - |
68 |
| -tape( 'the function allows a difference in sum within floating-point epsilon', function test( t ) { |
69 |
| - var bool = isUnityProbabilityArray( [ 0.1, 0.2, 0.1, 0.1, 0.2, 0.2, 0.1 ] ); |
70 |
| - t.strictEqual( bool, true, 'returns true' ); |
71 |
| - t.end(); |
72 |
| -}); |
73 |
| - |
74 |
| -tape( 'the function returns `false` if not provided an array of probabilities that sum to one', function test( t ) { |
75 |
| - var values; |
76 |
| - var i; |
77 |
| - |
78 |
| - values = [ |
79 |
| - '10', |
80 |
| - '01', |
81 |
| - '0.5', |
82 |
| - '5', |
83 |
| - 5, |
84 |
| - NaN, |
85 |
| - null, |
86 |
| - void 0, |
87 |
| - true, |
88 |
| - [], |
89 |
| - [ 5, null ], |
90 |
| - [ 5, '5' ], |
91 |
| - [ 1.0, 3.14 ], |
92 |
| - [ -1.0, 1.0, 1.0 ], |
93 |
| - [ 0.25, 0.33, 0.5 ], |
94 |
| - new Float64Array( [ 0.25, 0.33, 0.5 ] ), |
95 |
| - new Float64Array( [ 0.25, 1.33, 0.5 ] ), |
96 |
| - new Float64Array( [ 0.25, -0.33, 0.5 ] ), |
97 |
| - {}, |
98 |
| - function noop() {}, |
99 |
| - array2buffer( [ 1, 1, 0 ] ) |
100 |
| - ]; |
101 |
| - |
102 |
| - for ( i = 0; i < values.length; i++ ) { |
103 |
| - t.strictEqual( isUnityProbabilityArray( values[i] ), false, 'returns false when provided '+values[i] ); |
104 |
| - } |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
105 | 32 | t.end();
|
106 | 33 | });
|
0 commit comments