-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
98 lines (84 loc) · 3.25 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import test from 'ava';
import calculateHomeLoan from './index.js';
test('Calculate home loan and expect object', t => {
let result = calculateHomeLoan(80000, 30, 4.5, 12);
t.is(typeof result, 'object');
});
test('Calculate home loan at 4.5% for 30 years', t => {
let result = calculateHomeLoan(80000, 30, 4.5, 12);
t.is(result.monthlyPayment, 405.35);
t.is(result.totalPayment, 145925.37);
t.is(result.totalInterest, 65925.37);
});
test('Calculate home loan at 3.5% for 15 years', t => {
let result = calculateHomeLoan(80000, 15, 3.5, 12);
t.is(result.monthlyPayment, 571.91);
t.is(result.totalPayment, 102943.09);
t.is(result.totalInterest, 22943.09);
});
test('Calculate home loan at 5.0% for 20 years', t => {
let result = calculateHomeLoan(80000, 20, 5.0, 12);
t.is(result.monthlyPayment, 527.96);
t.is(result.totalPayment, 126711.5);
t.is(result.totalInterest, 46711.5);
});
test('Calculate home loan with 0% interest', t => {
let result = calculateHomeLoan(80000, 30, 0.0, 12);
t.is(result.monthlyPayment, 222.22);
t.is(result.totalPayment, 80000);
t.is(result.totalInterest, 0);
});
test('Calculate home loan with 0 years', t => {
let result = calculateHomeLoan(80000, 0, 4.5, 12);
t.is(result.monthlyPayment, 80000);
t.is(result.totalPayment, 80000);
t.is(result.totalInterest, 0);
});
test('Calculate home loan with 0 loan value', t => {
let result = calculateHomeLoan(0, 30, 4.5, 12);
t.is(result.monthlyPayment, 0);
t.is(result.totalPayment, 0);
t.is(result.totalInterest, 0);
});
test('Calculate home loan with 0 frequency', t => {
let result = calculateHomeLoan(80000, 30, 4.5, 0);
t.is(result.monthlyPayment, 80000);
t.is(result.totalPayment, 80000);
t.is(result.totalInterest, 0);
});
test('Calculate home loan with 0 rate', t => {
let result = calculateHomeLoan(80000, 30, 0, 12);
t.is(result.monthlyPayment, 222.22);
t.is(result.totalPayment, 80000);
t.is(result.totalInterest, 0);
});
test('Calculate home loan with 0 0 loan value, 0 years, 0 rate, 0 frequency', t => {
let result = calculateHomeLoan(0, 0, 0, 0);
t.is(result.monthlyPayment, 0);
t.is(result.totalPayment, 0);
t.is(result.totalInterest, 0);
});
test('Calculate home loan with negative loan value, years, rate, frequency', t => {
let result = calculateHomeLoan(-80000, -30, -4.5, -12);
t.is(result.monthlyPayment, NaN);
t.is(result.totalPayment, NaN);
t.is(result.totalInterest, NaN);
});
test('Calculate home loan with null loan value, years, rate, frequency', t => {
let result = calculateHomeLoan(null, null, null, null);
t.is(result.monthlyPayment, NaN);
t.is(result.totalPayment, NaN);
t.is(result.totalInterest, NaN);
});
test('Calculate home loan with undefined loan value, years, rate, frequency', t => {
let result = calculateHomeLoan(undefined, undefined, undefined, undefined);
t.is(result.monthlyPayment, NaN);
t.is(result.totalPayment, NaN);
t.is(result.totalInterest, NaN);
});
test('Calculate home loan with missing loan value, years, rate, frequency', t => {
let result = calculateHomeLoan();
t.is(result.monthlyPayment, NaN);
t.is(result.totalPayment, NaN);
t.is(result.totalInterest, NaN);
});