From 956448a1a50a715a3721816d5b23a87269a503a0 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 26 Jan 2019 13:20:07 -0500 Subject: [PATCH] Fixed tests again, locally --- .../anuke/mindustry/entities/TileEntity.java | 2 +- .../blocks/power/ItemLiquidGenerator.java | 4 +- tests/src/test/java/power/FakeGraphics.java | 222 ++++++++++++++++++ .../java/power/ItemLiquidGeneratorTests.java | 8 +- .../src/test/java/power/PowerTestFixture.java | 5 +- tests/src/test/java/power/PowerTests.java | 6 +- 6 files changed, 236 insertions(+), 11 deletions(-) create mode 100644 tests/src/test/java/power/FakeGraphics.java diff --git a/core/src/io/anuke/mindustry/entities/TileEntity.java b/core/src/io/anuke/mindustry/entities/TileEntity.java index 2d0c82e265..4241a25db9 100644 --- a/core/src/io/anuke/mindustry/entities/TileEntity.java +++ b/core/src/io/anuke/mindustry/entities/TileEntity.java @@ -151,7 +151,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{ if(health <= 0){ Call.onTileDestroyed(tile); - }else if(preHealth >= maxHealth() - 0.00001f && health < maxHealth()){ //when just damaged + }else if(preHealth >= maxHealth() - 0.00001f && health < maxHealth() && world != null){ //when just damaged world.indexer.notifyTileDamaged(this); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java b/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java index 3bfd065976..2392765e58 100644 --- a/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java +++ b/core/src/io/anuke/mindustry/world/blocks/power/ItemLiquidGenerator.java @@ -87,9 +87,7 @@ public class ItemLiquidGenerator extends PowerGenerator{ float used = Math.min(entity.liquids.get(liquid) * calculationDelta, maximumPossible); entity.liquids.remove(liquid, used); - - // Note: 0.5 = 100%. PowerGraph will multiply this efficiency by two on its own. - entity.productionEfficiency = Mathf.clamp(baseLiquidEfficiency * used / maximumPossible); + entity.productionEfficiency = baseLiquidEfficiency * used / maximumPossible; if(used > 0.001f && Mathf.chance(0.05 * entity.delta())){ Effects.effect(generateEffect, tile.drawx() + Mathf.range(3f), tile.drawy() + Mathf.range(3f)); diff --git a/tests/src/test/java/power/FakeGraphics.java b/tests/src/test/java/power/FakeGraphics.java new file mode 100644 index 0000000000..3006810379 --- /dev/null +++ b/tests/src/test/java/power/FakeGraphics.java @@ -0,0 +1,222 @@ +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.glutils.GLVersion; + +public class FakeGraphics extends Graphics{ + static int frame; + + @Override + public boolean isGL30Available(){ + return false; + } + + @Override + public GL20 getGL20(){ + return null; + } + + @Override + public void setGL20(GL20 gl20){ + + } + + @Override + public GL30 getGL30(){ + return null; + } + + @Override + public void setGL30(GL30 gl30){ + + } + + @Override + public int getWidth(){ + return 0; + } + + @Override + public int getHeight(){ + return 0; + } + + @Override + public int getBackBufferWidth(){ + return 0; + } + + @Override + public int getBackBufferHeight(){ + return 0; + } + + @Override + public long getFrameId(){ + return frame++; + } + + @Override + public float getDeltaTime(){ + return 0; + } + + @Override + public float getRawDeltaTime(){ + return 0; + } + + @Override + public int getFramesPerSecond(){ + return 0; + } + + @Override + public GLVersion getGLVersion(){ + return null; + } + + @Override + public float getPpiX(){ + return 0; + } + + @Override + public float getPpiY(){ + return 0; + } + + @Override + public float getPpcX(){ + return 0; + } + + @Override + public float getPpcY(){ + return 0; + } + + @Override + public float getDensity(){ + return 0; + } + + @Override + public boolean supportsDisplayModeChange(){ + return false; + } + + @Override + public Monitor getPrimaryMonitor(){ + return null; + } + + @Override + public Monitor getMonitor(){ + return null; + } + + @Override + public Monitor[] getMonitors(){ + return new Monitor[0]; + } + + @Override + public DisplayMode[] getDisplayModes(){ + return new DisplayMode[0]; + } + + @Override + public DisplayMode[] getDisplayModes(Monitor monitor){ + return new DisplayMode[0]; + } + + @Override + public DisplayMode getDisplayMode(){ + return null; + } + + @Override + public DisplayMode getDisplayMode(Monitor monitor){ + return null; + } + + @Override + public boolean setFullscreenMode(DisplayMode displayMode){ + return false; + } + + @Override + public boolean setWindowedMode(int width, int height){ + return false; + } + + @Override + public void setTitle(String title){ + + } + + @Override + public void setUndecorated(boolean undecorated){ + + } + + @Override + public void setResizable(boolean resizable){ + + } + + @Override + public void setVSync(boolean vsync){ + + } + + @Override + public BufferFormat getBufferFormat(){ + return null; + } + + @Override + public boolean supportsExtension(String extension){ + return false; + } + + @Override + public boolean isContinuousRendering(){ + return false; + } + + @Override + public void setContinuousRendering(boolean isContinuous){ + + } + + @Override + public void requestRendering(){ + + } + + @Override + public boolean isFullscreen(){ + return false; + } + + @Override + public Cursor newCursor(Pixmap pixmap, int xHotspot, int yHotspot){ + return null; + } + + @Override + protected void setCursor(Cursor cursor){ + + } + + @Override + protected void setSystemCursor(SystemCursor systemCursor){ + + } +} diff --git a/tests/src/test/java/power/ItemLiquidGeneratorTests.java b/tests/src/test/java/power/ItemLiquidGeneratorTests.java index 853286b3ed..87338158a1 100644 --- a/tests/src/test/java/power/ItemLiquidGeneratorTests.java +++ b/tests/src/test/java/power/ItemLiquidGeneratorTests.java @@ -7,12 +7,14 @@ 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.*; +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestFactory; import java.util.ArrayList; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.DynamicTest.dynamicTest; /** @@ -123,7 +125,7 @@ public class ItemLiquidGeneratorTests extends PowerTestFixture{ } void simulateItemConsumption(InputType inputType, Item item, int amount, String parameterDescription){ - final float expectedEfficiency = Math.min(1.0f, amount > 0 ? item.flammability : 0f); + final float expectedEfficiency = amount > 0 ? item.flammability : 0f; final float expectedRemainingItemAmount = Math.max(0, amount - 1); createGenerator(inputType); diff --git a/tests/src/test/java/power/PowerTestFixture.java b/tests/src/test/java/power/PowerTestFixture.java index 38db7cc8a6..f4303bfcb6 100644 --- a/tests/src/test/java/power/PowerTestFixture.java +++ b/tests/src/test/java/power/PowerTestFixture.java @@ -1,5 +1,6 @@ package power; +import io.anuke.arc.Core; import io.anuke.arc.math.Mathf; import io.anuke.arc.util.Time; import io.anuke.mindustry.Vars; @@ -24,13 +25,13 @@ import java.lang.reflect.Field; * 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; public static final float highRoundingTolerance = Mathf.FLOAT_ROUNDING_ERROR * 100; @BeforeAll static void initializeDependencies(){ + Core.graphics = new FakeGraphics(); Vars.content = new ContentLoader(); Vars.content.load(); Time.setDeltaProvider(() -> 0.5f); @@ -99,7 +100,7 @@ public class PowerTestFixture{ return tile; }catch(Exception ex){ - return null; + throw new RuntimeException(ex); } } } diff --git a/tests/src/test/java/power/PowerTests.java b/tests/src/test/java/power/PowerTests.java index db37e3668a..eb529e2cc5 100644 --- a/tests/src/test/java/power/PowerTests.java +++ b/tests/src/test/java/power/PowerTests.java @@ -1,5 +1,6 @@ package power; +import io.anuke.arc.Core; import io.anuke.arc.math.Mathf; import io.anuke.arc.util.Time; import io.anuke.mindustry.world.Tile; @@ -21,8 +22,9 @@ import static org.junit.jupiter.api.DynamicTest.dynamicTest; */ public class PowerTests extends PowerTestFixture{ - @BeforeEach - void initTest(){ + @BeforeAll + static void init(){ + Core.graphics = new FakeGraphics(); } @Nested