mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-05 13:08:20 +07:00
More Tests and fixes
- Batteries will now get charged with no consumers - Fixed stat display of power generators
This commit is contained in:
parent
99139dfcca
commit
77b9feb765
@ -22,7 +22,7 @@ public class PowerGenerator extends PowerDistributor{
|
|||||||
@Override
|
@Override
|
||||||
public void setStats(){
|
public void setStats(){
|
||||||
super.setStats();
|
super.setStats();
|
||||||
stats.add(generationType, powerProduction, StatUnit.powerSecond);
|
stats.add(generationType, powerProduction * 60.0f, StatUnit.powerSecond);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -132,7 +132,7 @@ public class PowerGraph{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update(){
|
public void update(){
|
||||||
if(threads.getFrameID() == lastFrameUpdated || consumers.size == 0 || producers.size == 0){
|
if(threads.getFrameID() == lastFrameUpdated || consumers.size == 0 && producers.size == 0 && batteries.size == 0){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,31 +108,40 @@ public class PowerTests extends PowerTestFixture{
|
|||||||
@TestFactory
|
@TestFactory
|
||||||
DynamicTest[] testDirectConsumptionWithBattery(){
|
DynamicTest[] testDirectConsumptionWithBattery(){
|
||||||
return new DynamicTest[]{
|
return new DynamicTest[]{
|
||||||
dynamicTest("1", () -> test_directConsumptionWithBattery(10.0f, 0.0f, 0.0f, 10.0f, 0.0f, "Empty battery, no consumer")),
|
dynamicTest("01", () -> test_directConsumptionWithBattery(10.0f, 0.0f, 0.0f, 10.0f, 0.0f, "Empty battery, no consumer")),
|
||||||
dynamicTest("2", () -> test_directConsumptionWithBattery(10.0f, 0.0f, 90.0f, 100.0f, 0.0f, "Battery full after update, no consumer")),
|
dynamicTest("02", () -> test_directConsumptionWithBattery(10.0f, 0.0f, 90.0f, 100.0f, 0.0f, "Battery full after update, no consumer")),
|
||||||
dynamicTest("3", () -> test_directConsumptionWithBattery(10.0f, 0.0f, 100.0f, 100.0f, 0.0f, "Full battery, no consumer")),
|
dynamicTest("03", () -> test_directConsumptionWithBattery(10.0f, 0.0f, 100.0f, 100.0f, 0.0f, "Full battery, no consumer")),
|
||||||
dynamicTest("4", () -> test_directConsumptionWithBattery(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, "No producer, no consumer, empty battery")),
|
dynamicTest("04", () -> test_directConsumptionWithBattery(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, "No producer, no consumer, empty battery")),
|
||||||
dynamicTest("5", () -> test_directConsumptionWithBattery(0.0f, 0.0f, 100.0f, 100.0f, 0.0f, "No producer, no consumer, full battery")),
|
dynamicTest("05", () -> test_directConsumptionWithBattery(0.0f, 0.0f, 100.0f, 100.0f, 0.0f, "No producer, no consumer, full battery")),
|
||||||
dynamicTest("6", () -> test_directConsumptionWithBattery(0.0f, 10.0f, 0.0f, 0.0f, 0.0f, "No producer, empty battery")),
|
dynamicTest("06", () -> test_directConsumptionWithBattery(0.0f, 10.0f, 0.0f, 0.0f, 0.0f, "No producer, empty battery")),
|
||||||
dynamicTest("7", () -> test_directConsumptionWithBattery(0.0f, 10.0f, 100.0f, 90.0f, 1.0f, "No producer, full battery")),
|
dynamicTest("07", () -> test_directConsumptionWithBattery(0.0f, 10.0f, 100.0f, 90.0f, 1.0f, "No producer, full battery")),
|
||||||
dynamicTest("8", () -> test_directConsumptionWithBattery(0.0f, 10.0f, 5.0f, 0.0f, 0.5f, "No producer, low battery"))
|
dynamicTest("08", () -> test_directConsumptionWithBattery(0.0f, 10.0f, 5.0f, 0.0f, 0.5f, "No producer, low battery")),
|
||||||
|
dynamicTest("09", () -> test_directConsumptionWithBattery(5.0f, 10.0f, 5.0f, 0.0f, 1.0f, "Producer + Battery = Consumed")),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
void test_directConsumptionWithBattery(float producedPower, float requestedPower, float initialBatteryCapacity, float expectedBatteryCapacity, float expectedSatisfaction, String parameterDescription){
|
void test_directConsumptionWithBattery(float producedPower, float requestedPower, float initialBatteryCapacity, float expectedBatteryCapacity, float expectedSatisfaction, String parameterDescription){
|
||||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
PowerGraph powerGraph = new PowerGraph();
|
||||||
Tile directConsumerTile = createFakeTile(0, 1, createFakeDirectConsumer(requestedPower, 0.6f));
|
|
||||||
|
if(producedPower > 0.0f){
|
||||||
|
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
||||||
|
powerGraph.add(producerTile);
|
||||||
|
}
|
||||||
|
Tile directConsumerTile = null;
|
||||||
|
if(requestedPower > 0.0f){
|
||||||
|
directConsumerTile = createFakeTile(0, 1, createFakeDirectConsumer(requestedPower, 0.6f));
|
||||||
|
powerGraph.add(directConsumerTile);
|
||||||
|
}
|
||||||
float maxCapacity = 100f;
|
float maxCapacity = 100f;
|
||||||
Tile batteryTile = createFakeTile(0, 2, createFakeBattery(maxCapacity, 10 ));
|
Tile batteryTile = createFakeTile(0, 2, createFakeBattery(maxCapacity, 10 ));
|
||||||
batteryTile.entity.power.satisfaction = initialBatteryCapacity / maxCapacity;
|
batteryTile.entity.power.satisfaction = initialBatteryCapacity / maxCapacity;
|
||||||
|
|
||||||
PowerGraph powerGraph = new PowerGraph();
|
|
||||||
powerGraph.add(producerTile);
|
|
||||||
powerGraph.add(directConsumerTile);
|
|
||||||
powerGraph.add(batteryTile);
|
powerGraph.add(batteryTile);
|
||||||
|
|
||||||
powerGraph.update();
|
powerGraph.update();
|
||||||
assertEquals(expectedBatteryCapacity, batteryTile.entity.power.satisfaction * maxCapacity, MathUtils.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery capacity did not match");
|
assertEquals(expectedBatteryCapacity, batteryTile.entity.power.satisfaction * maxCapacity, MathUtils.FLOAT_ROUNDING_ERROR, parameterDescription + ": Expected battery capacity did not match");
|
||||||
assertEquals(expectedSatisfaction, directConsumerTile.entity.power.satisfaction, MathUtils.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
if(directConsumerTile != null){
|
||||||
|
assertEquals(expectedSatisfaction, directConsumerTile.entity.power.satisfaction, MathUtils.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of direct consumer did not match");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user