describe('randos', () => { test('should return an array of finite random weights', () => { const temp = randos(10); const tempCheck = temp.filter((el) => Number.isFinite(el)); expect(temp.length).toBe(tempCheck.length); }); });
function stoppedCasting () { state.playing.location = 'local' state.playing.jumpToTime = Number.isFinite(state.playing.currentTime) ? state.playing.currentTime : 0 update() }
const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => { if (forceKillAfterTimeout === true) { return DEFAULT_FORCE_KILL_TIMEOUT; } if (!Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) { throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`); } return forceKillAfterTimeout; }
generateStr(eta, ratio) { const fmteta = Number.isNaN(eta) || !Number.isFinite(eta) ? 0 : eta / 1000; const str = this.fmt .replace(':eta', fmteta.toFixed(1)) .replace(':percent', `${(ratio * 100).toFixed(0)}%`); const availableSpace = Math.max( 0, this.stream.columns - str.replace(':bar', '').length ); const width = Math.min(this.width, availableSpace); const len = Math.max(0, Math.round(width * ratio)); const complete = new Array(len + 1).join('▓'); const incomplete = new Array(width - len + 1).join('░'); return str.replace(':bar', `${complete}${incomplete}`); }
// Skip (aka seek) to a specific point, in seconds skipTo (time) { if (!Number.isFinite(time)) { console.error('Tried to skip to a non-finite time ' + time) return console.trace() } if (isCasting(this.state)) Cast.seek(time) else this.state.playing.jumpToTime = time }
number(num) { if (typeof num === `bigint` || Number.isFinite(num)) { return num.toString(); } // Converting NaN/+Infinity/-Infinity according to Postgres documentation: // http://www.postgresql.org/docs/9.6/static/datatype-numeric.html#DATATYPE-FLOAT // // NOTE: strings for 'NaN'/'+Infinity'/'-Infinity' are not case-sensitive. if (num === Number.POSITIVE_INFINITY) { return wrapText(`+Infinity`); } if (num === Number.NEGATIVE_INFINITY) { return wrapText(`-Infinity`); } return wrapText(`NaN`); }
if (!Number.isFinite(labelValuePair.value)) { throw new TypeError( `Value is not a valid number: ${util.format(labelValuePair.value)}`,
const inc = function (labels, hash) { return value => { if (value && !Number.isFinite(value)) { throw new TypeError(`Value is not a valid number: ${util.format(value)}`); } if (value < 0) { throw new Error('It is not possible to decrease a counter'); } labels = labels || {}; validateLabel(this.labelNames, labels); const incValue = value === null || value === undefined ? 1 : value; this.hashMap = setValue(this.hashMap, incValue, labels, hash); }; }
case 'number': if (Number.isFinite(value) === false) { value = null
if (!Number.isFinite(labelValuePair.value)) { throw new TypeError( `Value is not a valid number: ${util.format(labelValuePair.value)}`,
// `timeout` option handling const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise) => { if (timeout === 0 || timeout === undefined) { return spawnedPromise; } if (!Number.isFinite(timeout) || timeout < 0) { throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`); } let timeoutId; const timeoutPromise = new Promise((resolve, reject) => { timeoutId = setTimeout(() => { timeoutKill(spawned, killSignal, reject); }, timeout); }); const safeSpawnedPromise = spawnedPromise.finally(() => { clearTimeout(timeoutId); }); return Promise.race([timeoutPromise, safeSpawnedPromise]); }
it("should generate a valid byte", () => { let schema = new JsonSchema({ type: "string", format: "byte" }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(0) .and.at.most(255); } });
function unary(op) { const arg = chr == '(' ? expr() : token(); if (op.name == '-' && arg.type == 'literal' && Number.isFinite(arg.value)) { return { type: 'literal', value: -arg.value }; } else { return { ...op, args: [arg] }; } }
it("should generate a valid int32", () => { let schema = new JsonSchema({ type: "integer", format: "int32" }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(-2147483648) .and.at.most(2147483647); } });
it("should generate a valid number above minimum", () => { let min = MAX_SAFE_INTEGER - 10; let schema = new JsonSchema({ type: "integer", minimum: min }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(min) .and.at.most(MAX_SAFE_INTEGER); } });