-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
45 lines (39 loc) · 1.81 KB
/
test.js
File metadata and controls
45 lines (39 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
const RandomCrap = require('./index.js');
const rc = new RandomCrap();
console.log('Test Bias');
let sum = 0;
const iterations = 10000;
const ideal = ((sum + iterations)/2)
console.log('control: ' + ideal);
for (let j = 0; j < iterations; j ++) {
sum += rc.simpleRandomInt(0, iterations);
}
const actual = sum/iterations;
console.log('actual: ' + actual);
console.log('Assert Bias within 5% of true random|true: ' + (Math.abs(ideal - actual) <= (ideal * 0.05)));
console.log('Test simpleRandomFloat');
const float = rc.simpleRandomFloat(5,7)
console.log('float: ' + float);
console.log('Assert Number is returned|true: ' + (float < float + 10));
console.log('Test randomFrom');
const testSet = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
let randomArray = [];
for (let i = 0; i < 10; i++) {
randomArray.push(rc.randomFrom(testSet, 'testSet', true));
}
console.log(testSet);
console.log(randomArray);
// @TODO: Things to test.
// undefined in non looped set
// no duplicates in named set that is not looped
// in limited loop set [ 1, 2, 3 ] only elements from set and no undefined
// are returned.
console.log('Test simpleRandomAlpha');
console.log('Assert setting allCaps and noCaps to true gives no result: true|' + (rc.simpleRandomAlpha({allCaps: true, noCaps: true}) === ''));;
console.log('Assert noCaps option works: true|' + (rc.simpleRandomAlpha({_set: ['A'], noCaps: true}) === 'a'));
console.log('Assert noCaps option works: false|' + (rc.simpleRandomAlpha({_set: ['a'], noCaps: true}) === 'A'));
console.log('Assert allCaps option works: true|' + (rc.simpleRandomAlpha({_set: ['a'], allCaps: true}) === 'A'));
console.log('Assert allCaps option works: false|' + (rc.simpleRandomAlpha({_set: ['a'], allCaps: true}) === 'a'));
console.log('Test simpleRandomAlphaNum');
console.log(rc.simpleRandomAlphaNum({noOfDigets: 100}));