Skip to content

Commit

Permalink
Created a function named roman numeral in faker.number to generate an…
Browse files Browse the repository at this point in the history
… random roman numeral
  • Loading branch information
AmaanRS committed Oct 20, 2024
1 parent 9ac3c1c commit 2cf192a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
33 changes: 32 additions & 1 deletion test/modules/number.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import validator from 'validator';
import { describe, expect, it } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import { FakerError, SimpleFaker, faker } from '../../src';
import { seededTests } from '../support/seeded-runs';
import { MERSENNE_MAX_VALUE } from '../utils/mersenne-test-utils';
Expand Down Expand Up @@ -667,6 +667,37 @@ describe('number', () => {
expect(values).toContain(roman);
});

it.each(
Object.entries({
I: 1,
IV: 4,
IX: 9,
X: 10,
XC: 90,
XCIX: 99,
XXVII: 27,
CCLXIII: 263,
DXXXVI: 536,
DCCXIX: 719,
MDCCCLI: 1851,
MDCCCXCII: 1892,
MMCLXXXIII: 2183,
MMCMXLIII: 2943,
MMMDCCLXVI: 3766,
MMMDCCLXXIV: 3774,
MMMCMXCIX: 3999,
})
)(
'should generate a Roman numeral %s for value %d',
(expected: string, value: number) => {
const mock = vi.spyOn(faker.number, 'int');
mock.mockReturnValue(value);
const actual = faker.number.romanNumeral();
mock.mockRestore();
expect(actual).toBe(expected);
}
);

it('should throw when min value is less than 1', () => {
expect(() => {
faker.number.romanNumeral({ min: 0 });
Expand Down
22 changes: 22 additions & 0 deletions tsconfig.vitest-temp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "ESNext",
"moduleResolution": "Bundler",
"module": "ESNext",
"strict": true,
"noEmit": true,
"stripInternal": true,
"verbatimModuleSyntax": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"emitDeclarationOnly": false,
"incremental": true,
"tsBuildInfoFile": "/home/amaan/Desktop/Open Source/fakerrrr/node_modules/.pnpm/vitest@2.1.2_@types+node@20.16.11_@vitest+ui@2.1.2_jsdom@25.0.1/node_modules/vitest/dist/chunks/tsconfig.tmp.tsbuildinfo"
},
"exclude": [
"node_modules",
"dist",
"test/scripts/apidocs/temp"
]
}

0 comments on commit 2cf192a

Please sign in to comment.