Source reformat

This commit is contained in:
Anuken
2019-04-08 09:03:18 -04:00
parent 4a96b9bb00
commit b40beb0d1d
331 changed files with 2822 additions and 3274 deletions

View File

@ -87,7 +87,7 @@ public class ApplicationTests{
@BeforeEach
void resetWorld(){
Time.setDeltaProvider(() -> 1f);
Time.setDeltaProvider(() -> 1f);
logic.reset();
state.set(State.menu);
}
@ -138,8 +138,8 @@ public class ApplicationTests{
int by = 4;
world.setBlock(world.tile(bx, by), Blocks.coreShard, Team.blue);
assertEquals(world.tile(bx, by).getTeam(), Team.blue);
for(int x = bx-1; x <= bx + 1; x++){
for(int y = by-1; y <= by + 1; y++){
for(int x = bx - 1; x <= bx + 1; x++){
for(int y = by - 1; y <= by + 1; y++){
if(x == bx && by == y){
assertEquals(world.tile(x, y).block(), Blocks.coreShard);
}else{
@ -247,8 +247,8 @@ public class ApplicationTests{
void buildingOverlap(){
initBuilding();
Spirit d1 = (Spirit) UnitTypes.spirit.create(Team.blue);
Spirit d2 = (Spirit) UnitTypes.spirit.create(Team.blue);
Spirit d1 = (Spirit)UnitTypes.spirit.create(Team.blue);
Spirit d2 = (Spirit)UnitTypes.spirit.create(Team.blue);
d1.set(10f, 20f);
d2.set(10f, 20f);
@ -302,8 +302,8 @@ public class ApplicationTests{
void buildingDestruction(){
initBuilding();
Spirit d1 = (Spirit) UnitTypes.spirit.create(Team.blue);
Spirit d2 = (Spirit) UnitTypes.spirit.create(Team.blue);
Spirit d1 = (Spirit)UnitTypes.spirit.create(Team.blue);
Spirit d2 = (Spirit)UnitTypes.spirit.create(Team.blue);
d1.set(10f, 20f);
d2.set(10f, 20f);
@ -340,7 +340,7 @@ public class ApplicationTests{
}
int i = 0;
for(int x = 5; x < tiles.length && i < content.blocks().size;){
for(int x = 5; x < tiles.length && i < content.blocks().size; ){
Block block = content.block(i++);
if(block.buildVisibility.get()){
tiles[x][5].setBlock(block);

View File

@ -2,26 +2,24 @@ import io.anuke.arc.util.Time;
import io.anuke.mindustry.content.Blocks;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.world.Tile;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import static io.anuke.mindustry.Vars.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class WorldTests {
public class WorldTests{
static Tile[][] tiles;
@BeforeAll
static void launchApplication(){
ApplicationTests.launchApplication();
world.createTiles(10,10);
ApplicationTests.launchApplication();
world.createTiles(10, 10);
tiles = world.getTiles();
}
@BeforeEach
void resetWorld(){
Time.setDeltaProvider(() -> 1f);
Time.setDeltaProvider(() -> 1f);
logic.reset();
state.set(State.menu);
}
@ -31,8 +29,8 @@ public class WorldTests {
fillWith(Blocks.rocks.id);
world.addDarkness(tiles);
for(int x = 0; x < tiles.length; x++) {
for (int y = 0; y < tiles[0].length; y++) {
for(int x = 0; x < tiles.length; x++){
for(int y = 0; y < tiles[0].length; y++){
assertEquals(4, tiles[x][y].getRotation());
}
}
@ -43,8 +41,8 @@ public class WorldTests {
fillWith(Blocks.copperWall.id);
world.addDarkness(tiles);
for(int x = 0; x < tiles.length; x++) {
for (int y = 0; y < tiles[0].length; y++) {
for(int x = 0; x < tiles.length; x++){
for(int y = 0; y < tiles[0].length; y++){
assertEquals(0, tiles[x][y].getRotation());
}
}
@ -55,8 +53,8 @@ public class WorldTests {
fillWith(Blocks.air.id);
world.addDarkness(tiles);
for(int x = 0; x < tiles.length; x++) {
for (int y = 0; y < tiles[0].length; y++) {
for(int x = 0; x < tiles.length; x++){
for(int y = 0; y < tiles[0].length; y++){
assertEquals(0, tiles[x][y].getRotation());
}
}
@ -67,8 +65,8 @@ public class WorldTests {
fillWith(Blocks.cliffs.id);
world.addDarkness(tiles);
for(int x = 0; x < tiles.length; x++) {
for (int y = 0; y < tiles[0].length; y++) {
for(int x = 0; x < tiles.length; x++){
for(int y = 0; y < tiles[0].length; y++){
assertEquals(0, tiles[x][y].getRotation());
}
}
@ -80,8 +78,8 @@ public class WorldTests {
tiles[5][5] = new Tile(5, 5, (byte)0, Blocks.copperWall.id, (byte)0, (byte)0);
world.addDarkness(tiles);
for(int x = 0; x < tiles.length; x++) {
for (int y = 0; y < tiles[0].length; y++) {
for(int x = 0; x < tiles.length; x++){
for(int y = 0; y < tiles[0].length; y++){
byte darkness = tiles[x][y].getRotation();
int distance = Math.abs(x - 5) + Math.abs(y - 5);
assertEquals(Math.min(Math.max(distance - 1, 0), 4), darkness);
@ -95,8 +93,8 @@ public class WorldTests {
tiles[7][7] = new Tile(5, 5, (byte)0, Blocks.copperWall.id, (byte)0, (byte)0);
world.addDarkness(tiles);
for(int x = 0; x < tiles.length; x++) {
for (int y = 0; y < tiles[0].length; y++) {
for(int x = 0; x < tiles.length; x++){
for(int y = 0; y < tiles[0].length; y++){
byte darkness = tiles[x][y].getRotation();
int distance = Math.abs(x - 7) + Math.abs(y - 7);
assertEquals(Math.min(Math.max(distance - 1, 0), 4), darkness);
@ -105,8 +103,8 @@ public class WorldTests {
}
private static void fillWith(byte tileID){
for(int x = 0; x < tiles.length; x++) {
for (int y = 0; y < tiles[0].length; y++) {
for(int x = 0; x < tiles.length; x++){
for(int y = 0; y < tiles[0].length; y++){
tiles[x][y] = new Tile(x, y, (byte)0, tileID, (byte)0, (byte)0);
}
}

View File

@ -1,6 +1,7 @@
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.ObjectSet;
import io.anuke.arc.util.*;
import io.anuke.arc.util.Structs;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Zone;
@ -21,7 +22,7 @@ public class ZoneTests{
@BeforeEach
void resetWorld(){
Time.setDeltaProvider(() -> 1f);
Time.setDeltaProvider(() -> 1f);
logic.reset();
state.set(State.menu);
}

View File

@ -2,9 +2,7 @@ package power;
import io.anuke.arc.Graphics;
import io.anuke.arc.Graphics.Cursor.SystemCursor;
import io.anuke.arc.graphics.GL20;
import io.anuke.arc.graphics.GL30;
import io.anuke.arc.graphics.Pixmap;
import io.anuke.arc.graphics.*;
import io.anuke.arc.graphics.glutils.GLVersion;
public class FakeGraphics extends Graphics{

View File

@ -7,9 +7,7 @@ import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.Liquid;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.power.ItemLiquidGenerator;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.*;
import java.util.ArrayList;
@ -61,8 +59,8 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
// Execute all tests for the case where only liquids are accepted and for the case where liquids and items are accepted (but supply only liquids)
InputType[] inputTypesToBeTested = new InputType[]{
InputType.liquids,
InputType.any
InputType.liquids,
InputType.any
};
ArrayList<DynamicTest> tests = new ArrayList<>();
@ -103,8 +101,8 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
// Execute all tests for the case where only items are accepted and for the case where liquids and items are accepted (but supply only items)
InputType[] inputTypesToBeTested = new InputType[]{
InputType.items,
InputType.any
InputType.items,
InputType.any
};
ArrayList<DynamicTest> tests = new ArrayList<>();
@ -171,7 +169,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{
generator.update(tile);
assertEquals(0.0f, entity.productionEfficiency, "Duration: " + currentDuration);
}
enum InputType{
items,
liquids,

View File

@ -12,19 +12,17 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.PowerBlock;
import io.anuke.mindustry.world.blocks.power.Battery;
import io.anuke.mindustry.world.blocks.power.PowerGenerator;
import io.anuke.mindustry.world.modules.ConsumeModule;
import io.anuke.mindustry.world.modules.ItemModule;
import io.anuke.mindustry.world.modules.LiquidModule;
import io.anuke.mindustry.world.modules.PowerModule;
import io.anuke.mindustry.world.modules.*;
import org.junit.jupiter.api.BeforeAll;
import java.lang.reflect.Field;
/** This class provides objects commonly used by power related unit tests.
* For now, this is a helper with static methods, but this might change.
*
* Note: All tests which subclass this will run with a fixed delta of 0.5!
* */
/**
* This class provides objects commonly used by power related unit tests.
* For now, this is a helper with static methods, but this might change.
* <p>
* Note: All tests which subclass this will run with a fixed delta of 0.5!
*/
public class PowerTestFixture{
public static final float smallRoundingTolerance = Mathf.FLOAT_ROUNDING_ERROR;
public static final float mediumRoundingTolerance = Mathf.FLOAT_ROUNDING_ERROR * 10;
@ -62,10 +60,11 @@ public class PowerTestFixture{
consumes.powerBuffered(capacity, ticksToFill);
}};
}
/**
* Creates a fake tile on the given location using the given block.
* @param x The X coordinate.
* @param y The y coordinate.
* @param x The X coordinate.
* @param y The y coordinate.
* @param block The block on the tile.
* @return The created tile or null in case of exceptions.
*/

View File

@ -30,25 +30,27 @@ public class PowerTests extends PowerTestFixture{
@Nested
class PowerGraphTests{
/** Tests the satisfaction of a single consumer after a single update of the power graph which contains a single producer.
*
* Assumption: When the consumer requests zero power, satisfaction does not change. Default is 0.0f.
/**
* Tests the satisfaction of a single consumer after a single update of the power graph which contains a single producer.
* <p>
* Assumption: When the consumer requests zero power, satisfaction does not change. Default is 0.0f.
*/
@TestFactory
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", () -> simulateDirectConsumption(0.0f, 1.0f, 0.0f, "0.0 produced, 1.0 consumed (no power available)")),
dynamicTest("02", () -> simulateDirectConsumption(0.0f, 0.0f, 1.0f, "0.0 produced, 0.0 consumed (no power anywhere)")),
dynamicTest("03", () -> simulateDirectConsumption(1.0f, 0.0f, 1.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 - Mathf.FLOAT_ROUNDING_ERROR / 10.0f, 1.0f, "floating point inaccuracy (stable consumption)"))
// 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", () -> simulateDirectConsumption(0.0f, 1.0f, 0.0f, "0.0 produced, 1.0 consumed (no power available)")),
dynamicTest("02", () -> simulateDirectConsumption(0.0f, 0.0f, 1.0f, "0.0 produced, 0.0 consumed (no power anywhere)")),
dynamicTest("03", () -> simulateDirectConsumption(1.0f, 0.0f, 1.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 - Mathf.FLOAT_ROUNDING_ERROR / 10.0f, 1.0f, "floating point inaccuracy (stable consumption)"))
};
}
void simulateDirectConsumption(float producedPower, float requiredPower, float expectedSatisfaction, String parameterDescription){
Tile producerTile = createFakeTile(0, 0, createFakeProducerBlock(producedPower));
producerTile.<PowerGenerator.GeneratorEntity>entity().productionEfficiency = 1f;
@ -70,29 +72,30 @@ public class PowerTests extends PowerTestFixture{
@TestFactory
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", () -> 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"))
// 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", () -> 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 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 = 1f;
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));
bufferedConsumerTile.entity.power.satisfaction = initialSatisfaction;
PowerGraph powerGraph = new PowerGraph();
@ -113,24 +116,26 @@ public class PowerTests extends PowerTestFixture{
assertEquals(expectedSatisfaction, bufferedConsumerTile.entity.power.satisfaction, Mathf.FLOAT_ROUNDING_ERROR, parameterDescription + ": Satisfaction of buffered consumer did not match");
}
/** Tests the satisfaction of a single direct consumer after a single update of the power graph which contains a single producer and a single battery.
* The used battery is created with a maximum capacity of 100 and receives ten power per tick.
/**
* Tests the satisfaction of a single direct consumer after a single update of the power graph which contains a single producer and a single battery.
* The used battery is created with a maximum capacity of 100 and receives ten power per tick.
*/
@TestFactory
DynamicTest[] batteryCapacityIsAsExpected(){
return new DynamicTest[]{
// Note: expectedBatteryCapacity is currently adjusted to a delta of 0.5! (FakeThreadHandler sets it to that)
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")),
// Note: expectedBatteryCapacity is currently adjusted to a delta of 0.5! (FakeThreadHandler sets it to that)
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 simulateDirectConsumptionWithBattery(float producedPower, float requestedPower, float initialBatteryCapacity, float expectedBatteryCapacity, float expectedSatisfaction, String parameterDescription){
PowerGraph powerGraph = new PowerGraph();
@ -145,7 +150,7 @@ public class PowerTests extends PowerTestFixture{
powerGraph.add(directConsumerTile);
}
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;
powerGraph.add(batteryTile);