Fixed tests again, locally

This commit is contained in:
Anuken 2019-01-26 13:20:07 -05:00
parent 4be675f977
commit 956448a1a5
6 changed files with 236 additions and 11 deletions

View File

@ -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);
}
}

View File

@ -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));

View File

@ -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){
}
}

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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