Skip to content

Commit

Permalink
(prng) test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Mar 10, 2019
1 parent b00cebb commit eb6b972
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
10 changes: 1 addition & 9 deletions prng.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const DefaultPRNG = Xoroshiro128plus
* @param {number} seed A positive 32bit integer. Do not use negative numbers.
* @return {PRNG}
*/
export const create = seed => new DefaultPRNG(Math.floor(seed < 1 ? seed * binary.BITS32 : seed))
export const create = seed => new DefaultPRNG(seed)

/**
* Generates a single random bool.
Expand Down Expand Up @@ -82,14 +82,6 @@ export const int31 = (gen, min, max) => {
return math.floor((gen.next() * (_max + 1 - _min)) + _min)
}

/**
* Generates a random real on [0, 1) with 32 bit resolution.
*
* @param {PRNG} gen A random number generator.
* @return {Number} A random real number on [0, 1).
*/
export const real32 = gen => gen.next()

/**
* Generates a random real on [0, 1) with 53 bit resolution.
*
Expand Down
5 changes: 4 additions & 1 deletion prng.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,15 @@ const runGenTest = (tc, gen) => {

t.group('uint53 - generates integer exceeding 32 bits', () => {
let largest = 0
let smallest = 0
let smallest = 10000
let i
let newNum
for (i = 0; i < genTestData; i++) {
newNum = prng.uint53(gen, 0, Number.MAX_SAFE_INTEGER)
if (newNum > largest) {
largest = newNum
}
/* istanbul ignore if */
if (newNum < smallest) {
smallest = newNum
}
Expand Down Expand Up @@ -175,6 +176,7 @@ export const testGeneratorXoroshiro128plus = tc => runGenTest(tc, new Xoroshiro1
export const testGeneratorXorshift32 = tc => runGenTest(tc, new Xorshift32(tc.seed))
export const testGeneratorMt19937 = tc => runGenTest(tc, new Mt19937(tc.seed))

/* istanbul ignore next */
/**
* @param {prng.PRNG} gen
* @param {t.TestCase} tc
Expand All @@ -195,6 +197,7 @@ const printDistribution = (gen, tc) => {
t.printCanvas(canvas, DIAMETER)
}

/* istanbul ignore next */
export const testNumberDistributions = tc => {
t.skip(!isBrowser)
t.group('Xoroshiro128plus', () => printDistribution(new Xoroshiro128plus(tc.seed), tc))
Expand Down

0 comments on commit eb6b972

Please sign in to comment.