Newer
Older
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
package complex;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.within;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* Test class for the complex class.
*/
class ComplexTest {
private static final float EPSILON = 0.000001F;
@BeforeAll
static void setUpBeforeClass() throws Exception {
// TODO: add message
}
@AfterAll
static void tearDownAfterClass() throws Exception {
// TODO: add message
}
@BeforeEach
void setUp() throws Exception {
// TODO: add message
}
@AfterEach
void tearDown() throws Exception {
// TODO: add message
}
@Test
void testGetterImaginary() {
float expected = 2.0F;
Complex z = new Complex(1.0F, 2.0f);
assertThat(z.getImaginaryPart()).as("problem on getter imaginary")
.isCloseTo(expected, within(EPSILON));
}
@Test
void testGetterReal() {
float expected = 1.0F;
Complex z = new Complex(1.0F, 2.0f);
assertThat(z.getRealPart()).as("problem on getter real")
.isCloseTo(expected, within(EPSILON));
}
@Test
void testSetterImaginary() {
float expected = 3.0F;
Complex z = new Complex();
z.setImaginaryPart(expected);
assertThat(z.getImaginaryPart()).as("problem on setter imaginary")
.isCloseTo(expected, within(EPSILON));
}
@Test
void testSetterReal() {
float expected = 3.0F;
Complex z = new Complex();
z.setRealPart(expected);
assertThat(z.getRealPart()).as("problem on setter real")
.isCloseTo(expected, within(EPSILON));
}
@Test
void testZeroTrue() {
Complex z = new Complex(0.0F, 0.0F);
assertThat(z.isZero()).as("problem with isZero on Zero Complex number")
.isTrue();
}
@Test
void testZeroFalse() {
Complex z = new Complex(1.0F, 1.0F);
assertThat(z.isZero()).as("problem with isZero on non Zero Complex number")
.isFalse();
}
@Test
void testSumReal() {
Complex z1 = new Complex(1.0F, 2.0F);
Complex z2 = new Complex(3.0F, 4.0F);
float expected = 1.0F + 3.0F;
Complex z = z1.sum(z2);
assertThat(z.getRealPart()).as("problem with real part of Sum")
.isCloseTo(expected, within(EPSILON));
}
@Test
void testSumImaginary() {
Complex z1 = new Complex(1.0F, 2.0F);
Complex z2 = new Complex(3.0F, 4.0F);
float expected = 2.0F + 4.0F;
Complex z = z1.sum(z2);
assertThat(z.getImaginaryPart()).as("problem with imaginary part of Sum")
.isCloseTo(expected, within(EPSILON));
}
@Test
void testProductReal() {
Complex z1 = new Complex(1.0F, 2.0F);
Complex z2 = new Complex(3.0F, 4.0F);
float expected = 1.0F * 3.0F - 2.0F * 4.0F;
Complex z = z1.product(z2);
assertThat(z.getRealPart()).as("problem with real part of Product")
.isCloseTo(expected, within(EPSILON));
}
@Test
void testProductImaginary() {
Complex z1 = new Complex(1.0F, 2.0F);
Complex z2 = new Complex(3.0F, 4.0F);
float expected = 1.0F * 4.0F + 2.0F * 3.0F;
Complex z = z1.product(z2);
assertThat(z.getImaginaryPart()).as("problem with imaginary part of Product")
.isCloseTo(expected, within(EPSILON));
}
@Test
final void testTimeoutInfinite() {
Complex.infinite();
fail("NYI");
}
}