|
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 INT32_MAX = require( '@stdlib/constants-int32-max' ); |
25 |
| -var isPositiveInteger = require( '@stdlib/math-base-assert-is-positive-integer' ); |
26 |
| -var isInt32Array = require( '@stdlib/assert-is-int32array' ); |
27 |
| -var minstd = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
28 | 25 |
|
29 | 26 |
|
30 | 27 | // TESTS //
|
31 | 28 |
|
32 |
| -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
33 | 30 | t.ok( true, __filename );
|
34 |
| - t.strictEqual( typeof minstd, 'function', 'main export is a function' ); |
35 |
| - t.end(); |
36 |
| -}); |
37 |
| - |
38 |
| -tape( 'attached to the main export is a method to generate normalized pseudorandom numbers', function test( t ) { |
39 |
| - t.equal( typeof minstd.normalized, 'function', 'has method' ); |
40 |
| - t.end(); |
41 |
| -}); |
42 |
| - |
43 |
| -tape( 'attached to the main export is a method to generate linear congruential pseudorandom number generator', function test( t ) { |
44 |
| - t.equal( typeof minstd.factory, 'function', 'has method' ); |
45 |
| - t.end(); |
46 |
| -}); |
47 |
| - |
48 |
| -tape( 'attached to the main export is a method to serialize a pseudorandom number generator as JSON', function test( t ) { |
49 |
| - t.equal( typeof minstd.toJSON, 'function', 'has method' ); |
50 |
| - t.end(); |
51 |
| -}); |
52 |
| - |
53 |
| -tape( 'attached to the main export is the generator name', function test( t ) { |
54 |
| - t.equal( minstd.NAME, 'minstd', 'has property' ); |
55 |
| - t.end(); |
56 |
| -}); |
57 |
| - |
58 |
| -tape( 'attached to the main export is the minimum possible generated number', function test( t ) { |
59 |
| - t.equal( minstd.MIN, 1, 'has property' ); |
60 |
| - t.end(); |
61 |
| -}); |
62 |
| - |
63 |
| -tape( 'attached to the main export is the maximum possible generated number', function test( t ) { |
64 |
| - t.equal( minstd.MAX, INT32_MAX-1, 'has property' ); |
65 |
| - t.end(); |
66 |
| -}); |
67 |
| - |
68 |
| -tape( 'attached to the main export is the generator seed', function test( t ) { |
69 |
| - t.equal( isInt32Array( minstd.seed ), true, 'has property' ); |
70 |
| - t.end(); |
71 |
| -}); |
72 |
| - |
73 |
| -tape( 'attached to the main export is the generator seed length', function test( t ) { |
74 |
| - t.equal( typeof minstd.seedLength, 'number', 'has property' ); |
75 |
| - t.end(); |
76 |
| -}); |
77 |
| - |
78 |
| -tape( 'attached to the main export is the generator state', function test( t ) { |
79 |
| - t.equal( isInt32Array( minstd.state ), true, 'has property' ); |
80 |
| - t.end(); |
81 |
| -}); |
82 |
| - |
83 |
| -tape( 'attached to the main export is the generator state length', function test( t ) { |
84 |
| - t.equal( typeof minstd.stateLength, 'number', 'has property' ); |
85 |
| - t.end(); |
86 |
| -}); |
87 |
| - |
88 |
| -tape( 'attached to the main export is the generator state size', function test( t ) { |
89 |
| - t.equal( typeof minstd.byteLength, 'number', 'has property' ); |
90 |
| - t.end(); |
91 |
| -}); |
92 |
| - |
93 |
| -tape( 'the function returns pseudorandom integers strictly between 0 and 2^31-1 (inclusive)', function test( t ) { |
94 |
| - var v; |
95 |
| - var i; |
96 |
| - for ( i = 0; i < 1e3; i++ ) { |
97 |
| - v = minstd(); |
98 |
| - t.equal( typeof v, 'number', 'returns a number' ); |
99 |
| - t.equal( isPositiveInteger( v ), true, 'returns a positive integer' ); |
100 |
| - t.equal( v >= 1 && v <= INT32_MAX-1, true, 'returns an integer between 1 and 2^31-1 (inclusive)' ); |
101 |
| - } |
102 |
| - t.end(); |
103 |
| -}); |
104 |
| - |
105 |
| -tape( 'the `normalized` method returns pseudorandom numbers strictly between 0 (inclusive) and 1 (exclusive)', function test( t ) { |
106 |
| - var v; |
107 |
| - var i; |
108 |
| - for ( i = 0; i < 1e3; i++ ) { |
109 |
| - v = minstd.normalized(); |
110 |
| - t.equal( typeof v, 'number', 'returns a number' ); |
111 |
| - t.equal( v >= 0.0 && v < 1.0, true, 'returns a number between 0 (inclusive) and 1 (exclusive)' ); |
112 |
| - } |
113 |
| - t.end(); |
114 |
| -}); |
115 |
| - |
116 |
| -tape( 'attached to the `normalized` method is the generator name', function test( t ) { |
117 |
| - t.equal( minstd.normalized.NAME, 'minstd', 'has property' ); |
118 |
| - t.end(); |
119 |
| -}); |
120 |
| - |
121 |
| -tape( 'attached to the `normalized` method is the minimum possible generated number', function test( t ) { |
122 |
| - t.equal( minstd.normalized.MIN, 0.0, 'has property' ); |
123 |
| - t.end(); |
124 |
| -}); |
125 |
| - |
126 |
| -tape( 'attached to the `normalized` method is the maximum possible generated number', function test( t ) { |
127 |
| - t.equal( minstd.normalized.MAX, (INT32_MAX-2.0)/(INT32_MAX-1.0), 'has property' ); |
128 |
| - t.end(); |
129 |
| -}); |
130 |
| - |
131 |
| -tape( 'attached to the `normalized` method is the generator seed', function test( t ) { |
132 |
| - t.equal( isInt32Array( minstd.normalized.seed ), true, 'has property' ); |
133 |
| - t.end(); |
134 |
| -}); |
135 |
| - |
136 |
| -tape( 'attached to the `normalized` method is the generator seed length', function test( t ) { |
137 |
| - t.equal( typeof minstd.normalized.seedLength, 'number', 'has property' ); |
138 |
| - t.end(); |
139 |
| -}); |
140 |
| - |
141 |
| -tape( 'attached to the `normalized` method is the generator state', function test( t ) { |
142 |
| - t.equal( isInt32Array( minstd.normalized.state ), true, 'has property' ); |
143 |
| - t.end(); |
144 |
| -}); |
145 |
| - |
146 |
| -tape( 'attached to the `normalized` method is the generator state length', function test( t ) { |
147 |
| - t.equal( typeof minstd.normalized.stateLength, 'number', 'has property' ); |
148 |
| - t.end(); |
149 |
| -}); |
150 |
| - |
151 |
| -tape( 'attached to the `normalized` method is the generator state size', function test( t ) { |
152 |
| - t.equal( typeof minstd.normalized.byteLength, 'number', 'has property' ); |
153 |
| - t.end(); |
154 |
| -}); |
155 |
| - |
156 |
| -tape( 'attached to the `normalized` method is a method to serialize a pseudorandom number generator as JSON', function test( t ) { |
157 |
| - t.equal( typeof minstd.normalized.toJSON, 'function', 'has method' ); |
158 |
| - t.end(); |
159 |
| -}); |
160 |
| - |
161 |
| -tape( 'the generator supports setting the generator state', function test( t ) { |
162 |
| - var state; |
163 |
| - var arr; |
164 |
| - var i; |
165 |
| - |
166 |
| - // Move to a future state... |
167 |
| - for ( i = 0; i < 100; i++ ) { |
168 |
| - minstd(); |
169 |
| - } |
170 |
| - // Capture the current state: |
171 |
| - state = minstd.state; |
172 |
| - |
173 |
| - // Move to a future state... |
174 |
| - arr = []; |
175 |
| - for ( i = 0; i < 100; i++ ) { |
176 |
| - arr.push( minstd() ); |
177 |
| - } |
178 |
| - // Set the state: |
179 |
| - minstd.state = state; |
180 |
| - |
181 |
| - // Replay previously generated values... |
182 |
| - for ( i = 0; i < 100; i++ ) { |
183 |
| - t.equal( minstd(), arr[ i ], 'returns expected value. i: '+i+'.' ); |
184 |
| - } |
185 |
| - t.end(); |
186 |
| -}); |
187 |
| - |
188 |
| -tape( 'the generator supports setting the generator state (normalized)', function test( t ) { |
189 |
| - var state; |
190 |
| - var arr; |
191 |
| - var i; |
192 |
| - |
193 |
| - // Move to a future state... |
194 |
| - for ( i = 0; i < 100; i++ ) { |
195 |
| - minstd.normalized(); |
196 |
| - } |
197 |
| - // Capture the current state: |
198 |
| - state = minstd.state; |
199 |
| - |
200 |
| - // Move to a future state... |
201 |
| - arr = []; |
202 |
| - for ( i = 0; i < 100; i++ ) { |
203 |
| - arr.push( minstd.normalized() ); |
204 |
| - } |
205 |
| - // Set the state: |
206 |
| - minstd.state = state; |
207 |
| - |
208 |
| - // Replay previously generated values... |
209 |
| - for ( i = 0; i < 100; i++ ) { |
210 |
| - t.equal( minstd.normalized(), arr[ i ], 'returns expected value. i: '+i+'.' ); |
211 |
| - } |
212 |
| - t.end(); |
213 |
| -}); |
214 |
| - |
215 |
| -tape( 'the generator supports setting the generator state (normalized)', function test( t ) { |
216 |
| - var state; |
217 |
| - var arr; |
218 |
| - var i; |
219 |
| - |
220 |
| - // Move to a future state... |
221 |
| - for ( i = 0; i < 100; i++ ) { |
222 |
| - minstd.normalized(); |
223 |
| - } |
224 |
| - // Capture the current state: |
225 |
| - state = minstd.normalized.state; |
226 |
| - |
227 |
| - // Move to a future state... |
228 |
| - arr = []; |
229 |
| - for ( i = 0; i < 100; i++ ) { |
230 |
| - arr.push( minstd.normalized() ); |
231 |
| - } |
232 |
| - // Set the state: |
233 |
| - minstd.normalized.state = state; |
234 |
| - |
235 |
| - // Replay previously generated values... |
236 |
| - for ( i = 0; i < 100; i++ ) { |
237 |
| - t.equal( minstd.normalized(), arr[ i ], 'returns expected value. i: '+i+'.' ); |
238 |
| - } |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
239 | 32 | t.end();
|
240 | 33 | });
|
0 commit comments