roman-numeral-to-decimal
Version:
A module that converts a string of Roman numerals into its decimal equivalent
31 lines (25 loc) • 1.13 kB
JavaScript
const romanNumeralToDecimal = require('../index.js');
const expect = require('chai').expect;
describe('romanNumeralToDecimal invalid input test cases', () => {
it('should return -1 when input is an empty string', () => {
expect(romanNumeralToDecimal('')).to.equal(-1);
});
it('should return -1 when input contains a non-Roman numeral', () => {
expect(romanNumeralToDecimal('aX')).to.equal(-1);
expect(romanNumeralToDecimal('XXa')).to.equal(-1);
});
it('should return -1 when input is a non-String', () => {
expect(romanNumeralToDecimal(5)).to.equal(-1);
});
});
describe('romanNumeralToDecimal valid input test cases', () => {
it('should properly calculate a single (digit) numeral', () => {
expect(romanNumeralToDecimal('X')).to.equal(10);
});
it('should properly calculate a multi-digit numeral', () => {
expect(romanNumeralToDecimal('XII')).to.equal(12);
});
it('should properly calculate a numeral where smaller denominations precede larger', () => {
expect(romanNumeralToDecimal('MCMLXXXVII')).to.equal(1987);
});
});