-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
58 lines (47 loc) · 1003 Bytes
/
test.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
const Mortgage = require('./index.js')
let m = new Mortgage(500000, 20, 4, 30)
let monthly = m.getMonthly()
let monthExp = 1910
let total = m.getTotal()
let totalExp = 687478
assertEqual(monthly, monthExp)
assertEqual(total, totalExp)
m = new Mortgage(1500000, 20, 4, 30)
monthly = m.getMonthly()
monthExp = 5729
total = m.getTotal()
totalExp = 2062434
assertEqual(monthly, monthExp)
assertEqual(total, totalExp)
try {
m = new Mortgage(1500000, 101, 4, 30)
} catch (error) {
console.log(error)
}
try {
m = new Mortgage(1500000, 0, 4, 30)
} catch (error) {
console.log(error)
}
try {
m = new Mortgage(1500000, 20, 21, 30)
} catch (error) {
console.log(error)
}
try {
m = new Mortgage(1500000, 20, -1, 30)
} catch (error) {
console.log(error)
}
try {
m = new Mortgage(1500000, 20, 4)
} catch (error) {
console.log(error)
}
function assertEqual(a, b) {
if (a === b) {
console.log(`Test PASS: ${a} === ${b}`);
} else {
console.log(`Test FAIL: ${a} != ${b}`);
}
}