Major rework of make.number

This commit is contained in:
pyoor 2018-08-02 14:21:27 -04:00
parent 21a6025481
commit 195411fe8d

View file

@ -6,8 +6,94 @@ const make = require('../make')
const random = require('../random') const random = require('../random')
class number extends make { class number extends make {
static bool () { /**
return random.bool() * generate a number that exceeds the supplied boundary by +- 3
* @param start
* @param end
* @private
*/
static _exceed (start, end) {
const value = random.item([start, end])
const offset = random.range(-3, 3)
return value + offset
}
/**
* Generate a int8 [-128, 127]
* @param bypass {boolean} - Determines if the range should be exceeded
* @returns {number}
*/
static int8 (bypass = false) {
if (bypass || random.chance(50)) {
return number._exceed(-128, 127)
}
return random.range(-128, 127)
}
/**
* Generate a uint8 [0, 255]
* @param bypass {boolean} - Determines if the range should be exceeded
* @returns {number}
*/
static uint8 (bypass = false) {
if (bypass || random.chance(50)) {
return number._exceed(0, 255)
}
return random.range(0, 255)
}
/**
* Generate a int16 [-32768, 32767]
* @param bypass {boolean} - Determines if the range should be exceeded
* @returns {number}
*/
static int16 (bypass = false) {
if (bypass || random.chance(50)) {
return number._exceed(-32768, 32767)
}
return random.range(-32768, 32767)
}
/**
* Generate a uint16 [0, 65535]
* @param bypass {boolean} - Determines if the range should be exceeded
* @returns {*}
*/
static uint16 (bypass = false) {
if (bypass || random.chance(50)) {
return number._exceed(0, 65535)
}
return random.range(-0, 65535)
}
/**
* Generate a int32 [-2147483648, 2147483647]
* @param bypass {boolean} - Determines if the range should be exceeded
* @returns {number}
*/
static int32 (bypass = false) {
if (bypass || random.chance(50)) {
return number._exceed(-2147483648, 2147483647)
}
return random.range(-2147483648, 2147483647)
}
/**
* Generate a uint32 [0, 4294967295]
* @param bypass {boolean} - Determines if the range should be exceeded
* @returns {number}
*/
static uint32 (bypass = false) {
if (bypass || random.chance(50)) {
return number._exceed(0, 4294967295)
}
return random.range(0, 4294967295)
} }
static float () { static float () {
@ -74,6 +160,7 @@ class number extends make {
static any () { static any () {
let value = random.choose([ let value = random.choose([
[1, number.interesting],
[1, number.float], [1, number.float],
[1, number.unsigned], [1, number.unsigned],
[1, [number.range, number.tiny]] [1, [number.range, number.tiny]]