Building / Fixed some tests
This commit is contained in:
@@ -37,8 +37,8 @@ public class DirectConsumerTests extends PowerTestFixture{
|
||||
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);
|
||||
consumerTile.entity.items().add(Items.silicon, siliconAmount);
|
||||
consumerTile.entity.items().add(Items.lead, leadAmount);
|
||||
|
||||
Tile producerTile = createFakeTile(2, 0, createFakeProducerBlock(producedPower));
|
||||
producerTile.<PowerGenerator.GeneratorEntity>ent().productionEfficiency = 1f;
|
||||
@@ -50,6 +50,6 @@ public class DirectConsumerTests extends PowerTestFixture{
|
||||
consumerTile.entity.update();
|
||||
graph.update();
|
||||
|
||||
assertEquals(expectedSatisfaction, consumertile.entity.power().status);
|
||||
assertEquals(expectedSatisfaction, consumerTile.entity.power().status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package power;
|
||||
|
||||
import arc.*;
|
||||
import arc.mock.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
@@ -14,7 +15,7 @@ import org.junit.jupiter.api.*;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
/**
|
||||
* This class provides objects commonly used by power related unit tests.
|
||||
@@ -26,8 +27,11 @@ public class PowerTestFixture{
|
||||
|
||||
@BeforeAll
|
||||
static void initializeDependencies(){
|
||||
headless = true;
|
||||
Core.graphics = new FakeGraphics();
|
||||
Core.files = new MockFiles();
|
||||
Vars.state = new GameState();
|
||||
Vars.tree = new FileTree();
|
||||
Vars.content = new ContentLoader(){
|
||||
@Override
|
||||
public void handleMappableContent(MappableContent content){
|
||||
@@ -87,11 +91,11 @@ public class PowerTestFixture{
|
||||
|
||||
// Simulate the "changed" method. Calling it through reflections would require half the game to be initialized.
|
||||
tile.entity = block.newEntity().init(tile, false);
|
||||
tile.entity.cons() = new ConsumeModule(tile.entity);
|
||||
if(block.hasItems) tile.entity.items() = new ItemModule();
|
||||
if(block.hasLiquids) tile.entity.liquids() = new LiquidModule();
|
||||
tile.entity.cons(new ConsumeModule(tile.entity));
|
||||
if(block.hasItems) tile.entity.items(new ItemModule());
|
||||
if(block.hasLiquids) tile.entity.liquids(new LiquidModule());
|
||||
if(block.hasPower){
|
||||
tile.entity.power() = new PowerModule();
|
||||
tile.entity.power(new PowerModule());
|
||||
tile.entity.power().graph = new PowerGraph(){
|
||||
//assume there's always something consuming power
|
||||
@Override
|
||||
@@ -104,7 +108,7 @@ public class PowerTestFixture{
|
||||
|
||||
// Assign incredibly high health so the block does not get destroyed on e.g. burning Blast Compound
|
||||
block.health = 100000;
|
||||
tile.entity.health = 100000.0f;
|
||||
tile.entity.health(100000.0f);
|
||||
|
||||
return tile;
|
||||
}catch(Exception ex){
|
||||
|
||||
@@ -66,7 +66,7 @@ public class PowerTests extends PowerTestFixture{
|
||||
|
||||
// Update and check for the expected power status of the consumer
|
||||
powerGraph.update();
|
||||
assertEquals(expectedSatisfaction, directConsumertile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
assertEquals(expectedSatisfaction, directConsumerTile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,14 +104,14 @@ public class PowerTests extends PowerTestFixture{
|
||||
}
|
||||
float maxCapacity = 100f;
|
||||
Tile batteryTile = createFakeTile(0, 2, createFakeBattery(maxCapacity));
|
||||
batterytile.entity.power().status = initialBatteryCapacity / maxCapacity;
|
||||
batteryTile.entity.power().status = initialBatteryCapacity / maxCapacity;
|
||||
|
||||
powerGraph.add(batteryTile);
|
||||
|
||||
powerGraph.update();
|
||||
assertEquals(expectedBatteryCapacity / maxCapacity, batterytile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery status did not match");
|
||||
assertEquals(expectedBatteryCapacity / maxCapacity, batteryTile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery status did not match");
|
||||
if(directConsumerTile != null){
|
||||
assertEquals(expectedSatisfaction, directConsumertile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
assertEquals(expectedSatisfaction, directConsumerTile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,13 +127,13 @@ public class PowerTests extends PowerTestFixture{
|
||||
powerGraph.add(consumerTile);
|
||||
powerGraph.update();
|
||||
|
||||
assertEquals(1.0f, consumertile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
assertEquals(1.0f, consumerTile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
|
||||
powerGraph.remove(producerTile);
|
||||
powerGraph.add(consumerTile);
|
||||
powerGraph.update();
|
||||
|
||||
assertEquals(0.0f, consumertile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
assertEquals(0.0f, consumerTile.entity.power().status, Mathf.FLOAT_ROUNDING_ERROR);
|
||||
if(consumerTile.block().consumes.hasPower()){
|
||||
ConsumePower consumePower = consumerTile.block().consumes.getPower();
|
||||
assertFalse(consumePower.valid(consumerTile.ent()));
|
||||
|
||||
Reference in New Issue
Block a user