Skip to content

Commit

Permalink
finalFinal
Browse files Browse the repository at this point in the history
  • Loading branch information
tonela10 committed May 14, 2024
1 parent 9320c01 commit 86bf364
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions implementation/romans.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// romans.js

// Constants for the literals
const INVALID_ROMAN = 'Please enter a valid roman';
const INVALID_INTEGER = 'Please enter a valid integer';
const OUT_OF_RANGE = 'Out of range (1-3999)';

function init() {
function init() {
// Load elements once to avoid repetition on every invocation
var modeCheckbox = document.querySelector('input[type="checkbox"]');
var header = document.querySelector('h1');
Expand All @@ -19,8 +21,8 @@ function init() {
return integerToRoman ? 'Integer To Roman' : 'Roman To Integer';
};

// Now, the conversion operation only performs the operation.
// Extracted actions to this listener:
// Now, the conversion operation does only perform the operation.
// Things we have extracted to this listener:
// 1 - Read the UI inputs (inputArea.value)
// 2 - Write the UI output (outputArea.innerHTML)
// 3 - Show error messages
Expand All @@ -36,12 +38,16 @@ function init() {
});
}

// Conversion method for Roman to Integer
// Now the conversion methods receive both an input argument instead
// of reading directly from the UI.
// On top of that, they return a JSON object instead of updating the
// UI directly. The JSON object contains the result (ok/nok), the value
// and an error message if needed
const convertRomanToInteger = (roman) => {
let response = {
value: 0,
value: 0,
message: '',
result: false
result: false
};

// Regexp to check if a string is a valid roman number
Expand Down
2 changes: 1 addition & 1 deletion implementation/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ QUnit.test("convertIntegerToRoman Test Cases", function(assert) {
// Test Cases for convertIntegerToRoman

// TC-1
assert.propEqual(convertIntegerToRoman(1), {value: "I", message: '', result: true}, "TC-1");
assert.equal(convertIntegerToRoman(1), {value: "I", message: '', result: true}, "TC-1");

// TC-2
assert.propEqual(convertIntegerToRoman(3999), {value: "MMMCMXCIX", message: '', result: true}, "TC-2");
Expand Down

0 comments on commit 86bf364

Please sign in to comment.