|
1 | 1 | import validator from 'validator'; |
2 | | -import { describe, expect, it } from 'vitest'; |
| 2 | +import { describe, expect, it, vi } from 'vitest'; |
3 | 3 | import { FakerError, SimpleFaker, faker } from '../../src'; |
4 | 4 | import { seededTests } from '../support/seeded-runs'; |
5 | 5 | import { MERSENNE_MAX_VALUE } from '../utils/mersenne-test-utils'; |
@@ -47,6 +47,16 @@ describe('number', () => { |
47 | 47 | max: 32465761264574654845432354n, |
48 | 48 | }); |
49 | 49 | }); |
| 50 | + |
| 51 | + t.describe('romanNumeral', (t) => { |
| 52 | + t.it('noArgs') |
| 53 | + .it('with number value', 1000) |
| 54 | + .it('with only min', { min: 5 }) |
| 55 | + .it('with only max', { max: 165 }) |
| 56 | + .it('with min as 1', { min: 1 }) |
| 57 | + .it('with max as 3999', { max: 3999 }) |
| 58 | + .it('with min and max', { min: 100, max: 502 }); |
| 59 | + }); |
50 | 60 | }); |
51 | 61 |
|
52 | 62 | describe(`random seeded tests for seed ${faker.seed()}`, () => { |
@@ -625,6 +635,68 @@ describe('number', () => { |
625 | 635 | ); |
626 | 636 | }); |
627 | 637 | }); |
| 638 | + |
| 639 | + describe('romanNumeral', () => { |
| 640 | + it('should generate a Roman numeral within default range', () => { |
| 641 | + const roman = faker.number.romanNumeral(); |
| 642 | + expect(roman).toBeTypeOf('string'); |
| 643 | + expect(roman).toMatch(/^[IVXLCDM]+$/); |
| 644 | + }); |
| 645 | + |
| 646 | + it('should generate a Roman numeral with max value of 1000', () => { |
| 647 | + const roman = faker.number.romanNumeral(1000); |
| 648 | + expect(roman).toMatch(/^[IVXLCDM]+$/); |
| 649 | + }); |
| 650 | + |
| 651 | + it.each( |
| 652 | + Object.entries({ |
| 653 | + I: 1, |
| 654 | + IV: 4, |
| 655 | + IX: 9, |
| 656 | + X: 10, |
| 657 | + XXVII: 27, |
| 658 | + XC: 90, |
| 659 | + XCIX: 99, |
| 660 | + CCLXIII: 263, |
| 661 | + DXXXVI: 536, |
| 662 | + DCCXIX: 719, |
| 663 | + MDCCCLI: 1851, |
| 664 | + MDCCCXCII: 1892, |
| 665 | + MMCLXXXIII: 2183, |
| 666 | + MMCMXLIII: 2943, |
| 667 | + MMMDCCLXVI: 3766, |
| 668 | + MMMDCCLXXIV: 3774, |
| 669 | + MMMCMXCIX: 3999, |
| 670 | + }) |
| 671 | + )( |
| 672 | + 'should generate a Roman numeral %s for value %d', |
| 673 | + (expected: string, value: number) => { |
| 674 | + const mock = vi.spyOn(faker.number, 'int'); |
| 675 | + mock.mockReturnValue(value); |
| 676 | + const actual = faker.number.romanNumeral(); |
| 677 | + mock.mockRestore(); |
| 678 | + expect(actual).toBe(expected); |
| 679 | + } |
| 680 | + ); |
| 681 | + |
| 682 | + it('should throw when min value is less than 1', () => { |
| 683 | + expect(() => { |
| 684 | + faker.number.romanNumeral({ min: 0 }); |
| 685 | + }).toThrow(new FakerError('Min value 0 should be 1 or greater.')); |
| 686 | + }); |
| 687 | + |
| 688 | + it('should throw when max value is greater than 3999', () => { |
| 689 | + expect(() => { |
| 690 | + faker.number.romanNumeral({ max: 4000 }); |
| 691 | + }).toThrow(new FakerError('Max value 4000 should be 3999 or less.')); |
| 692 | + }); |
| 693 | + |
| 694 | + it('should throw when max value is less than min value', () => { |
| 695 | + expect(() => { |
| 696 | + faker.number.romanNumeral({ min: 500, max: 100 }); |
| 697 | + }).toThrow(new FakerError('Max 100 should be greater than min 500.')); |
| 698 | + }); |
| 699 | + }); |
628 | 700 | }); |
629 | 701 |
|
630 | 702 | describe('value range tests', () => { |
|
0 commit comments