mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-10 02:37:12 +07:00
Tests: Add tests for addDarkness() in World.java (#412)
* Tests: Add tests for addDarkness() in World.java Add Junit tests for the addDarkness found in core/src/io/anuke/mindustry/core/World.java * Refactor: Remove code duplication Remove code duplication in WorldTests. Invoke launchApplication directly from ApplicationTests. * BugFix: Assign Tiles[][] tiles used for testing. Add assignment of Tiles[][] tiles separately when invoking ApplicationTests.launchApplication.
This commit is contained in:
parent
0c75f920de
commit
609565af5f
117
tests/src/test/java/WorldTests.java
Normal file
117
tests/src/test/java/WorldTests.java
Normal file
@ -0,0 +1,117 @@
|
||||
import static io.anuke.mindustry.Vars.logic;
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
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;
|
||||
|
||||
public class WorldTests {
|
||||
static Tile[][] tiles;
|
||||
|
||||
@BeforeAll
|
||||
static void launchApplication(){
|
||||
ApplicationTests.launchApplication();
|
||||
world.createTiles(10,10);
|
||||
tiles = world.getTiles();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void resetWorld(){
|
||||
Time.setDeltaProvider(() -> 1f);
|
||||
logic.reset();
|
||||
state.set(State.menu);
|
||||
}
|
||||
|
||||
@Test
|
||||
void addDarkness_allSolid_maxDarkness(){
|
||||
fillWith(Blocks.rocks.id);
|
||||
world.addDarkness(tiles);
|
||||
|
||||
for(int x = 0; x < tiles.length; x++) {
|
||||
for (int y = 0; y < tiles[0].length; y++) {
|
||||
assertEquals(4, tiles[x][y].getRotation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void addDarkness_allSyntethic_noDarkness(){
|
||||
fillWith(Blocks.copperWall.id);
|
||||
world.addDarkness(tiles);
|
||||
|
||||
for(int x = 0; x < tiles.length; x++) {
|
||||
for (int y = 0; y < tiles[0].length; y++) {
|
||||
assertEquals(0, tiles[x][y].getRotation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void addDarkness_allNotSolid_noDarkness(){
|
||||
fillWith(Blocks.air.id);
|
||||
world.addDarkness(tiles);
|
||||
|
||||
for(int x = 0; x < tiles.length; x++) {
|
||||
for (int y = 0; y < tiles[0].length; y++) {
|
||||
assertEquals(0, tiles[x][y].getRotation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void addDarkness_allNotFilled_noDarkness(){
|
||||
fillWith(Blocks.cliffs.id);
|
||||
world.addDarkness(tiles);
|
||||
|
||||
for(int x = 0; x < tiles.length; x++) {
|
||||
for (int y = 0; y < tiles[0].length; y++) {
|
||||
assertEquals(0, tiles[x][y].getRotation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void addDarkness_oneNotSolidMiddle_noDarkness(){
|
||||
fillWith(Blocks.rocks.id);
|
||||
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++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void addDarkness_oneNotSolidCorner_noDarkness(){
|
||||
fillWith(Blocks.rocks.id);
|
||||
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++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void fillWith(byte tileID){
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user