Skip to content

Commit 03d6f52

Browse files
committed
2 parents 741ecb3 + 0703ea1 commit 03d6f52

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
</repository>
3333
</distributionManagement>
3434
<dependencies>
35+
<dependency>
36+
<groupId>org.junit.jupiter</groupId>
37+
<artifactId>junit-jupiter-params</artifactId>
38+
<version>5.10.0</version>
39+
<scope>test</scope>
40+
</dependency>
3541
<dependency>
3642
<groupId>org.processing</groupId>
3743
<artifactId>core</artifactId>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package mesh.creator.archimedian;
2+
3+
import static org.junit.Assert.assertArrayEquals;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
6+
import org.junit.Test;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.ValueSource;
9+
10+
public class ArchimedianSolidEnumTest {
11+
12+
/**
13+
* Verifies that the `ArchimedianSolid` enum contains the expected number of
14+
* solids. This test ensures that all (and only) 13 known Archimedean solids
15+
* are represented.
16+
*/
17+
@Test
18+
public void verifiesExpectedNumberOfArchimedeanSolids() {
19+
assertEquals(13, ArchimedianSolid.values().length);
20+
}
21+
22+
/**
23+
* This test verifies the correct order of Archimedean solids after the
24+
* removal of explicit indices from the enum. Maintaining the correct order
25+
* is crucial for algorithms that already rely on the sequential nature of
26+
* the enum values.
27+
*/
28+
@Test
29+
public void testArchimedeanSolidEnumOrder() {
30+
ArchimedianSolid[] expected = new ArchimedianSolid[] {
31+
ArchimedianSolid.ICOSIDODECAHEDRON,
32+
ArchimedianSolid.TRUNCATED_CUBOCTAHEDRON,
33+
ArchimedianSolid.TRUNCATED_ICOSIDODECAHEDRON,
34+
ArchimedianSolid.CUBOCTAHEDRON,
35+
ArchimedianSolid.RHOMBICUBOCTAHEDRON,
36+
ArchimedianSolid.SNUB_CUBE,
37+
ArchimedianSolid.RHOMBISOSIDODECAHEDRON,
38+
ArchimedianSolid.SNUB_DODECAHEDRON,
39+
ArchimedianSolid.TRUNCATED_TETRAHEDRON,
40+
ArchimedianSolid.TRUNCATED_OCTAHEDRON,
41+
ArchimedianSolid.TRUNCATED_CUBE,
42+
ArchimedianSolid.TRUNCATED_ICOSAHEDRON,
43+
ArchimedianSolid.TRUNCATED_DODECAHEDRON };
44+
ArchimedianSolid[] actual = ArchimedianSolid.values();
45+
assertArrayEquals(expected, actual);
46+
}
47+
48+
/**
49+
* Tests the `valueOf` method of the `ArchimedianSolid` enum to ensure it
50+
* correctly parses string representations into enum values.
51+
*
52+
* <pre>
53+
* While it might seem redundant, especially for simple enums, it's a good
54+
* practice to test the valueOf method for several reasons:
55+
*
56+
* 1. Ensures Correct Parsing:
57+
* It verifies that the valueOf method can correctly parse string
58+
* representations of enum values into their corresponding enum constants.
59+
*
60+
* 2. Catches Potential Errors: It helps identify potential issues with the
61+
* valueOf implementation, such as case sensitivity, typos, or incorrect
62+
* mappings.
63+
*
64+
* 3. Maintains Code Quality: It contributes to a comprehensive test suite,
65+
* ensuring the correctness of the enum and its associated methods.
66+
* However, the specific need for this test might depend on the complexity
67+
* of the enum and the criticality of its correct behavior in the
68+
* application.
69+
*
70+
* If the enum is simple and its values are unlikely to change,
71+
* you might consider omitting such tests.
72+
* Ultimately, the decision to include such tests should be based on a risk
73+
* assessment and the overall quality standards of the project.
74+
* </pre>
75+
*/
76+
@ParameterizedTest
77+
@ValueSource(strings = {
78+
"ICOSIDODECAHEDRON",
79+
"TRUNCATED_CUBOCTAHEDRON",
80+
"TRUNCATED_ICOSIDODECAHEDRON",
81+
"CUBOCTAHEDRON",
82+
"RHOMBICUBOCTAHEDRON",
83+
"SNUB_CUBE",
84+
"RHOMBISOSIDODECAHEDRON",
85+
"SNUB_DODECAHEDRON",
86+
"TRUNCATED_TETRAHEDRON",
87+
"TRUNCATED_OCTAHEDRON",
88+
"TRUNCATED_CUBE",
89+
"TRUNCATED_ICOSAHEDRON",
90+
"TRUNCATED_DODECAHEDRON"
91+
})
92+
public void testValueOfMethod(String solidName) {
93+
ArchimedianSolid expectedSolid = ArchimedianSolid.valueOf(solidName);
94+
assertEquals(expectedSolid, ArchimedianSolid.valueOf(solidName));
95+
}
96+
97+
}

0 commit comments

Comments
 (0)