40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import {describe, beforeAll, it, expect} from 'bun:test';
|
|
import {Strings} from '../../src/strings';
|
|
|
|
const randomStringCount = 11;
|
|
|
|
describe('When generating random strings', () => {
|
|
it('generates a random string', () => {
|
|
const randomString = Strings.random();
|
|
|
|
expect(typeof randomString).toBe('string');
|
|
expect(randomString.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
describe('Given a length argument', () => {
|
|
const length = 4;
|
|
|
|
it('generates a random string of the given length', () => {
|
|
const randomString = Strings.random(length);
|
|
|
|
expect(typeof randomString).toBe('string');
|
|
expect(randomString.length).toBeGreaterThan(0);
|
|
expect(randomString.length).toBe(length);
|
|
});
|
|
});
|
|
|
|
describe(`Given [${randomStringCount}] are generated`, () => {
|
|
let randomStrings;
|
|
|
|
beforeAll(() => {
|
|
randomStrings = Array.from({length: randomStringCount}, () => Strings.random());
|
|
});
|
|
|
|
it('generates random strings such that no strings are identical', () => {
|
|
const uniqueRandomStrings = new Set(randomStrings);
|
|
|
|
expect(uniqueRandomStrings.size).toBe(randomStringCount);
|
|
});
|
|
});
|
|
});
|