Skip to content

Commit 5128115

Browse files
committed
Added new tests
1 parent d62e62c commit 5128115

File tree

8 files changed

+233
-0
lines changed

8 files changed

+233
-0
lines changed

package-lock.json

+139
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"author": "Ashok Dey <[email protected]> (http://ashokdey.in)",
2828
"license": "MIT",
2929
"devDependencies": {
30+
"chai": "^4.3.9",
3031
"eslint": "^8.2.0",
3132
"eslint-config-airbnb": "^19.0.4",
3233
"eslint-config-prettier": "^8.5.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { expect } = require('chai');
2+
const getCentury = require('./index');
3+
4+
describe('Century Calculation Function', () => {
5+
it('should return the correct century for the year 45', () => {
6+
const result = getCentury(45);
7+
expect(result).to.equal(1);
8+
});
9+
10+
it('should return the correct century for the year 175', () => {
11+
const result = getCentury(175);
12+
expect(result).to.equal(2);
13+
});
14+
15+
it('should return the correct century for the year 2023', () => {
16+
const result = getCentury(2023);
17+
expect(result).to.equal(21);
18+
});
19+
});
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function getCentury(year) {
2+
// Your century calculation logic here
3+
return Math.ceil(year / 100);
4+
}
5+
6+
// Export the getCentury function for testing
7+
module.exports = getCentury;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { expect } = require('chai');
2+
const timeSinceMidnight = require('./index');
3+
4+
describe('Time Since Midnight Calculation', () => {
5+
it('should return the correct time in milliseconds for 1 hour, 15 minutes, and 30 seconds', () => {
6+
const result = timeSinceMidnight(1, 15, 30);
7+
expect(result).to.equal(4530000);
8+
});
9+
10+
it('should return 0 milliseconds for midnight (0 hours, 0 minutes, 0 seconds)', () => {
11+
const result = timeSinceMidnight(0, 0, 0);
12+
expect(result).to.equal(0);
13+
});
14+
15+
it('should return the correct time in milliseconds for 23 hours, 59 minutes, and 59 seconds', () => {
16+
const result = timeSinceMidnight(23, 59, 59);
17+
expect(result).to.equal(86399000);
18+
});
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function timeSinceMidnight(h, m, s) {
2+
// Convert hours, minutes, and seconds to milliseconds and calculate the total
3+
return (h * 3600 + m * 60 + s) * 1000;
4+
}
5+
6+
module.exports = timeSinceMidnight;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function integerToRoman(num) {
2+
// Define the Roman numeral symbols and their corresponding values
3+
const symbols = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I'];
4+
const values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
5+
6+
let romanNumeral = '';
7+
8+
for (let i = 0; i < symbols.length; i++) {
9+
while (num >= values[i]) {
10+
romanNumeral += symbols[i];
11+
num -= values[i];
12+
}
13+
}
14+
15+
return romanNumeral;
16+
}
17+
18+
module.exports = integerToRoman;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { expect } = require('chai');
2+
const integerToRoman = require('./index');
3+
4+
describe('Integer to Roman Numeral Conversion', () => {
5+
it('should return "IV" for the integer 4', () => {
6+
const result = integerToRoman(4);
7+
expect(result).to.equal('IV');
8+
});
9+
10+
it('should return "IX" for the integer 9', () => {
11+
const result = integerToRoman(9);
12+
expect(result).to.equal('IX');
13+
});
14+
15+
it('should return "LVIII" for the integer 58', () => {
16+
const result = integerToRoman(58);
17+
expect(result).to.equal('LVIII');
18+
});
19+
20+
it('should return "MCMXCIV" for the integer 1994', () => {
21+
const result = integerToRoman(1994);
22+
expect(result).to.equal('MCMXCIV');
23+
});
24+
});

0 commit comments

Comments
 (0)