|
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 uniform = require( '@stdlib/random-base-uniform' ).factory; |
25 | | -var round = require( '@stdlib/math-base-special-round' ); |
26 | | -var isNonNegativeInteger = require( '@stdlib/math-base-assert-is-nonnegative-integer' ); |
27 | | -var isUint32Array = require( '@stdlib/assert-is-uint32array' ); |
28 | | -var binomial = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
29 | 25 |
|
30 | 26 |
|
31 | 27 | // TESTS // |
32 | 28 |
|
33 | | -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
34 | 30 | t.ok( true, __filename ); |
35 | | - t.strictEqual( typeof binomial, 'function', 'main export is a function' ); |
36 | | - t.end(); |
37 | | -}); |
38 | | - |
39 | | -tape( 'attached to the main export is a method to generate pseudorandom number generators', function test( t ) { |
40 | | - t.equal( typeof binomial.factory, 'function', 'has method' ); |
41 | | - t.end(); |
42 | | -}); |
43 | | - |
44 | | -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { |
45 | | - t.equal( typeof binomial.toJSON, 'function', 'has method' ); |
46 | | - t.end(); |
47 | | -}); |
48 | | - |
49 | | -tape( 'attached to the main export is the generator name', function test( t ) { |
50 | | - t.equal( binomial.NAME, 'binomial', 'has property' ); |
51 | | - t.end(); |
52 | | -}); |
53 | | - |
54 | | -tape( 'attached to the main export is the underlying PRNG', function test( t ) { |
55 | | - t.equal( typeof binomial.PRNG, 'function', 'has property' ); |
56 | | - t.end(); |
57 | | -}); |
58 | | - |
59 | | -tape( 'attached to the main export is the generator seed', function test( t ) { |
60 | | - t.equal( isUint32Array( binomial.seed ), true, 'has property' ); |
61 | | - t.end(); |
62 | | -}); |
63 | | - |
64 | | -tape( 'attached to the main export is the generator seed length', function test( t ) { |
65 | | - t.equal( typeof binomial.seedLength, 'number', 'has property' ); |
66 | | - t.end(); |
67 | | -}); |
68 | | - |
69 | | -tape( 'attached to the main export is the generator state', function test( t ) { |
70 | | - t.equal( isUint32Array( binomial.state ), true, 'has property' ); |
71 | | - t.end(); |
72 | | -}); |
73 | | - |
74 | | -tape( 'attached to the main export is the generator state length', function test( t ) { |
75 | | - t.equal( typeof binomial.stateLength, 'number', 'has property' ); |
76 | | - t.end(); |
77 | | -}); |
78 | | - |
79 | | -tape( 'attached to the main export is the generator state size', function test( t ) { |
80 | | - t.equal( typeof binomial.byteLength, 'number', 'has property' ); |
81 | | - t.end(); |
82 | | -}); |
83 | | - |
84 | | -tape( 'the function returns pseudorandom numbers', function test( t ) { |
85 | | - var rand; |
86 | | - var n; |
87 | | - var p; |
88 | | - var r; |
89 | | - var i; |
90 | | - |
91 | | - rand = uniform({ |
92 | | - 'seed': 3893 |
93 | | - }); |
94 | | - for ( i = 0; i < 1e2; i++ ) { |
95 | | - n = round( rand( 1.0, 100 ) ); |
96 | | - p = rand( 0.0, 1.0 ); |
97 | | - r = binomial( n, p ); |
98 | | - t.strictEqual( isNonNegativeInteger( r ), true, 'Binomial('+n+','+p+') => '+r ); |
99 | | - } |
100 | | - t.end(); |
101 | | -}); |
102 | | - |
103 | | -tape( 'the function supports setting the generator state', function test( t ) { |
104 | | - var state; |
105 | | - var arr; |
106 | | - var i; |
107 | | - |
108 | | - // Move to a future state... |
109 | | - for ( i = 0; i < 100; i++ ) { |
110 | | - binomial( 20, 0.67 ); |
111 | | - } |
112 | | - // Capture the current state: |
113 | | - state = binomial.state; |
114 | | - |
115 | | - // Move to a future state... |
116 | | - arr = []; |
117 | | - for ( i = 0; i < 100; i++ ) { |
118 | | - arr.push( binomial( 20, 0.67 ) ); |
119 | | - } |
120 | | - // Set the state: |
121 | | - binomial.state = state; |
122 | | - |
123 | | - // Replay previously generated values... |
124 | | - for ( i = 0; i < 100; i++ ) { |
125 | | - t.equal( binomial( 20, 0.67 ), arr[ i ], 'returns expected value. i: '+i+'.' ); |
126 | | - } |
127 | | - t.end(); |
128 | | -}); |
129 | | - |
130 | | -tape( 'the function supports setting the generator state', function test( t ) { |
131 | | - var state; |
132 | | - var arr; |
133 | | - var i; |
134 | | - |
135 | | - // Move to a future state... |
136 | | - for ( i = 0; i < 100; i++ ) { |
137 | | - binomial( 8, 0.39 ); |
138 | | - } |
139 | | - // Capture the current state: |
140 | | - state = binomial.state; |
141 | | - |
142 | | - // Move to a future state... |
143 | | - arr = []; |
144 | | - for ( i = 0; i < 100; i++ ) { |
145 | | - arr.push( binomial( 8, 0.39 ) ); |
146 | | - } |
147 | | - // Set the state: |
148 | | - binomial.state = state; |
149 | | - |
150 | | - // Replay previously generated values... |
151 | | - for ( i = 0; i < 100; i++ ) { |
152 | | - t.equal( binomial( 8, 0.39 ), arr[ i ], 'returns expected value. i: '+i+'.' ); |
153 | | - } |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
154 | 32 | t.end(); |
155 | 33 | }); |
0 commit comments