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