-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
279 lines (255 loc) · 6.79 KB
/
main.cpp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#include <iostream>
#include <cmath>
#include "includes/complex_header.hpp"
bool start_tests();
bool test_1();
bool test_2();
bool test_3();
bool test_4();
bool test_5();
bool test_6();
bool test_7();
bool test_8();
bool test_9();
bool test_10();
bool test_11();
bool test_12();
bool test_13();
bool test_14();
bool test_15();
bool test_16();
bool test_17();
int main() {
bool tests_passed = start_tests();
if (tests_passed) {
std::cout << "All the tests have been successfully passed" << std::endl;
}
else {
std::cout << "Some tests have failed" << std::endl;
}
return 0;
}
bool test_1 () {
Complex_num tmp_f(4.573267, 15.712341);
Complex_num tmp_s(4.573267, 15.712341);
Complex_num tmp_t(4.573266, 15.712342);
if (!(tmp_f == tmp_s)) {
std::cout << "Test 1 has failed" << std::endl;
return false;
}
if (tmp_t == tmp_f) {
std::cout << "Test 1 has failed" << std::endl;
return false;
}
return true;
}
bool test_2 () {
Complex_num tmp_f(4.573267, 15.712341);
Complex_num tmp_s(4.573267, 15.712341);
Complex_num tmp_t(4.573266, 15.712342);
if (tmp_f != tmp_s) {
std::cout << "Test 2 has failed" << std::endl;
return false;
}
if (!(tmp_f != tmp_t)) {
std::cout << "Test 2 has failed" << std::endl;
return false;
}
return true;
}
bool test_3 () {
Complex_num tmp_f(4.5, 7.3);
Complex_num tmp_s(4.5, 15.5);
Complex_num res = tmp_f + tmp_s;
if (fabs(res.real_part - 9) > 1e-9) {
std::cout << "Test 3 has failed" << std::endl;
return false;
}
if (fabs(res.imag_part - 22.8) > 1e-9) {
std::cout << "Test 3 has failed" << std::endl;
return false;
}
return true;
}
bool test_4 () {
Complex_num tmp_f(4.57, 15.71);
Complex_num tmp_s(4.57, 15.71);
Complex_num res = tmp_f - tmp_s;
if (fabs(res.real_part) > 1e-9) {
std::cout << "Test 4 has failed" << std::endl;
return false;
}
if (fabs(res.imag_part) > 1e-9) {
std::cout << "Test 4 has failed" << std::endl;
return false;
}
return true;
}
bool test_5 () {
Complex_num tmp_f(4.0, 10.0);
Complex_num tmp_s(4.5, 5.0);
Complex_num res = tmp_f * tmp_s;
if (fabs(res.real_part + 32.0) > 1e-9) {
std::cout << "Test 5 has failed" << std::endl;
return false;
}
if (fabs(res.imag_part - 65.0) > 1e-9) {
std::cout << "Test 5 has failed" << std::endl;
return false;
}
return true;
}
bool test_6 () {
Complex_num tmp_f(1.2, 3.5);
Complex_num tmp_s = -tmp_f;
if (fabs(tmp_s.real_part + 1.2) > 1e-9 && fabs(tmp_s.imag_part + 3.5) > 1e-9) {
std::cout << "Test 6 has failed" << std::endl;
return false;
}
return true;
}
bool test_7 () {
Complex_num tmp_f(4.0, 10.0);
tmp_f = tmp_f * 0.5;
if (fabs(tmp_f.real_part - 2.0) > 1e-9) {
return false;
}
if (fabs(tmp_f.imag_part - 5.0) > 1e-9) {
return false;
}
return true;
}
bool test_8 () {
Complex_num tmp_f(2.6, 4.2);
tmp_f = tmp_f / (2.0 / 3.0);
if (fabs(tmp_f.real_part - 3.9) > 1e-9) {
std::cout << "Test 8 has failed" << std::endl;
return false;
}
if (fabs(tmp_f.imag_part - 6.3) > 1e-9) {
std::cout << "Test 8 has failed" << std::endl;
return false;
}
return true;
}
bool test_9 () {
Complex_num tmp_f(2.6, 4.2);
Complex_num tmp_s(1.4, 11.3);
tmp_f += tmp_s;
if (fabs(tmp_f.real_part - 4.0) > 1e-9) {
std::cout << "Test 9 has failed" << std::endl;
return false;
}
if (fabs(tmp_f.imag_part - 15.5) > 1e-9) {
std::cout << "Test 9 has failed" << std::endl;
return false;
}
return true;
}
bool test_10 () {
Complex_num tmp_f(2.6, 4.2);
Complex_num tmp_s(1.4, 11.3);
tmp_f -= tmp_s;
if (fabs(tmp_f.real_part - 1.2) > 1e-9) {
std::cout << "Test 10 has failed" << std::endl;
return false;
}
if (fabs(tmp_f.imag_part + 7.1) > 1e-9) {
std::cout << "Test 10 has failed" << std::endl;
return false;
}
return true;
}
bool test_11 () {
Complex_num tmp_f(2.0, 4.0);
Complex_num tmp_s(3.0, 5.0);
tmp_f *= tmp_s;
if (fabs(tmp_f.real_part + 14.0) > 1e-9) {
std::cout << "Test 12 has failed" << std::endl;
return false;
}
if (fabs(tmp_f.imag_part - 22.0) > 1e-9) {
std::cout << "Test 12 has failed" << std::endl;
return false;
}
return true;
}
bool test_12 () {
Complex_num tmp_f(2.0, 4.0);
tmp_f /= 0.5;
if (fabs(tmp_f.real_part - 4) > 1e-9) {
std::cout << "Test 13 has failed" << std::endl;
return false;
}
if (fabs(tmp_f.imag_part - 8) > 1e-9) {
std::cout << "Test 13 has failed" << std::endl;
return false;
}
return true;
}
bool test_13 () {
Complex_num tmp_f(3.0, 4.0);
if (fabs(tmp_f.complex_module() - 5.0) > 1e-9) {
std::cout << "Test 13 has failed" << std::endl;
return false;
}
return true;
}
bool test_14 () {
Complex_num tmp_f(2.5, 3.5);
Complex_num tmp_s;
tmp_s = tmp_f;
if (abs(tmp_s.real_part - 2.5) > 1e-9 || abs(tmp_s.imag_part - 3.5) > 1e-9) {
std::cout << "Test 14 has failed" << std::endl;
return false;
}
return true;
}
bool test_15 () {
Complex_num tmp(2.5, 3.5);
tmp = 2.5 + tmp;
if (abs(tmp.real_part - 5) > 1e-9) {
std::cout << "Test 15 has failed" << std::endl;
return false;
}
return true;
}
bool test_16 () {
Complex_num tmp(2.5, 3.5);
tmp = 2.5 - tmp;
if (abs(tmp.real_part) > 1e-9) {
std::cout << "Test 16 has failed" << std::endl;
return false;
}
return true;
}
bool test_17 () {
Complex_num tmp(2.5, 3.5);
tmp = 2.0 * tmp;
if (abs(tmp.real_part - 5) > 1e-9) {
std::cout << "Test 17 has failed" << std::endl;
return false;
}
return true;
}
bool start_tests() {
bool result = true;
result = result && test_1();
result = result && test_2();
result = result && test_3();
result = result && test_4();
result = result && test_5();
result = result && test_6();
result = result && test_7();
result = result && test_8();
result = result && test_9();
result = result && test_10();
result = result && test_11();
result = result && test_12();
result = result && test_13();
result = result && test_14();
result = result && test_15();
result = result && test_16();
result = result && test_17();
return result;
}