Skip to content

Commit a45cd1b

Browse files
committed
transportation on vacation: done
1 parent 4fa0a5d commit a45cd1b

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

transportation_on_vacation/main.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function rentalCarCost(d) {
2+
return (d * 40) - (d >= 7 ? 50 : d >= 3 ? 20 : 0);
3+
}
4+
5+
/// Readable and reusable codes.
6+
// function baseCost(days, rate) {
7+
// return days * rate;
8+
// }
9+
10+
// function discountRate(days) {
11+
// if ( days >= 7 ) {
12+
// return 50;
13+
// }
14+
// else if ( days >= 3 ) {
15+
// return 20;
16+
// }
17+
// else {
18+
// return 0;
19+
// }
20+
// }
21+
22+
// function rentalCarCost(days) {
23+
// return baseCost(days, 40) - discountRate(days);
24+
// }
25+
26+
module.exports = rentalCarCost;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const rentalCarCost = require('./main');
2+
3+
describe('every day 40$ cost adding up test', () => {
4+
test('1 should return 40', () => {
5+
expect(rentalCarCost(1)).toBe(40);
6+
});
7+
test('2 should return 80', () => {
8+
expect(rentalCarCost(2)).toBe(80);
9+
});
10+
});
11+
12+
describe('rent a car more than 3 days, 20$ off test', () => {
13+
test('3 should return 100', () => {
14+
expect(rentalCarCost(3)).toBe(100);
15+
});
16+
test('4 should return 140', () => {
17+
expect(rentalCarCost(4)).toBe(140);
18+
});
19+
test('5 should return 180', () => {
20+
expect(rentalCarCost(5)).toBe(180);
21+
});
22+
});
23+
24+
describe('rent a car more than 7 days, 50$ off test', () => {
25+
test('7 should return 230', () => {
26+
expect(rentalCarCost(7)).toBe(230);
27+
});
28+
test('8 should return 270', () => {
29+
expect(rentalCarCost(8)).toBe(270);
30+
});
31+
});

0 commit comments

Comments
 (0)