UNPKG

@tonkite/jest-tolk

Version:

<p align="center"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/tonkite/tonkite/main/assets/logo-dark.svg"> <img alt="tonkite logo" src="https://raw.githubusercontent.com/tonkite/tonkite/main/a

34 lines (33 loc) 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateIntValues = generateIntValues; function generateIntValues(bits, signed, count) { const result = []; const edgeCases = signed ? [ BigInt(0), BigInt(1), BigInt(-1), (BigInt(1) << BigInt(bits - 1)) - BigInt(1), -(BigInt(1) << BigInt(bits - 1)), ] : [BigInt(0), BigInt(1), (BigInt(1) << BigInt(bits)) - BigInt(1)]; edgeCases.forEach((value) => result.push({ type: 'int', value, })); while (result.length < count) { result.push({ type: 'int', value: generateRandom(bits, signed), }); } return result; } function generateRandom(bits, signed) { const max = signed ? (BigInt(1) << BigInt(bits - 1)) - BigInt(1) : (BigInt(1) << BigInt(bits)) - BigInt(1); const value = BigInt(Math.floor(Math.random() * Number(max))); return signed && Math.random() < 0.5 ? -value : value; }