4 const assert
= require('assert');
5 const { toRoman
} = require('../index');
7 const noExpectedException
= 'did not get expected exception';
40 describe('toRoman', function () {
41 it('requires a value', function () {
44 assert
.fail(noExpectedException
);
46 assert(e
instanceof RangeError
, noExpectedException
);
50 it('requires a numeric value', function () {
53 assert
.fail(noExpectedException
);
55 assert(e
instanceof RangeError
, noExpectedException
);
59 it('accepts a numeric-like value', function () {
60 const result
= toRoman('5');
61 assert
.strictEqual(result
, 'Ⅴ');
64 it('requires a positive numeric value', function () {
67 assert
.fail(noExpectedException
);
69 assert(e
instanceof RangeError
, noExpectedException
);
73 it('returns single-characters for small numbers', function () {
74 const expectedLength
= 'Ⅹ'.length
;
75 for (let i
= 1; i
<= 12; i
++) {
76 const result
= toRoman(i
);
77 assert
.strictEqual(result
.length
, expectedLength
, `input '${i}' -> '${result}' (length ${result.length})`);
81 it('returns single-glyph entities for small numbers', function () {
82 const expectedLength
= 'Ⅰ'.length
;
83 for (let i
= 1; i
<= 12; i
++) {
84 const result
= toRoman(i
, true);
85 assert
.strictEqual(result
.length
, expectedLength
, `input '${i}' -> '${result}' (length ${result.length})`);
89 it('converts correctly', function () {
90 Object
.entries(spotChecks
).forEach(([num
, expected
]) => {
91 const result
= toRoman(num
);
92 assert
.strictEqual(result
, expected
);