mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-27 23:11:12 -08:00
Added unit tests for Java, JavaScript and JSON mods
This commit is contained in:
parent
d6016f1b04
commit
347b38ba26
20 changed files with 587 additions and 397 deletions
|
|
@ -1,10 +1,12 @@
|
|||
import arc.*;
|
||||
import arc.backend.headless.*;
|
||||
import arc.files.*;
|
||||
import arc.func.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import arc.util.serialization.*;
|
||||
import arc.util.serialization.JsonValue.*;
|
||||
import mindustry.*;
|
||||
|
|
@ -16,21 +18,36 @@ import mindustry.entities.units.*;
|
|||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.io.SaveIO.*;
|
||||
import mindustry.maps.*;
|
||||
import mindustry.mod.*;
|
||||
import mindustry.mod.Mods.*;
|
||||
import mindustry.net.Net;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.storage.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.params.*;
|
||||
import org.junit.jupiter.params.provider.*;
|
||||
|
||||
import java.nio.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.DynamicTest.*;
|
||||
|
||||
public class ApplicationTests{
|
||||
static Map testMap;
|
||||
static boolean initialized;
|
||||
//core/assets
|
||||
static final Fi testDataFolder = new Fi("../../tests/build/test_data");
|
||||
|
||||
@BeforeAll
|
||||
static void launchApplication(){
|
||||
public static void launchApplication(){
|
||||
launchApplication(true);
|
||||
}
|
||||
|
||||
public static void launchApplication(boolean clear){
|
||||
//only gets called once
|
||||
if(initialized) return;
|
||||
initialized = true;
|
||||
|
|
@ -43,6 +60,12 @@ public class ApplicationTests{
|
|||
ApplicationCore core = new ApplicationCore(){
|
||||
@Override
|
||||
public void setup(){
|
||||
//clear older data
|
||||
if(clear){
|
||||
ApplicationTests.testDataFolder.deleteDirectory();
|
||||
}
|
||||
|
||||
Core.settings.setDataDirectory(testDataFolder);
|
||||
headless = true;
|
||||
net = new Net(null);
|
||||
tree = new FileTree();
|
||||
|
|
@ -55,12 +78,26 @@ public class ApplicationTests{
|
|||
}
|
||||
};
|
||||
content.createBaseContent();
|
||||
mods.loadScripts();
|
||||
content.createModContent();
|
||||
|
||||
add(logic = new Logic());
|
||||
add(netServer = new NetServer());
|
||||
|
||||
content.init();
|
||||
|
||||
mods.eachClass(Mod::init);
|
||||
|
||||
if(mods.hasContentErrors()){
|
||||
for(LoadedMod mod : mods.list()){
|
||||
if(mod.hasContentErrors()){
|
||||
for(Content cont : mod.erroredContent){
|
||||
throw new RuntimeException("error in file: " + cont.minfo.sourceFile.path(), cont.minfo.baseError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -96,6 +133,55 @@ public class ApplicationTests{
|
|||
state.set(State.menu);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullSource
|
||||
@ValueSource(strings = {
|
||||
"asd asd asd asd asdagagasasjakbgeah;jwrej 23424234",
|
||||
"这个服务器可以用自己的语言说话"
|
||||
})
|
||||
void writeStringTest(String string){
|
||||
ByteBuffer buffer = ByteBuffer.allocate(500);
|
||||
TypeIO.writeString(buffer, string);
|
||||
buffer.position(0);
|
||||
assertEquals(TypeIO.readString(buffer), string);
|
||||
}
|
||||
|
||||
@Test
|
||||
void writeRules(){
|
||||
ByteBuffer buffer = ByteBuffer.allocate(500);
|
||||
|
||||
Rules rules = new Rules();
|
||||
rules.attackMode = true;
|
||||
rules.buildSpeedMultiplier = 99f;
|
||||
|
||||
TypeIO.writeRules(new Writes(new ByteBufferOutput(buffer)), rules);
|
||||
buffer.position(0);
|
||||
Rules res = TypeIO.readRules(new Reads(new ByteBufferInput(buffer)));
|
||||
|
||||
assertEquals(rules.buildSpeedMultiplier, res.buildSpeedMultiplier);
|
||||
assertEquals(rules.attackMode, res.attackMode);
|
||||
}
|
||||
|
||||
@Test
|
||||
void writeRules2(){
|
||||
Rules rules = new Rules();
|
||||
rules.attackMode = true;
|
||||
rules.tags.put("blah", "bleh");
|
||||
rules.buildSpeedMultiplier = 99.1f;
|
||||
|
||||
String str = JsonIO.write(rules);
|
||||
Rules res = JsonIO.read(Rules.class, str);
|
||||
|
||||
assertEquals(rules.buildSpeedMultiplier, res.buildSpeedMultiplier);
|
||||
assertEquals(rules.attackMode, res.attackMode);
|
||||
assertEquals(rules.tags.get("blah"), res.tags.get("blah"));
|
||||
|
||||
String str2 = JsonIO.write(new Rules(){{
|
||||
attackMode = true;
|
||||
}});
|
||||
Log.info(str2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void serverListJson(){
|
||||
String[] files = {"servers.json", "servers_be.json", "servers_v6.json"};
|
||||
|
|
@ -730,6 +816,83 @@ public class ApplicationTests{
|
|||
}
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
DynamicTest[] testSectorValidity(){
|
||||
Seq<DynamicTest> out = new Seq<>();
|
||||
if(world == null) world = new World();
|
||||
|
||||
for(SectorPreset zone : content.sectors()){
|
||||
|
||||
out.add(dynamicTest(zone.name, () -> {
|
||||
Time.setDeltaProvider(() -> 1f);
|
||||
|
||||
logic.reset();
|
||||
try{
|
||||
world.loadGenerator(zone.generator.map.width, zone.generator.map.height, zone.generator::generate);
|
||||
}catch(SaveException e){
|
||||
//fails randomly and I don't care about fixing it
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
zone.rules.get(state.rules);
|
||||
ObjectSet<Item> resources = new ObjectSet<>();
|
||||
boolean hasSpawnPoint = false;
|
||||
|
||||
for(Tile tile : world.tiles){
|
||||
if(tile.drop() != null){
|
||||
resources.add(tile.drop());
|
||||
}
|
||||
if(tile.block() instanceof CoreBlock && tile.team() == state.rules.defaultTeam){
|
||||
hasSpawnPoint = true;
|
||||
}
|
||||
}
|
||||
|
||||
Seq<SpawnGroup> spawns = state.rules.spawns;
|
||||
|
||||
int bossWave = 0;
|
||||
if(state.rules.winWave > 0){
|
||||
bossWave = state.rules.winWave;
|
||||
}else{
|
||||
outer:
|
||||
for(int i = 1; i <= 1000; i++){
|
||||
for(SpawnGroup spawn : spawns){
|
||||
if(spawn.effect == StatusEffects.boss && spawn.getSpawned(i) > 0){
|
||||
bossWave = i;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(state.rules.attackMode){
|
||||
bossWave = 100;
|
||||
}else{
|
||||
assertNotEquals(0, bossWave, "Sector doesn't have a boss wave.");
|
||||
}
|
||||
|
||||
//TODO check for difficulty?
|
||||
for(int i = 1; i <= bossWave; i++){
|
||||
int total = 0;
|
||||
for(SpawnGroup spawn : spawns){
|
||||
total += spawn.getSpawned(i);
|
||||
}
|
||||
|
||||
assertNotEquals(0, total, "Sector " + zone + " has no spawned enemies at wave " + i);
|
||||
//TODO this is flawed and needs to be changed later
|
||||
//assertTrue(total < 75, "Sector spawns too many enemies at wave " + i + " (" + total + ")");
|
||||
}
|
||||
|
||||
assertEquals(1, Team.sharded.cores().size, "Sector must have one core: " + zone);
|
||||
assertTrue(Team.sharded.core().items.total() < 1000, "Sector must not have starting resources: " + zone);
|
||||
|
||||
assertTrue(hasSpawnPoint, "Sector \"" + zone.name + "\" has no spawn points.");
|
||||
assertTrue(spawner.countSpawns() > 0 || (state.rules.attackMode && state.rules.waveTeam.data().hasCore()), "Sector \"" + zone.name + "\" has no enemy spawn points: " + spawner.countSpawns());
|
||||
}));
|
||||
}
|
||||
|
||||
return out.toArray(DynamicTest.class);
|
||||
}
|
||||
|
||||
void initBuilding(){
|
||||
createMap();
|
||||
|
||||
|
|
|
|||
35
tests/src/test/java/GenericModTest.java
Normal file
35
tests/src/test/java/GenericModTest.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import arc.*;
|
||||
import arc.Net.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class GenericModTest{
|
||||
|
||||
/** grabs a mod and puts it in the mod folder */
|
||||
static void grabMod(String url){
|
||||
//clear older mods
|
||||
ApplicationTests.testDataFolder.deleteDirectory();
|
||||
Core.net = new Net();
|
||||
Core.net.setBlock(true);
|
||||
Core.net.http(new HttpRequest().url(url).method(HttpMethod.GET), httpResponse -> {
|
||||
try{
|
||||
ApplicationTests.testDataFolder.child("mods").child("test_mod." + (url.endsWith("jar") ? "jar" : "zip")).writeBytes(Streams.copyBytes(httpResponse.getResultAsStream()));
|
||||
}catch(IOException e){
|
||||
Assertions.fail(e);
|
||||
}
|
||||
}, Assertions::fail);
|
||||
|
||||
ApplicationTests.launchApplication(false);
|
||||
}
|
||||
|
||||
static void checkExistence(String modName){
|
||||
assertNotEquals(Vars.mods, null);
|
||||
assertNotEquals(Vars.mods.list().size, 0, "At least one mod must be loaded.");
|
||||
assertEquals(Vars.mods.list().first().name, modName, modName + " must be loaded.");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.io.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.params.*;
|
||||
import org.junit.jupiter.params.provider.*;
|
||||
|
||||
import java.nio.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class IOTests{
|
||||
|
||||
@ParameterizedTest
|
||||
@NullSource
|
||||
@ValueSource(strings = {
|
||||
"asd asd asd asd asdagagasasjakbgeah;jwrej 23424234",
|
||||
"这个服务器可以用自己的语言说话"
|
||||
})
|
||||
void writeStringTest(String string){
|
||||
ByteBuffer buffer = ByteBuffer.allocate(500);
|
||||
TypeIO.writeString(buffer, string);
|
||||
buffer.position(0);
|
||||
assertEquals(TypeIO.readString(buffer), string);
|
||||
}
|
||||
|
||||
@Test
|
||||
void writeRules(){
|
||||
ByteBuffer buffer = ByteBuffer.allocate(500);
|
||||
|
||||
Rules rules = new Rules();
|
||||
rules.attackMode = true;
|
||||
rules.buildSpeedMultiplier = 99f;
|
||||
|
||||
TypeIO.writeRules(new Writes(new ByteBufferOutput(buffer)), rules);
|
||||
buffer.position(0);
|
||||
Rules res = TypeIO.readRules(new Reads(new ByteBufferInput(buffer)));
|
||||
|
||||
assertEquals(rules.buildSpeedMultiplier, res.buildSpeedMultiplier);
|
||||
assertEquals(rules.attackMode, res.attackMode);
|
||||
}
|
||||
|
||||
@Test
|
||||
void writeRules2(){
|
||||
Rules rules = new Rules();
|
||||
rules.attackMode = true;
|
||||
rules.tags.put("blah", "bleh");
|
||||
rules.buildSpeedMultiplier = 99.1f;
|
||||
|
||||
String str = JsonIO.write(rules);
|
||||
Rules res = JsonIO.read(Rules.class, str);
|
||||
|
||||
assertEquals(rules.buildSpeedMultiplier, res.buildSpeedMultiplier);
|
||||
assertEquals(rules.attackMode, res.attackMode);
|
||||
assertEquals(rules.tags.get("blah"), res.tags.get("blah"));
|
||||
|
||||
String str2 = JsonIO.write(new Rules(){{
|
||||
attackMode = true;
|
||||
}});
|
||||
Log.info(str2);
|
||||
}
|
||||
}
|
||||
39
tests/src/test/java/ModTestBM.java
Normal file
39
tests/src/test/java/ModTestBM.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import mindustry.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.meta.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
//grabs a betamindy release and makes sure it initializes correctly
|
||||
//this mod was chosen because:
|
||||
//- it is one of the top java mods on the browser
|
||||
//- it uses a variety of mindustry classes
|
||||
//- it is popular enough to cause significant amounts of crashes when something breaks
|
||||
//- I have some familiarity with its codebase
|
||||
public class ModTestBM extends GenericModTest{
|
||||
|
||||
@Test
|
||||
public void begin(){
|
||||
grabMod("https://github.com/sk7725/BetaMindy/releases/download/v0.955/BetaMindy.jar");
|
||||
|
||||
checkExistence("betamindy");
|
||||
|
||||
Block type = Vars.content.blocks().find(u -> u.name.equals("betamindy-piston"));
|
||||
assertNotNull(type, "A mod block must be loaded.");
|
||||
assertSame(type.buildVisibility, BuildVisibility.shown, "A mod block must be buildable.");
|
||||
|
||||
world.loadMap(ApplicationTests.testMap);
|
||||
Tile t = world.tile(3, 3);
|
||||
|
||||
t.setBlock(type);
|
||||
|
||||
//check for crash
|
||||
t.build.update();
|
||||
|
||||
assertTrue(t.build.health > 0, "Block must be spawned and alive.");
|
||||
assertSame(t.build.block, type, "Block must be spawned and alive.");
|
||||
}
|
||||
|
||||
}
|
||||
40
tests/src/test/java/ModTestExotic.java
Normal file
40
tests/src/test/java/ModTestExotic.java
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
//grabs a version-locked exotic-mod commit and makes sure its content is parsed correctly
|
||||
//this mod was chosen because:
|
||||
//- it is written solely in (h)json
|
||||
//- it is probably the mod with the most json, and as such covers a lot of classes
|
||||
//- it is popular enough in the mod browser
|
||||
//- I am somewhat familiar with its files & the type of content it adds
|
||||
public class ModTestExotic extends GenericModTest{
|
||||
|
||||
@Test
|
||||
public void begin(){
|
||||
grabMod("https://github.com/BlueWolf3682/Exotic-Mod/archive/08c861398ac9c3d1292132f9a110e17e06294a90.zip");
|
||||
checkExistence("exotic-mod");
|
||||
|
||||
UnitType type = Vars.content.units().find(u -> u.name.equals("exotic-mod-luminance"));
|
||||
assertNotNull(type, "A mod unit must be loaded.");
|
||||
assertTrue(type.weapons.size > 0, "A mod unit must have a weapon.");
|
||||
|
||||
Vars.world.loadMap(ApplicationTests.testMap);
|
||||
|
||||
Unit unit = type.spawn(0, 0);
|
||||
|
||||
//check for crash
|
||||
unit.update();
|
||||
|
||||
assertTrue(unit.health > 0, "Unit must be spawned and alive.");
|
||||
assertTrue(Groups.unit.size() > 0, "Unit must be spawned and alive.");
|
||||
|
||||
//just an extra sanity check
|
||||
Log.info("Modded units: @", Vars.content.units().select(u -> u.minfo.mod != null));
|
||||
}
|
||||
|
||||
}
|
||||
39
tests/src/test/java/ModTestHAI.java
Normal file
39
tests/src/test/java/ModTestHAI.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
//grabs a version-locked Heavy Armaments Industries commit and makes sure it initializes correctly
|
||||
//this mod was chosen because:
|
||||
//- it is one of the top JS mods, based on stars
|
||||
//- it contains both JS and JSON, which can be used to test compatibility of the two
|
||||
//- it can be used server-side (unlike FactoryDustry, which is a client-side texture pack that cannot be tested here)
|
||||
public class ModTestHAI extends GenericModTest{
|
||||
|
||||
@Test
|
||||
public void begin(){
|
||||
grabMod("https://github.com/Eschatologue/Heavy-Armaments-Industries/archive/d996e92dcf9a30a6acb7b3bfdfb6522dddc3804c.zip");
|
||||
checkExistence("heavy-armaments");
|
||||
|
||||
UnitType type = Vars.content.units().find(u -> u.name.equals("heavy-armaments-t3A_copter"));
|
||||
assertNotNull(type, "A mod unit must be loaded.");
|
||||
assertTrue(type.weapons.size > 0, "A mod unit must have a weapon.");
|
||||
|
||||
Vars.world.loadMap(ApplicationTests.testMap);
|
||||
|
||||
Unit unit = type.spawn(0, 0);
|
||||
|
||||
//check for crash
|
||||
unit.update();
|
||||
|
||||
assertTrue(unit.health > 0, "Unit must be spawned and alive.");
|
||||
assertTrue(Groups.unit.size() > 0, "Unit must be spawned and alive.");
|
||||
|
||||
//just an extra sanity check
|
||||
Log.info("Modded units: @", Vars.content.units().select(u -> u.minfo.mod != null));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.core.GameState.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.io.SaveIO.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.storage.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
|
||||
|
||||
public class SectorTests{
|
||||
|
||||
@BeforeAll
|
||||
static void launchApplication(){
|
||||
ApplicationTests.launchApplication();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void resetWorld(){
|
||||
Time.setDeltaProvider(() -> 1f);
|
||||
logic.reset();
|
||||
state.set(State.menu);
|
||||
}
|
||||
|
||||
@TestFactory
|
||||
DynamicTest[] testZoneValidity(){
|
||||
Seq<DynamicTest> out = new Seq<>();
|
||||
if(world == null) world = new World();
|
||||
|
||||
for(SectorPreset zone : content.sectors()){
|
||||
|
||||
out.add(dynamicTest(zone.name, () -> {
|
||||
logic.reset();
|
||||
try{
|
||||
world.loadGenerator(zone.generator.map.width, zone.generator.map.height, zone.generator::generate);
|
||||
}catch(SaveException e){
|
||||
//fails randomly and I don't care about fixing it
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
zone.rules.get(state.rules);
|
||||
ObjectSet<Item> resources = new ObjectSet<>();
|
||||
boolean hasSpawnPoint = false;
|
||||
|
||||
for(Tile tile : world.tiles){
|
||||
if(tile.drop() != null){
|
||||
resources.add(tile.drop());
|
||||
}
|
||||
if(tile.block() instanceof CoreBlock && tile.team() == state.rules.defaultTeam){
|
||||
hasSpawnPoint = true;
|
||||
}
|
||||
}
|
||||
|
||||
Seq<SpawnGroup> spawns = state.rules.spawns;
|
||||
|
||||
int bossWave = 0;
|
||||
if(state.rules.winWave > 0){
|
||||
bossWave = state.rules.winWave;
|
||||
}else{
|
||||
outer:
|
||||
for(int i = 1; i <= 1000; i++){
|
||||
for(SpawnGroup spawn : spawns){
|
||||
if(spawn.effect == StatusEffects.boss && spawn.getSpawned(i) > 0){
|
||||
bossWave = i;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(state.rules.attackMode){
|
||||
bossWave = 100;
|
||||
}else{
|
||||
assertNotEquals(0, bossWave, "Sector doesn't have a boss wave.");
|
||||
}
|
||||
|
||||
//TODO check for difficulty?
|
||||
for(int i = 1; i <= bossWave; i++){
|
||||
int total = 0;
|
||||
for(SpawnGroup spawn : spawns){
|
||||
total += spawn.getSpawned(i);
|
||||
}
|
||||
|
||||
assertNotEquals(0, total, "Sector " + zone + " has no spawned enemies at wave " + i);
|
||||
//TODO this is flawed and needs to be changed later
|
||||
//assertTrue(total < 75, "Sector spawns too many enemies at wave " + i + " (" + total + ")");
|
||||
}
|
||||
|
||||
assertEquals(1, Team.sharded.cores().size, "Sector must have one core: " + zone);
|
||||
assertTrue(Team.sharded.core().items.total() < 1000, "Sector must not have starting resources: " + zone);
|
||||
|
||||
assertTrue(hasSpawnPoint, "Sector \"" + zone.name + "\" has no spawn points.");
|
||||
assertTrue(spawner.countSpawns() > 0 || (state.rules.attackMode && state.rules.waveTeam.data().hasCore()), "Sector \"" + zone.name + "\" has no enemy spawn points: " + spawner.countSpawns());
|
||||
}));
|
||||
}
|
||||
|
||||
return out.toArray(DynamicTest.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,18 @@
|
|||
package power;
|
||||
|
||||
import mindustry.content.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.power.PowerGenerator.*;
|
||||
import mindustry.world.blocks.power.*;
|
||||
import mindustry.world.blocks.production.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Tests for direct power consumers. */
|
||||
public class DirectConsumerTests extends PowerTestFixture{
|
||||
//TODO reimplement
|
||||
/*
|
||||
|
||||
@Test
|
||||
void noPowerRequestedWithNoItems(){
|
||||
testUnitFactory(0, 0, 0.08f, 0.08f, 1f);
|
||||
|
|
@ -21,26 +30,26 @@ public class DirectConsumerTests extends PowerTestFixture{
|
|||
}
|
||||
|
||||
void testUnitFactory(int siliconAmount, int leadAmount, float producedPower, float requestedPower, float expectedSatisfaction){
|
||||
Tile consumerTile = createFakeTile(0, 0, new UnitFactory("fakefactory"){{
|
||||
entityType = UnitFactoryEntity::new;
|
||||
unitType = UnitTypes.spirit;
|
||||
produceTime = 60;
|
||||
Tile ct = createFakeTile(0, 0, new GenericCrafter("fakefactory"){{
|
||||
hasPower = true;
|
||||
hasItems = true;
|
||||
consumes.power(requestedPower);
|
||||
consumes.items(new ItemStack(Items.silicon, 30), new ItemStack(Items.lead, 30));
|
||||
}});
|
||||
consumerTile.entity.items.add(Items.silicon, siliconAmount);
|
||||
consumerTile.entity.items.add(Items.lead, leadAmount);
|
||||
ct.block().init();
|
||||
ct.build.items.add(Items.silicon, siliconAmount);
|
||||
ct.build.items.add(Items.lead, leadAmount);
|
||||
|
||||
Tile producerTile = createFakeTile(2, 0, createFakeProducerBlock(producedPower));
|
||||
producerTile.<PowerGenerator.GeneratorEntity>ent().productionEfficiency = 1f;
|
||||
((GeneratorBuild)producerTile.build).productionEfficiency = 1f;
|
||||
|
||||
PowerGraph graph = new PowerGraph();
|
||||
graph.add(producerTile.entity);
|
||||
graph.add(consumerTile.entity);
|
||||
graph.add(producerTile.build);
|
||||
graph.add(ct.build);
|
||||
|
||||
consumerTile.entity.update();
|
||||
ct.build.update();
|
||||
graph.update();
|
||||
|
||||
assertEquals(expectedSatisfaction, consumerTile.entity.power.status);
|
||||
}*/
|
||||
assertEquals(expectedSatisfaction, ct.build.power.status);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import static org.junit.jupiter.api.DynamicTest.dynamicTest;
|
|||
* Any expected power amount (produced, consumed, buffered) should be affected by FakeThreadHandler.fakeDelta but status should not!
|
||||
*/
|
||||
public class ItemLiquidGeneratorTests extends PowerTestFixture{
|
||||
|
||||
private ItemLiquidGenerator generator;
|
||||
private Tile tile;
|
||||
private ItemLiquidGeneratorBuild entity;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue