8
8
TEST_CASE (" Minimal first interest rate" , " [task_1]" ) {
9
9
double balance{0 };
10
10
double want{0.5 };
11
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
11
+ REQUIRE_THAT (interest_rate (balance),
12
+ Catch::Matchers::WithinRel (want, 0.000001 ));
12
13
}
13
14
14
15
#if defined(EXERCISM_RUN_ALL_TESTS)
15
16
16
17
TEST_CASE (" Tiny first interest rate" , " [task_1]" ) {
17
18
double balance{0.000001 };
18
19
double want{0.5 };
19
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
20
+ REQUIRE_THAT (interest_rate (balance),
21
+ Catch::Matchers::WithinRel (want, 0.000001 ));
20
22
}
21
23
22
24
TEST_CASE (" Maximum first interest rate" , " [task_1]" ) {
23
25
double balance{999.9999 };
24
26
double want{0.5 };
25
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
27
+ REQUIRE_THAT (interest_rate (balance),
28
+ Catch::Matchers::WithinRel (want, 0.000001 ));
26
29
}
27
30
28
31
TEST_CASE (" Minimal second interest rate" , " [task_1]" ) {
29
32
double balance{1000.0 };
30
33
double want{1.621 };
31
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
34
+ REQUIRE_THAT (interest_rate (balance),
35
+ Catch::Matchers::WithinRel (want, 0.000001 ));
32
36
}
33
37
34
38
TEST_CASE (" Tiny second interest rate" , " [task_1]" ) {
35
39
double balance{1000.0001 };
36
40
double want{1.621 };
37
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
41
+ REQUIRE_THAT (interest_rate (balance),
42
+ Catch::Matchers::WithinRel (want, 0.000001 ));
38
43
}
39
44
40
45
TEST_CASE (" Maximum second interest rate" , " [task_1]" ) {
41
46
double balance{4999.9990 };
42
47
double want{1.621 };
43
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
48
+ REQUIRE_THAT (interest_rate (balance),
49
+ Catch::Matchers::WithinRel (want, 0.000001 ));
44
50
}
45
51
46
52
TEST_CASE (" Minimal third interest rate" , " [task_1]" ) {
47
53
double balance{5000.0000 };
48
54
double want{2.475 };
49
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
55
+ REQUIRE_THAT (interest_rate (balance),
56
+ Catch::Matchers::WithinRel (want, 0.000001 ));
50
57
}
51
58
52
59
TEST_CASE (" Tiny third interest rate" , " [task_1]" ) {
53
60
double balance{5000.0001 };
54
61
double want{2.475 };
55
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
62
+ REQUIRE_THAT (interest_rate (balance),
63
+ Catch::Matchers::WithinRel (want, 0.000001 ));
56
64
}
57
65
58
66
TEST_CASE (" Large third interest rate" , " [task_1]" ) {
59
67
double balance{5639998.742909 };
60
68
double want{2.475 };
61
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
69
+ REQUIRE_THAT (interest_rate (balance),
70
+ Catch::Matchers::WithinRel (want, 0.000001 ));
62
71
}
63
72
64
73
TEST_CASE (" Rate on minimal negative balance" , " [task_1]" ) {
65
74
double balance{-0.000001 };
66
75
double want{3.213 };
67
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
76
+ REQUIRE_THAT (interest_rate (balance),
77
+ Catch::Matchers::WithinRel (want, 0.000001 ));
68
78
}
69
79
70
80
TEST_CASE (" Rate on small negative balance" , " [task_1]" ) {
71
81
double balance{-0.123 };
72
82
double want{3.213 };
73
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
83
+ REQUIRE_THAT (interest_rate (balance),
84
+ Catch::Matchers::WithinRel (want, 0.000001 ));
74
85
}
75
86
76
87
TEST_CASE (" Rate on regular negative balance" , " [task_1]" ) {
77
88
double balance{-300.0 };
78
89
double want{3.213 };
79
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
90
+ REQUIRE_THAT (interest_rate (balance),
91
+ Catch::Matchers::WithinRel (want, 0.000001 ));
80
92
}
81
93
82
94
TEST_CASE (" Rate on large negative balance" , " [task_1]" ) {
83
95
double balance{-152964.231 };
84
96
double want{3.213 };
85
- REQUIRE_THAT (interest_rate (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
97
+ REQUIRE_THAT (interest_rate (balance),
98
+ Catch::Matchers::WithinRel (want, 0.000001 ));
86
99
}
87
100
88
101
TEST_CASE (" Interest on negative balance" , " [task_2]" ) {
89
102
double balance{-10000.0 };
90
103
double want{-321.3 };
91
- REQUIRE_THAT (yearly_interest (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
104
+ REQUIRE_THAT (yearly_interest (balance),
105
+ Catch::Matchers::WithinRel (want, 0.000001 ));
92
106
}
93
107
TEST_CASE (" Interest on small balance" , " [task_2]" ) {
94
108
double balance{555.43 };
95
109
double want{2.77715 };
96
- REQUIRE_THAT (yearly_interest (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
110
+ REQUIRE_THAT (yearly_interest (balance),
111
+ Catch::Matchers::WithinRel (want, 0.000001 ));
97
112
}
98
113
TEST_CASE (" Interest on medium balance" , " [task_2]" ) {
99
114
double balance{4999.99 };
100
115
double want{81.0498379 };
101
- REQUIRE_THAT (yearly_interest (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
116
+ REQUIRE_THAT (yearly_interest (balance),
117
+ Catch::Matchers::WithinRel (want, 0.000001 ));
102
118
}
103
119
TEST_CASE (" Interest on large balance" , " [task_2]" ) {
104
120
double balance{34600.80 };
105
121
double want{856.3698 };
106
- REQUIRE_THAT (yearly_interest (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
122
+ REQUIRE_THAT (yearly_interest (balance),
123
+ Catch::Matchers::WithinRel (want, 0.000001 ));
107
124
}
108
125
109
126
TEST_CASE (" Annual balance update for empty start balance" , " [task_3]" ) {
110
127
double balance{0.0 };
111
128
double want{0.0000 };
112
- REQUIRE_THAT (annual_balance_update (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
129
+ REQUIRE_THAT (annual_balance_update (balance),
130
+ Catch::Matchers::WithinRel (want, 0.000001 ));
113
131
}
114
132
115
- TEST_CASE (" Annual balance update for small positive start balance" , " [task_3]" ) {
133
+ TEST_CASE (" Annual balance update for small positive start balance" ,
134
+ " [task_3]" ) {
116
135
double balance{0.000001 };
117
136
double want{0.000001005 };
118
- REQUIRE_THAT (annual_balance_update (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
137
+ REQUIRE_THAT (annual_balance_update (balance),
138
+ Catch::Matchers::WithinRel (want, 0.000001 ));
119
139
}
120
140
121
- TEST_CASE (" Annual balance update for average positive start balance" , " [task_3]" ) {
141
+ TEST_CASE (" Annual balance update for average positive start balance" ,
142
+ " [task_3]" ) {
122
143
double balance{1000.0 };
123
144
double want{1016.210000 };
124
- REQUIRE_THAT (annual_balance_update (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
145
+ REQUIRE_THAT (annual_balance_update (balance),
146
+ Catch::Matchers::WithinRel (want, 0.000001 ));
125
147
}
126
148
127
- TEST_CASE (" Annual balance update for large positive start balance" , " [task_3]" ) {
149
+ TEST_CASE (" Annual balance update for large positive start balance" ,
150
+ " [task_3]" ) {
128
151
double balance{1000.2001 };
129
152
double want{1016.413343621 };
130
- REQUIRE_THAT (annual_balance_update (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
153
+ REQUIRE_THAT (annual_balance_update (balance),
154
+ Catch::Matchers::WithinRel (want, 0.000001 ));
131
155
}
132
156
133
157
TEST_CASE (" Annual balance update for huge positive start balance" , " [task_3]" ) {
134
158
double balance{898124017.826243404425 };
135
159
double want{920352587.2674429417 };
136
- REQUIRE_THAT (annual_balance_update (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
160
+ REQUIRE_THAT (annual_balance_update (balance),
161
+ Catch::Matchers::WithinRel (want, 0.000001 ));
137
162
}
138
163
139
- TEST_CASE (" Annual balance update for small negative start balance" , " [task_3]" ) {
164
+ TEST_CASE (" Annual balance update for small negative start balance" ,
165
+ " [task_3]" ) {
140
166
double balance{-0.123 };
141
167
double want{-0.12695199 };
142
- REQUIRE_THAT (annual_balance_update (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
168
+ REQUIRE_THAT (annual_balance_update (balance),
169
+ Catch::Matchers::WithinRel (want, 0.000001 ));
143
170
}
144
171
145
- TEST_CASE (" Annual balance update for large negative start balance" , " [task_3]" ) {
172
+ TEST_CASE (" Annual balance update for large negative start balance" ,
173
+ " [task_3]" ) {
146
174
double balance{-152964.231 };
147
175
double want{-157878.97174203 };
148
- REQUIRE_THAT (annual_balance_update (balance), Catch::Matchers::WithinRel (want, 0.000001 ));
176
+ REQUIRE_THAT (annual_balance_update (balance),
177
+ Catch::Matchers::WithinRel (want, 0.000001 ));
149
178
}
150
179
151
180
TEST_CASE (" Years before desired balance for small start balance" , " [task_4]" ) {
@@ -154,7 +183,8 @@ TEST_CASE("Years before desired balance for small start balance", "[task_4]") {
154
183
int want{47 };
155
184
REQUIRE (years_until_desired_balance (balance, target_balance) == want);
156
185
}
157
- TEST_CASE (" Years before desired balance for average start balance" , " [task_4]" ) {
186
+ TEST_CASE (" Years before desired balance for average start balance" ,
187
+ " [task_4]" ) {
158
188
double balance{1000.0 };
159
189
double target_balance{1100.0 };
160
190
int want{6 };
@@ -166,7 +196,8 @@ TEST_CASE("Years before desired balance for large start balance", "[task_4]") {
166
196
int want{5 };
167
197
REQUIRE (years_until_desired_balance (balance, target_balance) == want);
168
198
}
169
- TEST_CASE (" Years before large difference between start and target balance" , " [task_4]" ) {
199
+ TEST_CASE (" Years before large difference between start and target balance" ,
200
+ " [task_4]" ) {
170
201
double balance{2345.67 };
171
202
double target_balance{12345.6789 };
172
203
int want{85 };
0 commit comments