Skip to content

Commit d534fd7

Browse files
committed
Added unit test.
1 parent d80eb5c commit d534fd7

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package mesh.creator.primitives;
2+
3+
import static org.junit.Assert.assertArrayEquals;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
8+
import org.junit.Test;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.params.ParameterizedTest;
11+
import org.junit.jupiter.params.provider.ValueSource;
12+
13+
import math.Vector3f;
14+
import mesh.Mesh3D;
15+
import mesh.creator.IMeshCreator;
16+
17+
public class CubeCreatorTest {
18+
19+
private CubeCreator creator;
20+
21+
@BeforeEach
22+
public void setUp() {
23+
creator = new CubeCreator();
24+
}
25+
26+
@Test
27+
public void testImplementsMeshCreatorInterface() {
28+
assertTrue(creator instanceof IMeshCreator);
29+
}
30+
31+
@Test
32+
public void testCreatedMeshIsNotNull() {
33+
assertNotNull(creator.create());
34+
}
35+
36+
@Test
37+
public void testDefaultRadius() {
38+
assertEquals(1, creator.getRadius());
39+
}
40+
41+
@Test
42+
public void testGetSetRadius() {
43+
float expectedRadius = 0.345f;
44+
creator.setRadius(expectedRadius);
45+
assertEquals(expectedRadius, creator.getRadius());
46+
}
47+
48+
@Test
49+
public void testFaceCount() {
50+
assertEquals(6, creator.create().getFaceCount());
51+
}
52+
53+
@Test
54+
public void testVertexCount() {
55+
assertEquals(8, creator.create().getVertexCount());
56+
}
57+
58+
@Test
59+
public void testFace0() {
60+
int[] expected = new int[] { 3, 0, 1, 2 };
61+
int[] actual = creator.create().getFaceAt(0).indices;
62+
assertArrayEquals(expected, actual);
63+
}
64+
65+
@Test
66+
public void testFace1() {
67+
int[] expected = new int[] { 6, 5, 4, 7 };
68+
int[] actual = creator.create().getFaceAt(1).indices;
69+
assertArrayEquals(expected, actual);
70+
}
71+
72+
@Test
73+
public void testFace2() {
74+
int[] expected = new int[] { 1, 0, 4, 5 };
75+
int[] actual = creator.create().getFaceAt(2).indices;
76+
assertArrayEquals(expected, actual);
77+
}
78+
79+
@Test
80+
public void testFace3() {
81+
int[] expected = new int[] { 1, 5, 6, 2 };
82+
int[] actual = creator.create().getFaceAt(3).indices;
83+
assertArrayEquals(expected, actual);
84+
}
85+
86+
@Test
87+
public void testFace4() {
88+
int[] expected = new int[] { 6, 7, 3, 2 };
89+
int[] actual = creator.create().getFaceAt(4).indices;
90+
assertArrayEquals(expected, actual);
91+
}
92+
93+
@Test
94+
public void testFace5() {
95+
int[] expected = new int[] { 3, 7, 4, 0 };
96+
int[] actual = creator.create().getFaceAt(5).indices;
97+
assertArrayEquals(expected, actual);
98+
}
99+
100+
@Test
101+
public void testDefaultVertices() {
102+
Vector3f[] expected = new Vector3f[] {
103+
new Vector3f(+1, -1, -1),
104+
new Vector3f(+1, -1, +1),
105+
new Vector3f(-1, -1, +1),
106+
new Vector3f(-1, -1, -1),
107+
new Vector3f(+1, +1, -1),
108+
new Vector3f(+1, +1, +1),
109+
new Vector3f(-1, +1, +1),
110+
new Vector3f(-1, +1, -1),
111+
};
112+
Mesh3D cube = creator.create();
113+
for (int i = 0; i < 8; i++) {
114+
Vector3f expectedVertex = expected[i];
115+
Vector3f actualVertex = cube.getVertexAt(i);
116+
assertEquals(actualVertex, expectedVertex);
117+
}
118+
}
119+
120+
@ParameterizedTest
121+
@ValueSource(floats = {
122+
1,
123+
42.44f,
124+
245.2444f,
125+
14332.21f,
126+
1342.02f,
127+
43.f,
128+
Float.MIN_VALUE,
129+
Float.MAX_VALUE
130+
})
131+
public void testVerticesDifferentRadii(float radius) {
132+
Vector3f[] expected = new Vector3f[] {
133+
new Vector3f(+radius, -radius, -radius),
134+
new Vector3f(+radius, -radius, +radius),
135+
new Vector3f(-radius, -radius, +radius),
136+
new Vector3f(-radius, -radius, -radius),
137+
new Vector3f(+radius, +radius, -radius),
138+
new Vector3f(+radius, +radius, +radius),
139+
new Vector3f(-radius, +radius, +radius),
140+
new Vector3f(-radius, +radius, -radius),
141+
};
142+
creator.setRadius(radius);
143+
Mesh3D cube = creator.create();
144+
for (int i = 0; i < 8; i++) {
145+
Vector3f expectedVertex = expected[i];
146+
Vector3f actualVertex = cube.getVertexAt(i);
147+
assertEquals(actualVertex, expectedVertex);
148+
}
149+
}
150+
151+
}

0 commit comments

Comments
 (0)