23
23
var tape = require ( 'tape' ) ;
24
24
var ENV = require ( '@stdlib/process/env' ) ;
25
25
var kstest = require ( '@stdlib/stats/kstest' ) ;
26
- var round = require ( '@stdlib/math/base/special/round ' ) ;
26
+ var now = require ( '@stdlib/time/now ' ) ;
27
27
var isnan = require ( '@stdlib/math/base/assert/is-nan' ) ;
28
+ var isUint32Array = require ( '@stdlib/assert/is-uint32array' ) ;
28
29
var factory = require ( './../lib/factory.js' ) ;
29
30
30
31
@@ -73,7 +74,7 @@ tape( 'the function returns a seeded pseudorandom number generator', function te
73
74
var r2 ;
74
75
var i ;
75
76
76
- seed = round ( Date . now ( ) / 1000 ) ;
77
+ seed = now ( ) ;
77
78
78
79
chisquare1 = factory ( 35 , {
79
80
'seed' : seed
@@ -113,6 +114,18 @@ tape( 'attached to the returned function is the generator seed', function test(
113
114
t . end ( ) ;
114
115
} ) ;
115
116
117
+ tape ( 'attached to the returned function is the generator state' , function test ( t ) {
118
+ var chisquare = factory ( ) ;
119
+ t . equal ( isUint32Array ( chisquare . STATE ) , true , 'has `STATE` property' ) ;
120
+ t . end ( ) ;
121
+ } ) ;
122
+
123
+ tape ( 'attached to the returned function is the generator state size' , function test ( t ) {
124
+ var chisquare = factory ( ) ;
125
+ t . equal ( typeof chisquare . STATE_SIZE , 'number' , 'has `STATE_SIZE` property' ) ;
126
+ t . end ( ) ;
127
+ } ) ;
128
+
116
129
tape ( 'the function throws an error if degrees of freedom `k` is not a positive number (no options)' , function test ( t ) {
117
130
var values ;
118
131
var i ;
@@ -123,7 +136,8 @@ tape( 'the function throws an error if degrees of freedom `k` is not a positive
123
136
'5' ,
124
137
null ,
125
138
true ,
126
- undefined ,
139
+ false ,
140
+ void 0 ,
127
141
NaN ,
128
142
[ ] ,
129
143
function noop ( ) { }
@@ -151,7 +165,8 @@ tape( 'the function throws an error if degrees of freedom `k` is not a positive
151
165
'5' ,
152
166
null ,
153
167
true ,
154
- undefined ,
168
+ false ,
169
+ void 0 ,
155
170
NaN ,
156
171
[ ] ,
157
172
{ } ,
@@ -178,7 +193,8 @@ tape( 'the function throws an error if provided an options argument which is no
178
193
'abc' ,
179
194
null ,
180
195
true ,
181
- undefined ,
196
+ false ,
197
+ void 0 ,
182
198
NaN ,
183
199
[ ] ,
184
200
function noop ( ) { }
@@ -205,7 +221,8 @@ tape( 'the function throws an error if provided an options argument which is not
205
221
5 ,
206
222
null ,
207
223
true ,
208
- undefined ,
224
+ false ,
225
+ void 0 ,
209
226
NaN ,
210
227
[ ] ,
211
228
function noop ( ) { }
@@ -320,3 +337,33 @@ tape( 'the function returns a PRNG for generating random numbers from a chi-squa
320
337
t . end ( ) ;
321
338
}
322
339
} ) ;
340
+
341
+ tape ( 'the returned function supports setting the generator state' , function test ( t ) {
342
+ var chisquare ;
343
+ var state ;
344
+ var arr ;
345
+ var i ;
346
+
347
+ chisquare = factory ( 4 ) ;
348
+
349
+ // Move to a future state...
350
+ for ( i = 0 ; i < 100 ; i ++ ) {
351
+ chisquare ( ) ;
352
+ }
353
+ // Capture the current state:
354
+ state = chisquare . STATE ;
355
+
356
+ // Move to a future state...
357
+ arr = [ ] ;
358
+ for ( i = 0 ; i < 100 ; i ++ ) {
359
+ arr . push ( chisquare ( ) ) ;
360
+ }
361
+ // Set the state:
362
+ chisquare . STATE = state ;
363
+
364
+ // Replay previously generated values...
365
+ for ( i = 0 ; i < 100 ; i ++ ) {
366
+ t . equal ( chisquare ( ) , arr [ i ] , 'returns expected value. i: ' + i + '.' ) ;
367
+ }
368
+ t . end ( ) ;
369
+ } ) ;
0 commit comments