diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2022-03-14 14:22:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 07:22:00 +0100 |
commit | b9de712dcfb935861059cb92a60c0d698cd302d4 (patch) | |
tree | 31604150a39489651071e15d52d72e07d8fbbd04 /src/test | |
parent | 34a94189cf413164d2364dad26325688bc8128e6 (diff) | |
download | GT5-Unofficial-b9de712dcfb935861059cb92a60c0d698cd302d4.tar.gz GT5-Unofficial-b9de712dcfb935861059cb92a60c0d698cd302d4.tar.bz2 GT5-Unofficial-b9de712dcfb935861059cb92a60c0d698cd302d4.zip |
pin comb type id instead of depending on array ordinal (#980)
* pin comb type id instead of depending on array ordinal
* fix up _NULL related problems
* fix out of bound
* make it private
* add some more test
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/gregtech/common/items/CombTypeTest.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/java/gregtech/common/items/CombTypeTest.java b/src/test/java/gregtech/common/items/CombTypeTest.java new file mode 100644 index 0000000000..0f55d0afd1 --- /dev/null +++ b/src/test/java/gregtech/common/items/CombTypeTest.java @@ -0,0 +1,43 @@ +package gregtech.common.items; + +import org.junit.jupiter.api.Test; + +import java.util.HashSet; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class CombTypeTest { + @Test + void noDuplicateID() { + Set<Integer> seen = new HashSet<>(); + for (CombType value : CombType.values()) { + assertTrue(seen.add(value.getId()), "Comb type must not have duplicate ID"); + } + } + + @Test + void noNegativeID() { + for (CombType value : CombType.values()) { + if (value == CombType._NULL) + assertTrue(value.getId() <= 0, "Comb type ID must be negative for _NULL"); + else + assertTrue(value.getId() >= 0, "Comb type ID must not be negative"); + } + } + + @Test + void invalidIDNotNull() { + assertEquals(CombType.valueOf(-2), CombType._NULL, "Invalid ID Lookup should result in _NULL"); + assertEquals(CombType.valueOf(Integer.MAX_VALUE), CombType._NULL, "Invalid ID Lookup should result in _NULL"); + } + + @Test + void validIDCorrectComb() { + for (CombType value : CombType.values()) { + if (value != CombType._NULL) + assertEquals(CombType.valueOf(value.getId()), value, "Valid ID Lookup should result in correct output"); + } + } +} |