mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-10 15:57:37 +07:00
Merge pull request #8 from Timmeey86/baltitenger
Fixed test names / Continued work on generators
This commit is contained in:
@ -40,7 +40,6 @@ public class DebugBlocks extends BlockList implements ContentList{
|
|||||||
public void load(){
|
public void load(){
|
||||||
powerVoid = new PowerBlock("powervoid"){
|
powerVoid = new PowerBlock("powervoid"){
|
||||||
{
|
{
|
||||||
// TODO Adapt to new power system if necessary
|
|
||||||
consumes.powerDirect(Float.MAX_VALUE);
|
consumes.powerDirect(Float.MAX_VALUE);
|
||||||
shadow = "shadow-round-1";
|
shadow = "shadow-round-1";
|
||||||
}
|
}
|
||||||
@ -54,8 +53,7 @@ public class DebugBlocks extends BlockList implements ContentList{
|
|||||||
@Override
|
@Override
|
||||||
public void init(){
|
public void init(){
|
||||||
super.init();
|
super.init();
|
||||||
// TODO Adapt to new power system if necessary
|
stats.remove(BlockStat.powerUse);
|
||||||
//stats.remove(BlockStat.powerCapacity);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -67,7 +65,6 @@ public class DebugBlocks extends BlockList implements ContentList{
|
|||||||
shadow = "shadow-round-1";
|
shadow = "shadow-round-1";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Adapt to new power system if necessary
|
|
||||||
@Override
|
@Override
|
||||||
public float getPowerProduction(Tile tile){
|
public float getPowerProduction(Tile tile){
|
||||||
return 10000f;
|
return 10000f;
|
||||||
|
@ -22,8 +22,6 @@ public class LiquidBlocks extends BlockList implements ContentList{
|
|||||||
pumpAmount = 0.2f;
|
pumpAmount = 0.2f;
|
||||||
consumes.powerDirect(0.015f);
|
consumes.powerDirect(0.015f);
|
||||||
liquidCapacity = 30f;
|
liquidCapacity = 30f;
|
||||||
// TODO Verify: No longer buffered
|
|
||||||
consumes.powerDirect(20f / 60f);
|
|
||||||
hasPower = true;
|
hasPower = true;
|
||||||
size = 2;
|
size = 2;
|
||||||
tier = 1;
|
tier = 1;
|
||||||
@ -35,8 +33,6 @@ public class LiquidBlocks extends BlockList implements ContentList{
|
|||||||
consumes.powerDirect(0.03f);
|
consumes.powerDirect(0.03f);
|
||||||
liquidCapacity = 40f;
|
liquidCapacity = 40f;
|
||||||
hasPower = true;
|
hasPower = true;
|
||||||
// TODO Verify: No longer buffered
|
|
||||||
consumes.powerDirect(20f / 60f);
|
|
||||||
size = 2;
|
size = 2;
|
||||||
tier = 2;
|
tier = 2;
|
||||||
}};
|
}};
|
||||||
|
@ -42,26 +42,13 @@ public class PowerBlocks extends BlockList implements ContentList{
|
|||||||
itemDuration = 220f;
|
itemDuration = 220f;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
// TODO: Maybe reintroduce a class for the initial production efficiency
|
solarPanel = new SolarGenerator("solar-panel"){{
|
||||||
solarPanel = new PowerGenerator("solar-panel"){
|
powerProduction = 0.0045f;
|
||||||
{
|
}};
|
||||||
powerProduction = 0.0045f;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void update(Tile tile){
|
|
||||||
tile.<GeneratorEntity>entity().productionEfficiency = 1.0f;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
largeSolarPanel = new PowerGenerator("solar-panel-large"){
|
largeSolarPanel = new PowerGenerator("solar-panel-large"){{
|
||||||
{
|
powerProduction = 0.055f;
|
||||||
powerProduction = 0.055f;
|
}};
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void update(Tile tile){
|
|
||||||
tile.<GeneratorEntity>entity().productionEfficiency = 1.0f;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
thoriumReactor = new NuclearReactor("thorium-reactor"){{
|
thoriumReactor = new NuclearReactor("thorium-reactor"){{
|
||||||
size = 3;
|
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.defense.turrets.Turret;
|
||||||
import io.anuke.mindustry.world.blocks.power.NuclearReactor;
|
import io.anuke.mindustry.world.blocks.power.NuclearReactor;
|
||||||
import io.anuke.mindustry.world.blocks.power.PowerGenerator;
|
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.CoreBlock;
|
||||||
import io.anuke.mindustry.world.blocks.storage.StorageBlock;
|
import io.anuke.mindustry.world.blocks.storage.StorageBlock;
|
||||||
import io.anuke.mindustry.world.blocks.units.UnitFactory;
|
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)),
|
seeder.get(PowerBlocks.solarPanel, tile -> tile.block() == PowerBlocks.largeSolarPanel && gen.random.chance(0.3)),
|
||||||
|
|
||||||
//coal gens
|
//coal gens
|
||||||
// TODO Verify - This used to be solar panel
|
seeder.get(PowerBlocks.combustionGenerator, tile -> tile.block() instanceof SolarGenerator && gen.random.chance(0.2)),
|
||||||
seeder.get(PowerBlocks.combustionGenerator, tile -> tile.block() instanceof PowerGenerator && gen.random.chance(0.2)),
|
|
||||||
|
|
||||||
//water extractors
|
//water extractors
|
||||||
seeder.get(ProductionBlocks.waterExtractor, tile -> tile.block() instanceof NuclearReactor && gen.random.chance(0.5)),
|
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 com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.world.Tile;
|
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.Graphics;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
import io.anuke.ucore.graphics.Draw;
|
||||||
import io.anuke.ucore.util.Mathf;
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class FusionReactor extends PowerGenerator{
|
public class FusionReactor extends PowerGenerator{
|
||||||
protected int plasmas = 4;
|
protected int plasmas = 4;
|
||||||
protected float maxPowerProduced = 2f;
|
|
||||||
protected float warmupSpeed = 0.001f;
|
protected float warmupSpeed = 0.001f;
|
||||||
|
|
||||||
protected Color plasma1 = Color.valueOf("ffd06b"), plasma2 = Color.valueOf("ff361b");
|
protected Color plasma1 = Color.valueOf("ffd06b"), plasma2 = Color.valueOf("ff361b");
|
||||||
@ -24,35 +24,25 @@ public class FusionReactor extends PowerGenerator{
|
|||||||
super(name);
|
super(name);
|
||||||
hasPower = true;
|
hasPower = true;
|
||||||
hasLiquids = true;
|
hasLiquids = true;
|
||||||
// TODO Adapt to new power system
|
powerProduction = 2.0f;
|
||||||
//powerCapacity = 100f;
|
|
||||||
liquidCapacity = 30f;
|
liquidCapacity = 30f;
|
||||||
hasItems = true;
|
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
|
@Override
|
||||||
public void update(Tile tile){
|
public void update(Tile tile){
|
||||||
FusionReactorEntity entity = tile.entity();
|
FusionReactorEntity entity = tile.entity();
|
||||||
|
|
||||||
|
float increaseOrDecrease = 1.0f;
|
||||||
if(entity.cons.valid()){
|
if(entity.cons.valid()){
|
||||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
entity.warmup = Mathf.lerpDelta(entity.warmup, 1f, warmupSpeed);
|
||||||
}else{
|
}else{
|
||||||
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f);
|
entity.warmup = Mathf.lerpDelta(entity.warmup, 0f, 0.01f);
|
||||||
|
increaseOrDecrease = -1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Adapt to new power system
|
float efficiencyAdded = Mathf.pow(entity.warmup, 4f) * Timers.delta();
|
||||||
//float powerAdded = Math.min(powerCapacity - entity.power.amount, maxPowerProduced * Mathf.pow(entity.warmup, 4f) * Timers.delta());
|
entity.productionEfficiency = Mathf.clamp(entity.productionEfficiency + efficiencyAdded * increaseOrDecrease);
|
||||||
//entity.power.amount += powerAdded;
|
|
||||||
entity.totalProgress += entity.warmup * Timers.delta();
|
|
||||||
|
|
||||||
tile.entity.power.graph.update();
|
tile.entity.power.graph.update();
|
||||||
}
|
}
|
||||||
@ -100,7 +90,7 @@ public class FusionReactor extends PowerGenerator{
|
|||||||
|
|
||||||
Draw.rect(name + "-top", tile.drawx(), tile.drawy());
|
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.rect(name + "-light", tile.drawx(), tile.drawy());
|
||||||
|
|
||||||
Draw.color();
|
Draw.color();
|
||||||
@ -127,7 +117,19 @@ public class FusionReactor extends PowerGenerator{
|
|||||||
//TODO catastrophic failure
|
//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.BlockFlag;
|
||||||
import io.anuke.mindustry.world.meta.BlockStat;
|
import io.anuke.mindustry.world.meta.BlockStat;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class PowerGenerator extends PowerDistributor{
|
public class PowerGenerator extends PowerDistributor{
|
||||||
/** The amount of power produced per tick. */
|
/** The amount of power produced per tick. */
|
||||||
protected float powerProduction;
|
protected float powerProduction;
|
||||||
@ -58,5 +62,15 @@ public class PowerGenerator extends PowerDistributor{
|
|||||||
public static class GeneratorEntity extends TileEntity{
|
public static class GeneratorEntity extends TileEntity{
|
||||||
public float generateTime;
|
public float generateTime;
|
||||||
public float productionEfficiency = 0.0f;
|
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. */
|
/** Tests the consumption and efficiency when being supplied with liquids. */
|
||||||
@TestFactory
|
@TestFactory
|
||||||
DynamicTest[] testLiquidConsumption(){
|
DynamicTest[] generatorWorksProperlyWithLiquidInput(){
|
||||||
return new DynamicTest[]{
|
return new DynamicTest[]{
|
||||||
dynamicTest("01", () -> test_liquidConsumption(Liquids.oil, 0.0f, "No liquids provided")),
|
dynamicTest("01", () -> simulateLiquidConsumption(Liquids.oil, 0.0f, "No liquids provided")),
|
||||||
dynamicTest("02", () -> test_liquidConsumption(Liquids.oil, maximumLiquidUsage / 4.0f, "Low oil provided")),
|
dynamicTest("02", () -> simulateLiquidConsumption(Liquids.oil, maximumLiquidUsage / 4.0f, "Low oil provided")),
|
||||||
dynamicTest("03", () -> test_liquidConsumption(Liquids.oil, maximumLiquidUsage * 1.0f, "Sufficient oil provided")),
|
dynamicTest("03", () -> simulateLiquidConsumption(Liquids.oil, maximumLiquidUsage * 1.0f, "Sufficient oil provided")),
|
||||||
dynamicTest("04", () -> test_liquidConsumption(Liquids.oil, maximumLiquidUsage * 2.0f, "Excess 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
|
// 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 baseEfficiency = fakeLiquidPowerMultiplier * liquid.flammability;
|
||||||
final float expectedEfficiency = Math.min(1.0f, availableLiquidAmount / maximumLiquidUsage) * baseEfficiency;
|
final float expectedEfficiency = Math.min(1.0f, availableLiquidAmount / maximumLiquidUsage) * baseEfficiency;
|
||||||
final float expectedConsumptionPerTick = Math.min(maximumLiquidUsage, availableLiquidAmount);
|
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. */
|
/** Tests the consumption and efficiency when being supplied with items. */
|
||||||
@TestFactory
|
@TestFactory
|
||||||
DynamicTest[] testItemConsumption(){
|
DynamicTest[] generatorWorksProperlyWithItemInput(){
|
||||||
return new DynamicTest[]{
|
return new DynamicTest[]{
|
||||||
dynamicTest("01", () -> test_itemConsumption(Items.coal, 0, "No items provided")),
|
dynamicTest("01", () -> simulateItemConsumption(Items.coal, 0, "No items provided")),
|
||||||
dynamicTest("02", () -> test_itemConsumption(Items.coal, 1, "Sufficient coal provided")),
|
dynamicTest("02", () -> simulateItemConsumption(Items.coal, 1, "Sufficient coal provided")),
|
||||||
dynamicTest("03", () -> test_itemConsumption(Items.coal, 10, "Excess coal provided")),
|
dynamicTest("03", () -> simulateItemConsumption(Items.coal, 10, "Excess coal provided")),
|
||||||
dynamicTest("04", () -> test_itemConsumption(Items.blastCompound, 1, "Blast compound provided")),
|
dynamicTest("04", () -> simulateItemConsumption(Items.blastCompound, 1, "Blast compound provided")),
|
||||||
//dynamicTest("03", () -> test_itemConsumption(Items.plastanium, 1, "Plastanium provided")), // Not accepted by generator due to low flammability
|
//dynamicTest("03", () -> simulateItemConsumption(Items.plastanium, 1, "Plastanium provided")), // Not accepted by generator due to low flammability
|
||||||
dynamicTest("05", () -> test_itemConsumption(Items.biomatter, 1, "Biomatter provided")),
|
dynamicTest("05", () -> simulateItemConsumption(Items.biomatter, 1, "Biomatter provided")),
|
||||||
dynamicTest("06", () -> test_itemConsumption(Items.pyratite, 1, "Pyratite 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 expectedEfficiency = Math.min(1.0f, amount > 0 ? item.flammability : 0f);
|
||||||
final float expectedRemainingItemAmount = Math.max(0, amount - 1);
|
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.");
|
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. */
|
/** Makes sure the efficiency stays equal during the item duration. */
|
||||||
@Test
|
@Test
|
||||||
void test_efficiencyConstantDuringItemDuration(){
|
void efficiencyRemainsConstantWithinItemDuration(){
|
||||||
|
|
||||||
// Burn a single coal and test for the duration
|
// Burn a single coal and test for the duration
|
||||||
entity.items.add(Items.coal, 1);
|
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.
|
* Assumption: When the consumer requests zero power, satisfaction does not change. Default is 0.0f.
|
||||||
*/
|
*/
|
||||||
@TestFactory
|
@TestFactory
|
||||||
DynamicTest[] testDirectConsumption(){
|
DynamicTest[] directConsumerSatisfactionIsAsExpected(){
|
||||||
return new DynamicTest[]{
|
return new DynamicTest[]{
|
||||||
// Note: Unfortunately, the display names are not yet output through gradle. See https://github.com/gradle/gradle/issues/5975
|
// 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.
|
// 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.
|
// 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("01", () -> simulateDirectConsumption(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("02", () -> simulateDirectConsumption(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("03", () -> simulateDirectConsumption(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("04", () -> simulateDirectConsumption(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("05", () -> simulateDirectConsumption(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("06", () -> simulateDirectConsumption(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("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));
|
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
||||||
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||||
Tile directConsumerTile = createFakeTile(0, 1, createFakeDirectConsumer(requiredPower, 0.6f));
|
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. */
|
/** Tests the satisfaction of a single buffered consumer after a single update of the power graph which contains a single producer. */
|
||||||
@TestFactory
|
@TestFactory
|
||||||
DynamicTest[] testBufferedConsumption(){
|
DynamicTest[] bufferedConsumerSatisfactionIsAsExpected(){
|
||||||
return new DynamicTest[]{
|
return new DynamicTest[]{
|
||||||
// Note: powerPerTick may not be 0 in any of the test cases. This would equal a "ticksToFill" of infinite.
|
// 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!
|
// 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("01", () -> simulateBufferedConsumption(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("02", () -> simulateBufferedConsumption(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("03", () -> simulateBufferedConsumption(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("04", () -> simulateBufferedConsumption(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("05", () -> simulateBufferedConsumption(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("06", () -> simulateBufferedConsumption(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("07", () -> simulateBufferedConsumption(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("08", () -> simulateBufferedConsumption(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("09", () -> simulateBufferedConsumption(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("10", () -> simulateBufferedConsumption(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("11", () -> simulateBufferedConsumption(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("12", () -> simulateBufferedConsumption(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("13", () -> simulateBufferedConsumption(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("14", () -> simulateBufferedConsumption(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("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));
|
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
|
||||||
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||||
Tile bufferedConsumerTile = createFakeTile(0, 1, createFakeBufferedConsumer(maxBuffer, maxBuffer > 0.0f ? maxBuffer/powerConsumedPerTick : 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.
|
* The used battery is created with a maximum capacity of 100 and receives ten power per tick.
|
||||||
*/
|
*/
|
||||||
@TestFactory
|
@TestFactory
|
||||||
DynamicTest[] testDirectConsumptionWithBattery(){
|
DynamicTest[] batteryCapacityIsAsExpected(){
|
||||||
return new DynamicTest[]{
|
return new DynamicTest[]{
|
||||||
// Note: expectedBatteryCapacity is currently adjusted to a delta of 0.5! (FakeThreadHandler sets it to that)
|
// 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("01", () -> simulateDirectConsumptionWithBattery(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("02", () -> simulateDirectConsumptionWithBattery(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("03", () -> simulateDirectConsumptionWithBattery(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("04", () -> simulateDirectConsumptionWithBattery(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("05", () -> simulateDirectConsumptionWithBattery(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("06", () -> simulateDirectConsumptionWithBattery(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("07", () -> simulateDirectConsumptionWithBattery(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("08", () -> simulateDirectConsumptionWithBattery(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("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();
|
PowerGraph powerGraph = new PowerGraph();
|
||||||
|
|
||||||
if(producedPower > 0.0f){
|
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. */
|
/** Makes sure a direct consumer stops working after power production is set to zero. */
|
||||||
@Test
|
@Test
|
||||||
void testDirectConsumptionStopsWithNoPower(){
|
void directConsumptionStopsWithNoPower(){
|
||||||
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(10.0f));
|
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(10.0f));
|
||||||
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1.0f;
|
||||||
Tile consumerTile = createFakeTile(0, 1, createFakeDirectConsumer(5.0f, 0.6f));
|
Tile consumerTile = createFakeTile(0, 1, createFakeDirectConsumer(5.0f, 0.6f));
|
||||||
|
Reference in New Issue
Block a user