-
Notifications
You must be signed in to change notification settings - Fork 755
/
CompatibleStatTest.java
121 lines (99 loc) · 5.39 KB
/
CompatibleStatTest.java
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
package slimeknights.tconstruct.library.tools.stat;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import slimeknights.tconstruct.fixture.MaterialItemFixture;
import slimeknights.tconstruct.fixture.MaterialStatsFixture;
import slimeknights.tconstruct.library.materials.MaterialRegistryExtension;
import slimeknights.tconstruct.library.materials.definition.IMaterial;
import slimeknights.tconstruct.library.materials.stats.IMaterialStats;
import slimeknights.tconstruct.library.materials.stats.MaterialStatsId;
import slimeknights.tconstruct.library.tools.definition.module.material.MaterialStatsModule.WeightedStatType;
import slimeknights.tconstruct.library.tools.nbt.MaterialNBT;
import slimeknights.tconstruct.test.BaseMcTest;
import slimeknights.tconstruct.tools.stats.ExtraMaterialStats;
import slimeknights.tconstruct.tools.stats.HandleMaterialStats;
import slimeknights.tconstruct.tools.stats.HeadMaterialStats;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static slimeknights.tconstruct.fixture.MaterialFixture.MATERIAL_WITH_ALL_STATS;
import static slimeknights.tconstruct.fixture.MaterialFixture.MATERIAL_WITH_EXTRA;
import static slimeknights.tconstruct.fixture.MaterialFixture.MATERIAL_WITH_HANDLE;
import static slimeknights.tconstruct.fixture.MaterialFixture.MATERIAL_WITH_HEAD;
@ExtendWith(MaterialRegistryExtension.class)
public class CompatibleStatTest extends BaseMcTest {
@BeforeAll
static void beforeAll() {
MaterialItemFixture.init();
}
record StatTypesWithMaterials(List<WeightedStatType> statTypes, MaterialNBT materials) {
/** Gets all stats of the given type */
public <T extends IMaterialStats> List<T> getStats(MaterialStatsId id) {
return MaterialStatProvider.listOfCompatibleWith(id, materials, statTypes);
}
/** Gets head material stats */
public List<HeadMaterialStats> getHeads() {
return getStats(HeadMaterialStats.ID);
}
/** Gets handle material stats */
public List<HandleMaterialStats> getHandles() {
return getStats(HandleMaterialStats.ID);
}
/** Gets extra material stats */
public List<ExtraMaterialStats> getExtras() {
return getStats(ExtraMaterialStats.ID);
}
}
/**
* Gets a builder for the given materials list, validating the size is correct
* @param materials List of materials
* @return Melee harvest tool stats builder
*/
static StatTypesWithMaterials withMaterials(IMaterial... materials) {
List<WeightedStatType> statTypes = List.of(new WeightedStatType(HeadMaterialStats.ID, 1), new WeightedStatType(HandleMaterialStats.ID, 1), new WeightedStatType(ExtraMaterialStats.ID, 1));
assertThat(materials).overridingErrorMessage("Given materials list is the wrong size").hasSize(statTypes.size());
return new StatTypesWithMaterials(statTypes, MaterialNBT.of(materials));
}
@Test
void init_onlyHead() {
StatTypesWithMaterials builder = withMaterials(MATERIAL_WITH_HEAD, MATERIAL_WITH_HEAD, MATERIAL_WITH_HEAD);
assertThat(builder.getHeads()).containsExactly(MaterialStatsFixture.MATERIAL_STATS_HEAD);
assertThat(builder.getHandles()).containsExactly(HandleMaterialStats.DEFAULT);
assertThat(builder.getExtras()).containsExactly(ExtraMaterialStats.DEFAULT);
}
@Test
void init_onlyHandle() {
StatTypesWithMaterials builder = withMaterials(MATERIAL_WITH_HANDLE, MATERIAL_WITH_HANDLE, MATERIAL_WITH_HANDLE);
assertThat(builder.getHeads()).containsExactly(HeadMaterialStats.DEFAULT);
assertThat(builder.getHandles()).containsExactly(MaterialStatsFixture.MATERIAL_STATS_HANDLE);
assertThat(builder.getExtras()).containsExactly(ExtraMaterialStats.DEFAULT);
}
@Test
void init_onlyExtra() {
StatTypesWithMaterials builder = withMaterials(MATERIAL_WITH_EXTRA, MATERIAL_WITH_EXTRA, MATERIAL_WITH_EXTRA);
assertThat(builder.getHeads()).containsExactly(HeadMaterialStats.DEFAULT);
assertThat(builder.getHandles()).containsExactly(HandleMaterialStats.DEFAULT);
assertThat(builder.getExtras()).containsExactly(MaterialStatsFixture.MATERIAL_STATS_EXTRA);
}
@Test
void init_allCorrectStats() {
StatTypesWithMaterials builder = withMaterials(MATERIAL_WITH_HEAD, MATERIAL_WITH_HANDLE, MATERIAL_WITH_EXTRA);
assertThat(builder.getHeads()).containsExactly(MaterialStatsFixture.MATERIAL_STATS_HEAD);
assertThat(builder.getHandles()).containsExactly(MaterialStatsFixture.MATERIAL_STATS_HANDLE);
assertThat(builder.getExtras()).containsExactly(MaterialStatsFixture.MATERIAL_STATS_EXTRA);
}
@Test
void init_wrongOrder() {
StatTypesWithMaterials builder = withMaterials(MATERIAL_WITH_HANDLE, MATERIAL_WITH_EXTRA, MATERIAL_WITH_HEAD);
assertThat(builder.getHeads()).containsExactly(HeadMaterialStats.DEFAULT);
assertThat(builder.getHandles()).containsExactly(HandleMaterialStats.DEFAULT);
assertThat(builder.getExtras()).containsExactly(ExtraMaterialStats.DEFAULT);
}
@Test
void init_singleMaterialAllStats() {
StatTypesWithMaterials builder = withMaterials(MATERIAL_WITH_ALL_STATS, MATERIAL_WITH_ALL_STATS, MATERIAL_WITH_ALL_STATS);
assertThat(builder.getHeads()).containsExactly(MaterialStatsFixture.MATERIAL_STATS_HEAD);
assertThat(builder.getHandles()).containsExactly(MaterialStatsFixture.MATERIAL_STATS_HANDLE);
assertThat(builder.getExtras()).containsExactly(MaterialStatsFixture.MATERIAL_STATS_EXTRA);
}
}