mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-05 16:37:38 +07:00
Merge pull request #8 from Timmeey86/baltitenger
Fixed test names / Continued work on generators
This commit is contained in:
commit
82d20efa8d
@ -40,7 +40,6 @@ public class DebugBlocks extends BlockList implements ContentList{
|
||||
public void load(){
|
||||
powerVoid = new PowerBlock("powervoid"){
|
||||
{
|
||||
// TODO Adapt to new power system if necessary
|
||||
consumes.powerDirect(Float.MAX_VALUE);
|
||||
shadow = "shadow-round-1";
|
||||
}
|
||||
@ -54,8 +53,7 @@ public class DebugBlocks extends BlockList implements ContentList{
|
||||
@Override
|
||||
public void init(){
|
||||
super.init();
|
||||
// TODO Adapt to new power system if necessary
|
||||
//stats.remove(BlockStat.powerCapacity);
|
||||
stats.remove(BlockStat.powerUse);
|
||||
}
|
||||
};
|
||||
|
||||
@ -67,7 +65,6 @@ public class DebugBlocks extends BlockList implements ContentList{
|
||||
shadow = "shadow-round-1";
|
||||
}
|
||||
|
||||
// TODO Adapt to new power system if necessary
|
||||
@Override
|
||||
public float getPowerProduction(Tile tile){
|
||||
return 10000f;
|
||||
|
@ -22,8 +22,6 @@ public class LiquidBlocks extends BlockList implements ContentList{
|
||||
pumpAmount = 0.2f;
|
||||
consumes.powerDirect(0.015f);
|
||||
liquidCapacity = 30f;
|
||||
// TODO Verify: No longer buffered
|
||||
consumes.powerDirect(20f / 60f);
|
||||
hasPower = true;
|
||||
size = 2;
|
||||
tier = 1;
|
||||
@ -35,8 +33,6 @@ public class LiquidBlocks extends BlockList implements ContentList{
|
||||
consumes.powerDirect(0.03f);
|
||||
liquidCapacity = 40f;
|
||||
hasPower = true;
|
||||
// TODO Verify: No longer buffered
|
||||
consumes.powerDirect(20f / 60f);
|
||||
size = 2;
|
||||
tier = 2;
|
||||
}};
|
||||
|
@ -42,26 +42,13 @@ public class PowerBlocks extends BlockList implements ContentList{
|
||||
itemDuration = 220f;
|
||||
}};
|
||||
|
||||
// TODO: Maybe reintroduce a class for the initial production efficiency
|
||||
solarPanel = new PowerGenerator("solar-panel"){
|
||||
{
|
||||
powerProduction = 0.0045f;
|
||||
}
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
tile.<GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||
}
|
||||
};
|
||||
solarPanel = new SolarGenerator("solar-panel"){{
|
||||
powerProduction = 0.0045f;
|
||||
}};
|
||||
|
||||
largeSolarPanel = new PowerGenerator("solar-panel-large"){
|
||||
{
|
||||
powerProduction = 0.055f;
|
||||
}
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
tile.<GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||
}
|
||||
};
|
||||
largeSolarPanel = new PowerGenerator("solar-panel-large"){{
|
||||
powerProduction = 0.055f;
|
||||
}};
|
||||
|
||||
thoriumReactor = new NuclearReactor("thorium-reactor"){{
|
||||
size = 3;
|
||||
|
@ -25,6 +25,7 @@ import io.anuke.mindustry.world.blocks.defense.turrets.PowerTurret;
|
||||
import io.anuke.mindustry.world.blocks.defense.turrets.Turret;
|
||||
import io.anuke.mindustry.world.blocks.power.NuclearReactor;
|
||||
import io.anuke.mindustry.world.blocks.power.PowerGenerator;
|
||||
import io.anuke.mindustry.world.blocks.power.SolarGenerator;
|
||||
import io.anuke.mindustry.world.blocks.storage.CoreBlock;
|
||||
import io.anuke.mindustry.world.blocks.storage.StorageBlock;
|
||||
import io.anuke.mindustry.world.blocks.units.UnitFactory;
|
||||
@ -114,8 +115,7 @@ public class FortressGenerator{
|
||||
seeder.get(PowerBlocks.solarPanel, tile -> tile.block() == PowerBlocks.largeSolarPanel && gen.random.chance(0.3)),
|
||||
|
||||
//coal gens
|
||||
// TODO Verify - This used to be solar panel
|
||||
seeder.get(PowerBlocks.combustionGenerator, tile -> tile.block() instanceof PowerGenerator && gen.random.chance(0.2)),
|
||||
seeder.get(PowerBlocks.combustionGenerator, tile -> tile.block() instanceof SolarGenerator && gen.random.chance(0.2)),
|
||||
|
||||
//water extractors
|
||||
seeder.get(ProductionBlocks.waterExtractor, tile -> tile.block() instanceof NuclearReactor && gen.random.chance(0.5)),
|
||||
|
@ -4,17 +4,17 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.production.GenericCrafter.GenericCrafterEntity;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FusionReactor extends PowerGenerator{
|
||||
protected int plasmas = 4;
|
||||
protected float maxPowerProduced = 2f;
|
||||
protected float warmupSpeed = 0.001f;
|
||||
|
||||
protected Color plasma1 = Color.valueOf("ffd06b"), plasma2 = Color.valueOf("ff361b");
|
||||
@ -24,35 +24,25 @@ public class FusionReactor extends PowerGenerator{
|
||||
super(name);
|
||||
hasPower = true;
|
||||
hasLiquids = true;
|
||||
// TODO Adapt to new power system
|
||||
//powerCapacity = 100f;
|
||||
powerProduction = 2.0f;
|
||||
liquidCapacity = 30f;
|
||||
hasItems = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStats(){
|
||||
super.setStats();
|
||||
|
||||
// TODO Verify for new power system
|
||||
stats.remove(BlockStat.basePowerGeneration);
|
||||
stats.add(BlockStat.basePowerGeneration, maxPowerProduced * 60f, StatUnit.powerSecond);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
FusionReactorEntity entity = tile.entity();
|
||||
|
||||
float increaseOrDecrease = 1.0f;
|
||||
if(entity.cons.valid()){
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
||||
}else{
|
||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f);
|
||||
increaseOrDecrease = -1.0f;
|
||||
}
|
||||
|
||||
// TODO Adapt to new power system
|
||||
//float powerAdded = Math.min(powerCapacity - entity.power.amount, maxPowerProduced * Mathf.pow(entity.warmup, 4f) * Timers.delta());
|
||||
//entity.power.amount += powerAdded;
|
||||
entity.totalProgress += entity.warmup * Timers.delta();
|
||||
float efficiencyAdded = Mathf.pow(entity.warmup, 4f) * Timers.delta();
|
||||
entity.productionEfficiency = Mathf.clamp(entity.productionEfficiency + efficiencyAdded * increaseOrDecrease);
|
||||
|
||||
tile.entity.power.graph.update();
|
||||
}
|
||||
@ -100,7 +90,7 @@ public class FusionReactor extends PowerGenerator{
|
||||
|
||||
Draw.rect(name + "-top", tile.drawx(), tile.drawy());
|
||||
|
||||
Draw.color(ind1, ind2, entity.warmup + Mathf.absin(entity.totalProgress, 3f, entity.warmup * 0.5f));
|
||||
Draw.color(ind1, ind2, entity.warmup + Mathf.absin(entity.productionEfficiency, 3f, entity.warmup * 0.5f));
|
||||
Draw.rect(name + "-light", tile.drawx(), tile.drawy());
|
||||
|
||||
Draw.color();
|
||||
@ -127,7 +117,19 @@ public class FusionReactor extends PowerGenerator{
|
||||
//TODO catastrophic failure
|
||||
}
|
||||
|
||||
public static class FusionReactorEntity extends GenericCrafterEntity{
|
||||
public static class FusionReactorEntity extends GeneratorEntity{
|
||||
public float warmup;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(warmup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
super.read(stream);
|
||||
warmup = stream.readFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,10 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockFlag;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PowerGenerator extends PowerDistributor{
|
||||
/** The amount of power produced per tick. */
|
||||
protected float powerProduction;
|
||||
@ -58,5 +62,15 @@ public class PowerGenerator extends PowerDistributor{
|
||||
public static class GeneratorEntity extends TileEntity{
|
||||
public float generateTime;
|
||||
public float productionEfficiency = 0.0f;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
stream.writeFloat(productionEfficiency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
productionEfficiency = stream.readFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package io.anuke.mindustry.world.blocks.power;
|
||||
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.world.BarType;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.meta.BlockBar;
|
||||
import io.anuke.mindustry.world.meta.BlockStat;
|
||||
import io.anuke.mindustry.world.meta.StatUnit;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.EnumSet;
|
||||
|
||||
public class SolarGenerator extends PowerGenerator{
|
||||
|
||||
public SolarGenerator(String name){
|
||||
super(name);
|
||||
// Remove the BlockFlag.producer flag to make this a lower priority target than other generators.
|
||||
flags = EnumSet.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity newEntity(){
|
||||
return new PowerGenerator.GeneratorEntity(){{
|
||||
productionEfficiency = 1.0f;
|
||||
}};
|
||||
}
|
||||
|
||||
}
|
@ -49,17 +49,17 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
|
||||
|
||||
/** Tests the consumption and efficiency when being supplied with liquids. */
|
||||
@TestFactory
|
||||
DynamicTest[] testLiquidConsumption(){
|
||||
DynamicTest[] generatorWorksProperlyWithLiquidInput(){
|
||||
return new DynamicTest[]{
|
||||
dynamicTest("01", () -> test_liquidConsumption(Liquids.oil, 0.0f, "No liquids provided")),
|
||||
dynamicTest("02", () -> test_liquidConsumption(Liquids.oil, maximumLiquidUsage / 4.0f, "Low oil provided")),
|
||||
dynamicTest("03", () -> test_liquidConsumption(Liquids.oil, maximumLiquidUsage * 1.0f, "Sufficient oil provided")),
|
||||
dynamicTest("04", () -> test_liquidConsumption(Liquids.oil, maximumLiquidUsage * 2.0f, "Excess oil provided"))
|
||||
dynamicTest("01", () -> simulateLiquidConsumption(Liquids.oil, 0.0f, "No liquids provided")),
|
||||
dynamicTest("02", () -> simulateLiquidConsumption(Liquids.oil, maximumLiquidUsage / 4.0f, "Low oil provided")),
|
||||
dynamicTest("03", () -> simulateLiquidConsumption(Liquids.oil, maximumLiquidUsage * 1.0f, "Sufficient oil provided")),
|
||||
dynamicTest("04", () -> simulateLiquidConsumption(Liquids.oil, maximumLiquidUsage * 2.0f, "Excess oil provided"))
|
||||
// Note: The generator will decline any other liquid since it's not flammable
|
||||
};
|
||||
}
|
||||
|
||||
void test_liquidConsumption(Liquid liquid, float availableLiquidAmount, String parameterDescription){
|
||||
void simulateLiquidConsumption(Liquid liquid, float availableLiquidAmount, String parameterDescription){
|
||||
final float baseEfficiency = fakeLiquidPowerMultiplier * liquid.flammability;
|
||||
final float expectedEfficiency = Math.min(1.0f, availableLiquidAmount / maximumLiquidUsage) * baseEfficiency;
|
||||
final float expectedConsumptionPerTick = Math.min(maximumLiquidUsage, availableLiquidAmount);
|
||||
@ -84,19 +84,19 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
|
||||
|
||||
/** Tests the consumption and efficiency when being supplied with items. */
|
||||
@TestFactory
|
||||
DynamicTest[] testItemConsumption(){
|
||||
DynamicTest[] generatorWorksProperlyWithItemInput(){
|
||||
return new DynamicTest[]{
|
||||
dynamicTest("01", () -> test_itemConsumption(Items.coal, 0, "No items provided")),
|
||||
dynamicTest("02", () -> test_itemConsumption(Items.coal, 1, "Sufficient coal provided")),
|
||||
dynamicTest("03", () -> test_itemConsumption(Items.coal, 10, "Excess coal provided")),
|
||||
dynamicTest("04", () -> test_itemConsumption(Items.blastCompound, 1, "Blast compound provided")),
|
||||
//dynamicTest("03", () -> test_itemConsumption(Items.plastanium, 1, "Plastanium provided")), // Not accepted by generator due to low flammability
|
||||
dynamicTest("05", () -> test_itemConsumption(Items.biomatter, 1, "Biomatter provided")),
|
||||
dynamicTest("06", () -> test_itemConsumption(Items.pyratite, 1, "Pyratite provided"))
|
||||
dynamicTest("01", () -> simulateItemConsumption(Items.coal, 0, "No items provided")),
|
||||
dynamicTest("02", () -> simulateItemConsumption(Items.coal, 1, "Sufficient coal provided")),
|
||||
dynamicTest("03", () -> simulateItemConsumption(Items.coal, 10, "Excess coal provided")),
|
||||
dynamicTest("04", () -> simulateItemConsumption(Items.blastCompound, 1, "Blast compound provided")),
|
||||
//dynamicTest("03", () -> simulateItemConsumption(Items.plastanium, 1, "Plastanium provided")), // Not accepted by generator due to low flammability
|
||||
dynamicTest("05", () -> simulateItemConsumption(Items.biomatter, 1, "Biomatter provided")),
|
||||
dynamicTest("06", () -> simulateItemConsumption(Items.pyratite, 1, "Pyratite provided"))
|
||||
};
|
||||
}
|
||||
|
||||
void test_itemConsumption(Item item, int amount, String parameterDescription){
|
||||
void simulateItemConsumption(Item item, int amount, String parameterDescription){
|
||||
final float expectedEfficiency = Math.min(1.0f, amount > 0 ? item.flammability : 0f);
|
||||
final float expectedRemainingItemAmount = Math.max(0, amount - 1);
|
||||
assertTrue(generator.acceptItem(item, tile, null), parameterDescription + ": Items which will be declined by the generator don't need to be tested - The code won't be called for those cases.");
|
||||
@ -122,7 +122,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
|
||||
|
||||
/** Makes sure the efficiency stays equal during the item duration. */
|
||||
@Test
|
||||
void test_efficiencyConstantDuringItemDuration(){
|
||||
void efficiencyRemainsConstantWithinItemDuration(){
|
||||
|
||||
// Burn a single coal and test for the duration
|
||||
entity.items.add(Items.coal, 1);
|
||||
|
@ -33,21 +33,21 @@ public class PowerTests extends PowerTestFixture{
|
||||
* Assumption: When the consumer requests zero power, satisfaction does not change. Default is 0.0f.
|
||||
*/
|
||||
@TestFactory
|
||||
DynamicTest[] testDirectConsumption(){
|
||||
DynamicTest[] directConsumerSatisfactionIsAsExpected(){
|
||||
return new DynamicTest[]{
|
||||
// Note: Unfortunately, the display names are not yet output through gradle. See https://github.com/gradle/gradle/issues/5975
|
||||
// That's why we inject the description into the test method for now.
|
||||
// Additional Note: If you don't see any labels in front of the values supplied as function parameters, use a better IDE like IntelliJ IDEA.
|
||||
dynamicTest("01", () -> test_directConsumptionCalculation(0.0f, 1.0f, 0.0f, "0.0 produced, 1.0 consumed (no power available)")),
|
||||
dynamicTest("02", () -> test_directConsumptionCalculation(0.0f, 0.0f, 0.0f, "0.0 produced, 0.0 consumed (no power anywhere)")),
|
||||
dynamicTest("03", () -> test_directConsumptionCalculation(1.0f, 0.0f, 0.0f, "1.0 produced, 0.0 consumed (no power requested)")),
|
||||
dynamicTest("04", () -> test_directConsumptionCalculation(1.0f, 1.0f, 1.0f, "1.0 produced, 1.0 consumed (stable consumption)")),
|
||||
dynamicTest("05", () -> test_directConsumptionCalculation(0.5f, 1.0f, 0.5f, "0.5 produced, 1.0 consumed (power shortage)")),
|
||||
dynamicTest("06", () -> test_directConsumptionCalculation(1.0f, 0.5f, 1.0f, "1.0 produced, 0.5 consumed (power excess)")),
|
||||
dynamicTest("07", () -> test_directConsumptionCalculation(0.09f, 0.09f - MathUtils.FLOAT_ROUNDING_ERROR / 10.0f, 1.0f, "floating point inaccuracy (stable consumption)"))
|
||||
dynamicTest("01", () -> simulateDirectConsumption(0.0f, 1.0f, 0.0f, "0.0 produced, 1.0 consumed (no power available)")),
|
||||
dynamicTest("02", () -> simulateDirectConsumption(0.0f, 0.0f, 0.0f, "0.0 produced, 0.0 consumed (no power anywhere)")),
|
||||
dynamicTest("03", () -> simulateDirectConsumption(1.0f, 0.0f, 0.0f, "1.0 produced, 0.0 consumed (no power requested)")),
|
||||
dynamicTest("04", () -> simulateDirectConsumption(1.0f, 1.0f, 1.0f, "1.0 produced, 1.0 consumed (stable consumption)")),
|
||||
dynamicTest("05", () -> simulateDirectConsumption(0.5f, 1.0f, 0.5f, "0.5 produced, 1.0 consumed (power shortage)")),
|
||||
dynamicTest("06", () -> simulateDirectConsumption(1.0f, 0.5f, 1.0f, "1.0 produced, 0.5 consumed (power excess)")),
|
||||
dynamicTest("07", () -> simulateDirectConsumption(0.09f, 0.09f - MathUtils.FLOAT_ROUNDING_ERROR / 10.0f, 1.0f, "floating point inaccuracy (stable consumption)"))
|
||||
};
|
||||
}
|
||||
void test_directConsumptionCalculation(float producedPower, float requiredPower, float expectedSatisfaction, String parameterDescription){
|
||||
void simulateDirectConsumption(float producedPower, float requiredPower, float expectedSatisfaction, String parameterDescription){
|
||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
||||
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||
Tile directConsumerTile = createFakeTile(0, 1, createFakeDirectConsumer(requiredPower, 0.6f));
|
||||
@ -66,28 +66,28 @@ public class PowerTests extends PowerTestFixture{
|
||||
|
||||
/** Tests the satisfaction of a single buffered consumer after a single update of the power graph which contains a single producer. */
|
||||
@TestFactory
|
||||
DynamicTest[] testBufferedConsumption(){
|
||||
DynamicTest[] bufferedConsumerSatisfactionIsAsExpected(){
|
||||
return new DynamicTest[]{
|
||||
// Note: powerPerTick may not be 0 in any of the test cases. This would equal a "ticksToFill" of infinite.
|
||||
// Note: Due to a fixed delta of 0.5, only half of what is defined here will in fact be produced/consumed. Keep this in mind when defining expectedSatisfaction!
|
||||
dynamicTest("01", () -> test_bufferedConsumptionCalculation(0.0f, 0.0f, 0.1f, 0.0f, 0.0f, "Empty Buffer, No power anywhere")),
|
||||
dynamicTest("02", () -> test_bufferedConsumptionCalculation(0.0f, 1.0f, 0.1f, 0.0f, 0.0f, "Empty Buffer, No power provided")),
|
||||
dynamicTest("03", () -> test_bufferedConsumptionCalculation(1.0f, 0.0f, 0.1f, 0.0f, 0.0f, "Empty Buffer, No power requested")),
|
||||
dynamicTest("04", () -> test_bufferedConsumptionCalculation(1.0f, 1.0f, 1.0f, 0.0f, 0.5f, "Empty Buffer, Stable Power, One tick to fill")),
|
||||
dynamicTest("05", () -> test_bufferedConsumptionCalculation(2.0f, 1.0f, 2.0f, 0.0f, 1.0f, "Empty Buffer, Stable Power, One delta to fill")),
|
||||
dynamicTest("06", () -> test_bufferedConsumptionCalculation(1.0f, 1.0f, 0.1f, 0.0f, 0.05f, "Empty Buffer, Stable Power, multiple ticks to fill")),
|
||||
dynamicTest("07", () -> test_bufferedConsumptionCalculation(1.2f, 0.5f, 1.0f, 0.0f, 1.0f, "Empty Buffer, Power excess, one delta to fill")),
|
||||
dynamicTest("08", () -> test_bufferedConsumptionCalculation(1.0f, 0.5f, 0.1f, 0.0f, 0.1f, "Empty Buffer, Power excess, multiple ticks to fill")),
|
||||
dynamicTest("09", () -> test_bufferedConsumptionCalculation(1.0f, 1.0f, 2.0f, 0.0f, 0.5f, "Empty Buffer, Power shortage, one delta to fill")),
|
||||
dynamicTest("10", () -> test_bufferedConsumptionCalculation(0.5f, 1.0f, 0.1f, 0.0f, 0.05f, "Empty Buffer, Power shortage, multiple ticks to fill")),
|
||||
dynamicTest("11", () -> test_bufferedConsumptionCalculation(0.0f, 1.0f, 0.1f, 0.5f, 0.5f, "Unchanged buffer with no power produced")),
|
||||
dynamicTest("12", () -> test_bufferedConsumptionCalculation(1.0f, 1.0f, 0.1f, 1.0f, 1.0f, "Unchanged buffer when already full")),
|
||||
dynamicTest("13", () -> test_bufferedConsumptionCalculation(0.2f, 1.0f, 0.5f, 0.5f, 0.6f, "Half buffer, power shortage")),
|
||||
dynamicTest("14", () -> test_bufferedConsumptionCalculation(1.0f, 1.0f, 0.5f, 0.9f, 1.0f, "Buffer does not get exceeded")),
|
||||
dynamicTest("15", () -> test_bufferedConsumptionCalculation(2.0f, 1.0f, 1.0f, 0.5f, 1.0f, "Half buffer, filled with excess"))
|
||||
dynamicTest("01", () -> simulateBufferedConsumption(0.0f, 0.0f, 0.1f, 0.0f, 0.0f, "Empty Buffer, No power anywhere")),
|
||||
dynamicTest("02", () -> simulateBufferedConsumption(0.0f, 1.0f, 0.1f, 0.0f, 0.0f, "Empty Buffer, No power provided")),
|
||||
dynamicTest("03", () -> simulateBufferedConsumption(1.0f, 0.0f, 0.1f, 0.0f, 0.0f, "Empty Buffer, No power requested")),
|
||||
dynamicTest("04", () -> simulateBufferedConsumption(1.0f, 1.0f, 1.0f, 0.0f, 0.5f, "Empty Buffer, Stable Power, One tick to fill")),
|
||||
dynamicTest("05", () -> simulateBufferedConsumption(2.0f, 1.0f, 2.0f, 0.0f, 1.0f, "Empty Buffer, Stable Power, One delta to fill")),
|
||||
dynamicTest("06", () -> simulateBufferedConsumption(1.0f, 1.0f, 0.1f, 0.0f, 0.05f, "Empty Buffer, Stable Power, multiple ticks to fill")),
|
||||
dynamicTest("07", () -> simulateBufferedConsumption(1.2f, 0.5f, 1.0f, 0.0f, 1.0f, "Empty Buffer, Power excess, one delta to fill")),
|
||||
dynamicTest("08", () -> simulateBufferedConsumption(1.0f, 0.5f, 0.1f, 0.0f, 0.1f, "Empty Buffer, Power excess, multiple ticks to fill")),
|
||||
dynamicTest("09", () -> simulateBufferedConsumption(1.0f, 1.0f, 2.0f, 0.0f, 0.5f, "Empty Buffer, Power shortage, one delta to fill")),
|
||||
dynamicTest("10", () -> simulateBufferedConsumption(0.5f, 1.0f, 0.1f, 0.0f, 0.05f, "Empty Buffer, Power shortage, multiple ticks to fill")),
|
||||
dynamicTest("11", () -> simulateBufferedConsumption(0.0f, 1.0f, 0.1f, 0.5f, 0.5f, "Unchanged buffer with no power produced")),
|
||||
dynamicTest("12", () -> simulateBufferedConsumption(1.0f, 1.0f, 0.1f, 1.0f, 1.0f, "Unchanged buffer when already full")),
|
||||
dynamicTest("13", () -> simulateBufferedConsumption(0.2f, 1.0f, 0.5f, 0.5f, 0.6f, "Half buffer, power shortage")),
|
||||
dynamicTest("14", () -> simulateBufferedConsumption(1.0f, 1.0f, 0.5f, 0.9f, 1.0f, "Buffer does not get exceeded")),
|
||||
dynamicTest("15", () -> simulateBufferedConsumption(2.0f, 1.0f, 1.0f, 0.5f, 1.0f, "Half buffer, filled with excess"))
|
||||
};
|
||||
}
|
||||
void test_bufferedConsumptionCalculation(float producedPower, float maxBuffer, float powerConsumedPerTick, float initialSatisfaction, float expectedSatisfaction, String parameterDescription){
|
||||
void simulateBufferedConsumption(float producedPower, float maxBuffer, float powerConsumedPerTick, float initialSatisfaction, float expectedSatisfaction, String parameterDescription){
|
||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
||||
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||
Tile bufferedConsumerTile = createFakeTile(0, 1, createFakeBufferedConsumer(maxBuffer, maxBuffer > 0.0f ? maxBuffer/powerConsumedPerTick : 1.0f));
|
||||
@ -109,21 +109,21 @@ public class PowerTests extends PowerTestFixture{
|
||||
* The used battery is created with a maximum capacity of 100 and receives ten power per tick.
|
||||
*/
|
||||
@TestFactory
|
||||
DynamicTest[] testDirectConsumptionWithBattery(){
|
||||
DynamicTest[] batteryCapacityIsAsExpected(){
|
||||
return new DynamicTest[]{
|
||||
// Note: expectedBatteryCapacity is currently adjusted to a delta of 0.5! (FakeThreadHandler sets it to that)
|
||||
dynamicTest("01", () -> test_directConsumptionWithBattery(10.0f, 0.0f, 0.0f, 5.0f, 0.0f, "Empty battery, no consumer")),
|
||||
dynamicTest("02", () -> test_directConsumptionWithBattery(10.0f, 0.0f, 94.999f, 99.999f, 0.0f, "Battery almost full after update, no consumer")),
|
||||
dynamicTest("03", () -> test_directConsumptionWithBattery(10.0f, 0.0f, 100.0f, 100.0f, 0.0f, "Full battery, no consumer")),
|
||||
dynamicTest("04", () -> test_directConsumptionWithBattery(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, "No producer, no consumer, empty battery")),
|
||||
dynamicTest("05", () -> test_directConsumptionWithBattery(0.0f, 0.0f, 100.0f, 100.0f, 0.0f, "No producer, no consumer, full battery")),
|
||||
dynamicTest("06", () -> test_directConsumptionWithBattery(0.0f, 10.0f, 0.0f, 0.0f, 0.0f, "No producer, empty battery")),
|
||||
dynamicTest("07", () -> test_directConsumptionWithBattery(0.0f, 10.0f, 100.0f, 95.0f, 1.0f, "No producer, full battery")),
|
||||
dynamicTest("08", () -> test_directConsumptionWithBattery(0.0f, 10.0f, 2.5f, 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")),
|
||||
dynamicTest("01", () -> simulateDirectConsumptionWithBattery(10.0f, 0.0f, 0.0f, 5.0f, 0.0f, "Empty battery, no consumer")),
|
||||
dynamicTest("02", () -> simulateDirectConsumptionWithBattery(10.0f, 0.0f, 94.999f, 99.999f, 0.0f, "Battery almost full after update, no consumer")),
|
||||
dynamicTest("03", () -> simulateDirectConsumptionWithBattery(10.0f, 0.0f, 100.0f, 100.0f, 0.0f, "Full battery, no consumer")),
|
||||
dynamicTest("04", () -> simulateDirectConsumptionWithBattery(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, "No producer, no consumer, empty battery")),
|
||||
dynamicTest("05", () -> simulateDirectConsumptionWithBattery(0.0f, 0.0f, 100.0f, 100.0f, 0.0f, "No producer, no consumer, full battery")),
|
||||
dynamicTest("06", () -> simulateDirectConsumptionWithBattery(0.0f, 10.0f, 0.0f, 0.0f, 0.0f, "No producer, empty battery")),
|
||||
dynamicTest("07", () -> simulateDirectConsumptionWithBattery(0.0f, 10.0f, 100.0f, 95.0f, 1.0f, "No producer, full battery")),
|
||||
dynamicTest("08", () -> simulateDirectConsumptionWithBattery(0.0f, 10.0f, 2.5f, 0.0f, 0.5f, "No producer, low battery")),
|
||||
dynamicTest("09", () -> simulateDirectConsumptionWithBattery(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 simulateDirectConsumptionWithBattery(float producedPower, float requestedPower, float initialBatteryCapacity, float expectedBatteryCapacity, float expectedSatisfaction, String parameterDescription){
|
||||
PowerGraph powerGraph = new PowerGraph();
|
||||
|
||||
if(producedPower > 0.0f){
|
||||
@ -151,7 +151,7 @@ public class PowerTests extends PowerTestFixture{
|
||||
|
||||
/** Makes sure a direct consumer stops working after power production is set to zero. */
|
||||
@Test
|
||||
void testDirectConsumptionStopsWithNoPower(){
|
||||
void directConsumptionStopsWithNoPower(){
|
||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(10.0f));
|
||||
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||
Tile consumerTile = createFakeTile(0, 1, createFakeDirectConsumer(5.0f, 0.6f));
|
||||
|
Loading…
Reference in New Issue
Block a user