Add additional strategies to make._exceed

This commit is contained in:
pyoor 2018-08-06 10:22:21 -04:00
parent 80f16a4aaf
commit b47a281403

View file

@ -7,15 +7,23 @@ const random = require('../random')
class number extends make { class number extends make {
/** /**
* generate a number that exceeds the supplied boundary by +- 3 * Generate a number that is more likely to exceed the supplied boundary
* @param start * @param value {number}
* @param end
* @private * @private
*/ */
static _exceed (start, end) { static _exceed (value) {
const value = random.item([start, end]) switch (random.number(4)) {
const offset = random.range(-3, 3) case 0:
return value + offset // Divisions
return Math.ceil(value / random.range(2, 4))
case 1:
// Powers
const offset = Math.pow(2, random.range(1, 7))
return (value > 0) ? (value - offset) : value + offset
default:
// Slightly less than limit
return (value > 0) ? (value - random.number(3)) : value + random.number(3)
}
} }
/** /**
@ -25,7 +33,10 @@ class number extends make {
*/ */
static int8 (bypass = false) { static int8 (bypass = false) {
if (bypass || random.chance(50)) { if (bypass || random.chance(50)) {
return number._exceed(-128, 127) return number._exceed(random.choose([
[1, -128],
[10, 127]
]))
} }
return random.range(-128, 127) return random.range(-128, 127)
@ -38,7 +49,7 @@ class number extends make {
*/ */
static uint8 (bypass = false) { static uint8 (bypass = false) {
if (bypass || random.chance(50)) { if (bypass || random.chance(50)) {
return number._exceed(0, 255) return number._exceed(255)
} }
return random.range(0, 255) return random.range(0, 255)
@ -51,7 +62,10 @@ class number extends make {
*/ */
static int16 (bypass = false) { static int16 (bypass = false) {
if (bypass || random.chance(50)) { if (bypass || random.chance(50)) {
return number._exceed(-32768, 32767) return number._exceed(random.choose([
[1, -32768],
[10, 32767]
]))
} }
return random.range(-32768, 32767) return random.range(-32768, 32767)
@ -64,7 +78,7 @@ class number extends make {
*/ */
static uint16 (bypass = false) { static uint16 (bypass = false) {
if (bypass || random.chance(50)) { if (bypass || random.chance(50)) {
return number._exceed(0, 65535) return number._exceed(65535)
} }
return random.range(-0, 65535) return random.range(-0, 65535)
@ -77,7 +91,10 @@ class number extends make {
*/ */
static int32 (bypass = false) { static int32 (bypass = false) {
if (bypass || random.chance(50)) { if (bypass || random.chance(50)) {
return number._exceed(-2147483648, 2147483647) return number._exceed(random.choose([
[1, -2147483648],
[10, 2147483647]
]))
} }
return random.range(-2147483648, 2147483647) return random.range(-2147483648, 2147483647)
@ -90,7 +107,7 @@ class number extends make {
*/ */
static uint32 (bypass = false) { static uint32 (bypass = false) {
if (bypass || random.chance(50)) { if (bypass || random.chance(50)) {
return number._exceed(0, 4294967295) return number._exceed(4294967295)
} }
return random.range(0, 4294967295) return random.range(0, 4294967295)