Files
directus/packages/random/src/integer.test.ts
Rijk van Zanten 243fa71b12 New functions for @directus/random (#18668)
* Add array randomizer

* Add sequence randomizer

* Add barebones readme

* Rename randomIntBetween -> randomInteger

* Finish couple new randomizer functions

* Add basic tsdoc

* Add changeset

* Downgrade types/node
2023-05-19 17:21:39 -04:00

12 lines
421 B
TypeScript

import { test, expect } from 'vitest';
import { randomInteger } from './integer.js';
test('Returns random number in range', () => {
const testInts = Array.from(Array(2)).map(() => Math.floor(Math.random() * 1000));
const min = Math.min(...testInts);
const max = Math.max(...testInts);
const output = randomInteger(min, max);
expect(output).toBeGreaterThanOrEqual(min);
expect(output).toBeLessThanOrEqual(max);
});