|
|
@@ -9,13 +9,15 @@ public class ComplexNumberTest {
|
|
9
|
9
|
|
|
10
|
10
|
private static final double DOUBLE_EQUALITY_TOLERANCE = 1e-15;
|
|
11
|
11
|
|
|
12
|
|
- private void assertDoublesEqual(double d1, double d2) {
|
|
13
|
|
- assertEquals(d1, d2, DOUBLE_EQUALITY_TOLERANCE);
|
|
|
12
|
+ private void assertDoublesEqual(double d1, double d2, String numberPart) {
|
|
|
13
|
+ String errorMessage = "While testing " + numberPart + " part of number,";
|
|
|
14
|
+
|
|
|
15
|
+ assertEquals(errorMessage, d1, d2, DOUBLE_EQUALITY_TOLERANCE);
|
|
14
|
16
|
}
|
|
15
|
17
|
|
|
16
|
18
|
private void assertComplexNumbersEqual(ComplexNumber c1, ComplexNumber c2) {
|
|
17
|
|
- assertDoublesEqual(c1.getReal(), c2.getReal());
|
|
18
|
|
- assertDoublesEqual(c1.getImag(), c2.getImag());
|
|
|
19
|
+ assertDoublesEqual(c1.getReal(), c2.getReal(), "real");
|
|
|
20
|
+ assertDoublesEqual(c1.getImag(), c2.getImag(), "imaginary");
|
|
19
|
21
|
}
|
|
20
|
22
|
|
|
21
|
23
|
// Tests
|
|
|
@@ -128,7 +130,7 @@ public class ComplexNumberTest {
|
|
128
|
130
|
public void testAbsoluteValueOfPositivePurelyRealNumber() {
|
|
129
|
131
|
double expected = 5.0;
|
|
130
|
132
|
double actual = new ComplexNumber(5.0, 0).abs();
|
|
131
|
|
- assertDoublesEqual(expected, actual);
|
|
|
133
|
+ assertDoublesEqual(expected, actual, "real");
|
|
132
|
134
|
}
|
|
133
|
135
|
|
|
134
|
136
|
@Ignore("Remove to run test")
|
|
|
@@ -136,7 +138,7 @@ public class ComplexNumberTest {
|
|
136
|
138
|
public void testAbsoluteValueOfNegativePurelyRealNumber() {
|
|
137
|
139
|
double expected = 5.0;
|
|
138
|
140
|
double actual = new ComplexNumber(-5.0, 0).abs();
|
|
139
|
|
- assertDoublesEqual(expected, actual);
|
|
|
141
|
+ assertDoublesEqual(expected, actual, "real");
|
|
140
|
142
|
}
|
|
141
|
143
|
|
|
142
|
144
|
@Ignore("Remove to run test")
|
|
|
@@ -144,7 +146,7 @@ public class ComplexNumberTest {
|
|
144
|
146
|
public void testAbsoluteValueOfPurelyImaginaryNumberWithPositiveImaginaryPart() {
|
|
145
|
147
|
double expected = 5.0;
|
|
146
|
148
|
double actual = new ComplexNumber(0, 5.0).abs();
|
|
147
|
|
- assertDoublesEqual(expected, actual);
|
|
|
149
|
+ assertDoublesEqual(expected, actual, "real");
|
|
148
|
150
|
}
|
|
149
|
151
|
|
|
150
|
152
|
@Ignore("Remove to run test")
|
|
|
@@ -152,7 +154,7 @@ public class ComplexNumberTest {
|
|
152
|
154
|
public void testAbsoluteValueOfPurelyImaginaryNumberWithNegativeImaginaryPart() {
|
|
153
|
155
|
double expected = 5.0;
|
|
154
|
156
|
double actual = new ComplexNumber(0, -5.0).abs();
|
|
155
|
|
- assertDoublesEqual(expected, actual);
|
|
|
157
|
+ assertDoublesEqual(expected, actual, "real");
|
|
156
|
158
|
}
|
|
157
|
159
|
|
|
158
|
160
|
@Ignore("Remove to run test")
|
|
|
@@ -160,7 +162,7 @@ public class ComplexNumberTest {
|
|
160
|
162
|
public void testAbsoluteValueOfNumberWithRealAndImaginaryParts() {
|
|
161
|
163
|
double expected = 5.0;
|
|
162
|
164
|
double actual = new ComplexNumber(3.0, 4.0).abs();
|
|
163
|
|
- assertDoublesEqual(expected, actual);
|
|
|
165
|
+ assertDoublesEqual(expected, actual, "real");
|
|
164
|
166
|
}
|
|
165
|
167
|
|
|
166
|
168
|
@Ignore("Remove to run test")
|
|
|
@@ -192,7 +194,7 @@ public class ComplexNumberTest {
|
|
192
|
194
|
public void testRealPartOfPurelyRealNumber() {
|
|
193
|
195
|
double expected = 1.0;
|
|
194
|
196
|
double actual = new ComplexNumber(1.0, 0).getReal();
|
|
195
|
|
- assertDoublesEqual(expected, actual);
|
|
|
197
|
+ assertDoublesEqual(expected, actual, "real");
|
|
196
|
198
|
}
|
|
197
|
199
|
|
|
198
|
200
|
@Ignore("Remove to run test")
|
|
|
@@ -200,7 +202,7 @@ public class ComplexNumberTest {
|
|
200
|
202
|
public void testRealPartOfPurelyImaginaryNumber() {
|
|
201
|
203
|
double expected = 0.0;
|
|
202
|
204
|
double actual = new ComplexNumber(0, 1.0).getReal();
|
|
203
|
|
- assertDoublesEqual(expected, actual);
|
|
|
205
|
+ assertDoublesEqual(expected, actual, "real");
|
|
204
|
206
|
}
|
|
205
|
207
|
|
|
206
|
208
|
@Ignore("Remove to run test")
|
|
|
@@ -208,7 +210,7 @@ public class ComplexNumberTest {
|
|
208
|
210
|
public void testRealPartOfNumberWithRealAndImaginaryParts() {
|
|
209
|
211
|
double expected = 1.0;
|
|
210
|
212
|
double actual = new ComplexNumber(1.0, 2.0).getReal();
|
|
211
|
|
- assertDoublesEqual(expected, actual);
|
|
|
213
|
+ assertDoublesEqual(expected, actual, "real");
|
|
212
|
214
|
}
|
|
213
|
215
|
|
|
214
|
216
|
@Ignore("Remove to run test")
|
|
|
@@ -216,7 +218,7 @@ public class ComplexNumberTest {
|
|
216
|
218
|
public void testImaginaryPartOfPurelyRealNumber() {
|
|
217
|
219
|
double expected = 0.0;
|
|
218
|
220
|
double actual = new ComplexNumber(1.0, 0).getImag();
|
|
219
|
|
- assertDoublesEqual(expected, actual);
|
|
|
221
|
+ assertDoublesEqual(expected, actual, "imaginary");
|
|
220
|
222
|
}
|
|
221
|
223
|
|
|
222
|
224
|
@Ignore("Remove to run test")
|
|
|
@@ -224,7 +226,7 @@ public class ComplexNumberTest {
|
|
224
|
226
|
public void testImaginaryPartOfPurelyImaginaryNumber() {
|
|
225
|
227
|
double expected = 1.0;
|
|
226
|
228
|
double actual = new ComplexNumber(0, 1.0).getImag();
|
|
227
|
|
- assertDoublesEqual(expected, actual);
|
|
|
229
|
+ assertDoublesEqual(expected, actual, "imaginary");
|
|
228
|
230
|
}
|
|
229
|
231
|
|
|
230
|
232
|
@Ignore("Remove to run test")
|
|
|
@@ -232,7 +234,7 @@ public class ComplexNumberTest {
|
|
232
|
234
|
public void testImaginaryPartOfNumberWithRealAndImaginaryParts() {
|
|
233
|
235
|
double expected = 2.0;
|
|
234
|
236
|
double actual = new ComplexNumber(1.0, 2.0).getImag();
|
|
235
|
|
- assertDoublesEqual(expected, actual);
|
|
|
237
|
+ assertDoublesEqual(expected, actual, "imaginary");
|
|
236
|
238
|
}
|
|
237
|
239
|
|
|
238
|
240
|
@Ignore("Remove to run test")
|