-
Notifications
You must be signed in to change notification settings - Fork 0
/
vehicle-purchase.spec.js
74 lines (61 loc) · 2.12 KB
/
vehicle-purchase.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {
needsLicense,
chooseVehicle,
calculateResellPrice,
} from './vehicle-purchase';
describe('vehicle purchase', () => {
describe('needsLicense', () => {
test('requires a license for a car', () => {
expect(needsLicense('car')).toBe(true);
});
test('requires a license for a truck', () => {
expect(needsLicense('truck')).toBe(true);
});
test('does not require a license for a bike', () => {
expect(needsLicense('bike')).toBe(false);
});
test('does not require a license for a stroller', () => {
expect(needsLicense('stroller')).toBe(false);
});
test('does not require a license for an e-scooter', () => {
expect(needsLicense('e-scooter')).toBe(false);
});
});
describe('chooseVehicle', () => {
const rest = ' is clearly the better choice.';
test('correctly recommends the first option', () => {
expect(chooseVehicle('Bugatti Veyron', 'Ford Pinto')).toBe(
'Bugatti Veyron' + rest
);
expect(chooseVehicle('Chery EQ', 'Kia Niro Elektro')).toBe(
'Chery EQ' + rest
);
});
test('correctly recommends the second option', () => {
expect(chooseVehicle('Ford Pinto', 'Bugatti Veyron')).toBe(
'Bugatti Veyron' + rest
);
expect(chooseVehicle('2020 Gazelle Medeo', '2018 Bergamont City')).toBe(
'2018 Bergamont City' + rest
);
});
});
describe('calculateResellPrice', () => {
test('price is reduced to 80% for age below 3', () => {
expect(calculateResellPrice(40000, 2)).toBe(32000);
expect(calculateResellPrice(40000, 2.5)).toBe(32000);
});
test('price is reduced to 50% for age above 10', () => {
expect(calculateResellPrice(40000, 12)).toBe(20000);
});
test('price is reduced to 70% for between 3 and 10', () => {
expect(calculateResellPrice(25000, 7)).toBe(17500);
});
test('works correctly for threshold age 3', () => {
expect(calculateResellPrice(40000, 3)).toBe(28000);
});
test('works correctly for threshold age 10', () => {
expect(calculateResellPrice(25000, 10)).toBe(17500);
});
});
});