test: migrate test cases for jupiter (#39)
parent
1546f3e6e7
commit
4cf8f4485f
|
@ -16,9 +16,8 @@
|
|||
|
||||
package org.terasology.polyworld;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.terasology.engine.SimpleUri;
|
||||
|
@ -34,6 +33,8 @@ import org.terasology.world.block.BlockRegion;
|
|||
import org.terasology.world.generation.Region;
|
||||
import org.terasology.world.generation.World;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests the flatness of lakes
|
||||
*/
|
||||
|
@ -43,7 +44,7 @@ public class FlatLakeTest {
|
|||
|
||||
private IslandWorldGenerator worldGen;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
TinyEnvironment.setup();
|
||||
|
||||
|
@ -83,16 +84,13 @@ public class FlatLakeTest {
|
|||
float centerElevation = elevationModel.getElevation(reg);
|
||||
float eps = 0.001f;
|
||||
for (Corner corner : reg.getCorners()) {
|
||||
Assert.assertEquals(centerElevation, elevationModel.getElevation(corner), eps);
|
||||
assertEquals(centerElevation, elevationModel.getElevation(corner), eps);
|
||||
}
|
||||
}
|
||||
|
||||
private Region createRegion(int minX, int minY, int maxX, int maxY) {
|
||||
|
||||
BlockRegion area3d = new BlockRegion(minX, 0, minY, maxX, 1, maxY);
|
||||
World world = worldGen.getWorld();
|
||||
Region region = world.getWorldData(area3d);
|
||||
|
||||
return region;
|
||||
return world.getWorldData(area3d);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,7 @@ package org.terasology.polyworld;
|
|||
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2fc;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.terasology.joml.geom.Rectanglef;
|
||||
import org.terasology.polyworld.graph.Corner;
|
||||
import org.terasology.polyworld.graph.Edge;
|
||||
|
@ -30,6 +29,9 @@ import org.terasology.world.block.BlockArea;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
/**
|
||||
* Tests the correct representation of a {@link Graph}
|
||||
*/
|
||||
|
@ -47,21 +49,21 @@ public abstract class GraphTest {
|
|||
|
||||
// check location of all border corners
|
||||
|
||||
Assert.assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(realBounds.minX, realBounds.minY), .001f)).count());
|
||||
Assert.assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(realBounds.minX, realBounds.maxY), .001f)).count());
|
||||
Assert.assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(realBounds.maxX, realBounds.minY), .001f)).count());
|
||||
Assert.assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(realBounds.maxX, realBounds.maxY), .001f)).count());
|
||||
assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(realBounds.minX, realBounds.minY), .001f)).count());
|
||||
assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(realBounds.minX, realBounds.maxY), .001f)).count());
|
||||
assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(realBounds.maxX, realBounds.minY), .001f)).count());
|
||||
assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(realBounds.maxX, realBounds.maxY), .001f)).count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGraphEdgesExist() {
|
||||
|
||||
for (Edge e : graph.getEdges()) {
|
||||
Assert.assertTrue(graph.getRegions().contains(e.getRegion0()));
|
||||
Assert.assertTrue(graph.getRegions().contains(e.getRegion1()));
|
||||
assertTrue(graph.getRegions().contains(e.getRegion0()));
|
||||
assertTrue(graph.getRegions().contains(e.getRegion1()));
|
||||
|
||||
Assert.assertTrue(graph.getCorners().contains(e.getCorner0()));
|
||||
Assert.assertTrue(graph.getCorners().contains(e.getCorner1()));
|
||||
assertTrue(graph.getCorners().contains(e.getCorner0()));
|
||||
assertTrue(graph.getCorners().contains(e.getCorner1()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,23 +77,23 @@ public abstract class GraphTest {
|
|||
Corner c0 = e.getCorner0();
|
||||
Corner c1 = e.getCorner1();
|
||||
|
||||
Assert.assertTrue(r0.getCorners().contains(c0));
|
||||
Assert.assertTrue(r0.getCorners().contains(c1));
|
||||
assertTrue(r0.getCorners().contains(c0));
|
||||
assertTrue(r0.getCorners().contains(c1));
|
||||
|
||||
Assert.assertTrue(r1.getCorners().contains(c0));
|
||||
Assert.assertTrue(r1.getCorners().contains(c1));
|
||||
assertTrue(r1.getCorners().contains(c0));
|
||||
assertTrue(r1.getCorners().contains(c1));
|
||||
|
||||
Assert.assertTrue(c0.getTouches().contains(r0));
|
||||
Assert.assertTrue(c0.getTouches().contains(r1));
|
||||
assertTrue(c0.getTouches().contains(r0));
|
||||
assertTrue(c0.getTouches().contains(r1));
|
||||
|
||||
Assert.assertTrue(c1.getTouches().contains(r0));
|
||||
Assert.assertTrue(c1.getTouches().contains(r1));
|
||||
assertTrue(c1.getTouches().contains(r0));
|
||||
assertTrue(c1.getTouches().contains(r1));
|
||||
|
||||
Assert.assertTrue(c1.getAdjacent().contains(c0));
|
||||
Assert.assertTrue(c0.getAdjacent().contains(c1));
|
||||
assertTrue(c1.getAdjacent().contains(c0));
|
||||
assertTrue(c0.getAdjacent().contains(c1));
|
||||
|
||||
Assert.assertTrue(r0.getNeighbors().contains(r1));
|
||||
Assert.assertTrue(r1.getNeighbors().contains(r0));
|
||||
assertTrue(r0.getNeighbors().contains(r1));
|
||||
assertTrue(r1.getNeighbors().contains(r0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +101,7 @@ public abstract class GraphTest {
|
|||
public void testGraphCornerRegions() {
|
||||
|
||||
for (GraphRegion r : graph.getRegions()) {
|
||||
Assert.assertTrue(graph.getCorners().containsAll(r.getCorners()));
|
||||
assertTrue(graph.getCorners().containsAll(r.getCorners()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,12 +110,12 @@ public abstract class GraphTest {
|
|||
float eps = 0.1f;
|
||||
for (Corner c : graph.getCorners()) {
|
||||
if ((Math.abs(c.getLocation().x() - realBounds.minX) < eps)
|
||||
|| (Math.abs(c.getLocation().x() - realBounds.maxX) < eps)
|
||||
|| (Math.abs(c.getLocation().y() - realBounds.minY) < eps)
|
||||
|| (Math.abs(c.getLocation().y() - realBounds.maxY) < eps)) {
|
||||
Assert.assertTrue("Corner must have border flag: " + c, c.isBorder());
|
||||
|| (Math.abs(c.getLocation().x() - realBounds.maxX) < eps)
|
||||
|| (Math.abs(c.getLocation().y() - realBounds.minY) < eps)
|
||||
|| (Math.abs(c.getLocation().y() - realBounds.maxY) < eps)) {
|
||||
assertTrue(c.isBorder(), "Corner must have border flag: " + c);
|
||||
} else {
|
||||
Assert.assertFalse("Corner must not have border flag: " + c, c.isBorder());
|
||||
assertFalse(c.isBorder(), "Corner must not have border flag: " + c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,14 +123,14 @@ public abstract class GraphTest {
|
|||
@Test
|
||||
public void testGraphRegionNeighborsSet() {
|
||||
for (GraphRegion r : graph.getRegions()) {
|
||||
Assert.assertFalse(r.getNeighbors().isEmpty());
|
||||
assertFalse(r.getNeighbors().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGraphCornerTouchesSet() {
|
||||
for (Corner c : graph.getCorners()) {
|
||||
Assert.assertFalse(c.getTouches().isEmpty());
|
||||
assertFalse(c.getTouches().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.terasology.polyworld;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.terasology.joml.geom.Rectanglef;
|
||||
import org.terasology.polyworld.graph.GridGraph;
|
||||
import org.terasology.world.block.BlockArea;
|
||||
|
@ -26,7 +26,7 @@ import org.terasology.world.block.BlockArea;
|
|||
*/
|
||||
public class GridGraphTest extends GraphTest {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
final int width = 512;
|
||||
final int height = 256;
|
||||
|
|
|
@ -19,11 +19,9 @@ package org.terasology.polyworld;
|
|||
import com.google.common.math.DoubleMath;
|
||||
import org.joml.Vector2fc;
|
||||
import org.joml.Vector2ic;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.terasology.joml.geom.Rectanglef;
|
||||
|
@ -39,31 +37,28 @@ import org.terasology.world.block.BlockArea;
|
|||
import org.terasology.world.block.BlockAreac;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class LookupTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(LookupTest.class);
|
||||
private MersenneRandom rng;
|
||||
|
||||
public LookupTest(long seed) {
|
||||
rng = new MersenneRandom(seed);
|
||||
}
|
||||
|
||||
@Parameters(name = "{index}: seed={0}")
|
||||
public static Collection<Object[]> data() {
|
||||
List<Object[]> params = new ArrayList<>();
|
||||
public static Stream<Arguments> generateSeed() {
|
||||
Random seedGen = new FastRandom(12345);
|
||||
Arguments[] args = new Arguments[50];
|
||||
for (int i = 0; i < 50; i++) {
|
||||
params.add(new Object[] {seedGen.nextInt()});
|
||||
args[i] = Arguments.of(seedGen.nextInt());
|
||||
}
|
||||
return params;
|
||||
return Arrays.stream(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoverage() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("generateSeed")
|
||||
public void testCoverage(int seed) {
|
||||
MersenneRandom rng = new MersenneRandom(seed);
|
||||
|
||||
int x = rng.nextInt(-10000, 10000);
|
||||
int y = rng.nextInt(-10000, 10000);
|
||||
|
@ -86,7 +81,7 @@ public class LookupTest {
|
|||
TriangleLookup lookup = new TriangleLookup(graph);
|
||||
for (Vector2ic coord : intBounds) {
|
||||
Triangle tri = lookup.findTriangleAt(coord.x(), coord.y());
|
||||
Assert.assertNotNull(tri);
|
||||
assertNotNull(tri);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,9 @@ package org.terasology.polyworld;
|
|||
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2fc;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.terasology.joml.geom.Rectanglef;
|
||||
import org.terasology.math.delaunay.Voronoi;
|
||||
import org.terasology.polyworld.graph.GraphRegion;
|
||||
|
@ -32,6 +31,9 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests the correct representation of a {@link VoronoiGraph}
|
||||
*/
|
||||
|
@ -39,7 +41,7 @@ public class VoronoiGraphTest extends GraphTest {
|
|||
|
||||
protected List<Vector2fc> points;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
final int width = 512;
|
||||
final int height = 256;
|
||||
|
@ -59,23 +61,22 @@ public class VoronoiGraphTest extends GraphTest {
|
|||
@Test
|
||||
public void testRegionAndSiteMatch() {
|
||||
List<GraphRegion> regions = graph.getRegions();
|
||||
Assert.assertEquals("Number of regions differs from number of input sites", points.size(), regions.size());
|
||||
assertEquals(points.size(), regions.size(), "Number of regions differs from number of input sites");
|
||||
for (GraphRegion reg : regions) {
|
||||
Assert.assertTrue(points.contains(reg.getCenter()));
|
||||
assertTrue(points.contains(reg.getCenter()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // umm the locations changed
|
||||
@Disabled // umm the locations changed
|
||||
public void testVoronoiLocations() {
|
||||
List<Vector2fc> corners = new ArrayList<>();
|
||||
graph.getCorners().forEach(c -> corners.add(c.getLocation()));
|
||||
|
||||
Assert.assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(171, 128), .001f)).count());
|
||||
Assert.assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(192, 256), .001f)).count());
|
||||
Assert.assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(308, 256), .001f)).count());
|
||||
Assert.assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(332, 160), .001f)).count());
|
||||
|
||||
assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(171, 128), .001f)).count());
|
||||
assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(192, 256), .001f)).count());
|
||||
assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(308, 256), .001f)).count());
|
||||
assertEquals(1, corners.stream().filter(c -> c.equals(new Vector2f(332, 160), .001f)).count());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,13 +18,14 @@ package org.terasology.polyworld.sampling;
|
|||
|
||||
import com.google.common.math.DoubleMath;
|
||||
import org.joml.Vector2fc;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.terasology.joml.geom.Rectanglef;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class PoissonDiscTest {
|
||||
|
||||
@Test
|
||||
|
@ -46,7 +47,7 @@ public class PoissonDiscTest {
|
|||
if (p0.distanceSquared(p1) < rad * rad) {
|
||||
System.err.println("FAIL FOR " + p1);
|
||||
System.err.println("EXISTING " + p0);
|
||||
Assert.fail(String.format("Distance for %d/%d == %.2f", i, j, p0.distance(p1)));
|
||||
fail(String.format("Distance for %d/%d == %.2f", i, j, p0.distance(p1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue