Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new tests #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"author": "Ashok Dey <[email protected]> (http://ashokdey.in)",
"license": "MIT",
"devDependencies": {
"chai": "^4.3.9",
"eslint": "^8.2.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
Expand Down
19 changes: 19 additions & 0 deletions src/_Problems_/Century_fromYear/Century_fromYear.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { expect } = require('chai');
const getCentury = require('./index');

describe('Century Calculation Function', () => {
it('should return the correct century for the year 45', () => {
const result = getCentury(45);
expect(result).to.equal(1);
});

it('should return the correct century for the year 175', () => {
const result = getCentury(175);
expect(result).to.equal(2);
});

it('should return the correct century for the year 2023', () => {
const result = getCentury(2023);
expect(result).to.equal(21);
});
});
7 changes: 7 additions & 0 deletions src/_Problems_/Century_fromYear/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function getCentury(year) {
// Your century calculation logic here
return Math.ceil(year / 100);
}

// Export the getCentury function for testing
module.exports = getCentury;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { expect } = require('chai');
const timeSinceMidnight = require('./index');

describe('Time Since Midnight Calculation', () => {
it('should return the correct time in milliseconds for 1 hour, 15 minutes, and 30 seconds', () => {
const result = timeSinceMidnight(1, 15, 30);
expect(result).to.equal(4530000);
});

it('should return 0 milliseconds for midnight (0 hours, 0 minutes, 0 seconds)', () => {
const result = timeSinceMidnight(0, 0, 0);
expect(result).to.equal(0);
});

it('should return the correct time in milliseconds for 23 hours, 59 minutes, and 59 seconds', () => {
const result = timeSinceMidnight(23, 59, 59);
expect(result).to.equal(86399000);
});
});
6 changes: 6 additions & 0 deletions src/_Problems_/convert-to-milliseconds/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function timeSinceMidnight(h, m, s) {
// Convert hours, minutes, and seconds to milliseconds and calculate the total
return (h * 3600 + m * 60 + s) * 1000;
}

module.exports = timeSinceMidnight;
18 changes: 18 additions & 0 deletions src/_Problems_/roman-numerals-encoder/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function integerToRoman(num) {
// Define the Roman numeral symbols and their corresponding values
const symbols = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
const values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];

let romanNumeral = '';

for (let i = 0; i < symbols.length; i++) {
while (num >= values[i]) {
romanNumeral += symbols[i];
num -= values[i];
}
}

return romanNumeral;
}

module.exports = integerToRoman;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { expect } = require('chai');
const integerToRoman = require('./index');

describe('Integer to Roman Numeral Conversion', () => {
it('should return "IV" for the integer 4', () => {
const result = integerToRoman(4);
expect(result).to.equal('IV');
});

it('should return "IX" for the integer 9', () => {
const result = integerToRoman(9);
expect(result).to.equal('IX');
});

it('should return "LVIII" for the integer 58', () => {
const result = integerToRoman(58);
expect(result).to.equal('LVIII');
});

it('should return "MCMXCIV" for the integer 1994', () => {
const result = integerToRoman(1994);
expect(result).to.equal('MCMXCIV');
});
});