Refactored and updated to JUnit 5. Fixed biome selector.
This commit is contained in:
parent
78cd32106f
commit
c6001bdfea
38
pom.xml
38
pom.xml
@ -12,20 +12,12 @@
|
|||||||
<id>papermc</id>
|
<id>papermc</id>
|
||||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
|
||||||
<id>sk89q-repo</id>
|
|
||||||
<url>https://maven.enginehub.org/repo/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>rutger-repo</id>
|
|
||||||
<url>http://rutgerkok.nl/repo</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
</repositories>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>5.6.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -34,19 +26,19 @@
|
|||||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.sk89q.worldguard</groupId>
|
|
||||||
<artifactId>worldguard-bukkit</artifactId>
|
|
||||||
<version>7.0.2</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>nl.rutgerkok</groupId>
|
|
||||||
<artifactId>worldgeneratorapi</artifactId>
|
|
||||||
<version>0.4</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.2</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
@ -4,7 +4,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import ca.recrown.islandsurvivalcraft.worldgen.IslandSurvivalCraftWorldGenerator;
|
import ca.recrown.islandsurvivalcraft.worldgeneration.IslandSurvivalCraftWorldGenerator;
|
||||||
|
|
||||||
public class IslandSurvivalCraft extends JavaPlugin {
|
public class IslandSurvivalCraft extends JavaPlugin {
|
||||||
IslandSurvivalCraftWorldGenerator generator;
|
IslandSurvivalCraftWorldGenerator generator;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package ca.recrown.islandsurvivalcraft.worldgen;
|
package ca.recrown.islandsurvivalcraft.worldgeneration;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package ca.recrown.islandsurvivalcraft.worldgen;
|
package ca.recrown.islandsurvivalcraft.worldgeneration;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
@ -1,4 +1,4 @@
|
|||||||
package ca.recrown.islandsurvivalcraft.worldgen;
|
package ca.recrown.islandsurvivalcraft.worldgeneration;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -114,17 +114,21 @@ public class BiomeSelector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains the normal temperature for the given biome.
|
||||||
|
* @param biome The given biome.
|
||||||
|
* @return the Minecraft temperature.
|
||||||
|
*/
|
||||||
public float getBiomeTemperature(Biome biome) {
|
public float getBiomeTemperature(Biome biome) {
|
||||||
String biomeName = biome.name().toLowerCase();
|
String biomeName = biome.name().toLowerCase();
|
||||||
if (biomeName.endsWith("hills") || biomeName.endsWith("beach") || biomeName.endsWith("shore")) {
|
if (biomeName.endsWith("hills") || biomeName.endsWith("beach") || biomeName.endsWith("shore")) {
|
||||||
String biomeTypeName = biomeName;
|
String biomeTypeName = biomeName;
|
||||||
biomeTypeName = biomeTypeName.replace("hills", "");
|
biomeTypeName = biomeTypeName.replace("_hills", "");
|
||||||
biomeTypeName = biomeTypeName.replace("beach", "");
|
biomeTypeName = biomeTypeName.replace("_beach", "");
|
||||||
biomeTypeName = biomeTypeName.replace("shore", "");
|
biomeTypeName = biomeTypeName.replace("_shore", "");
|
||||||
biomeTypeName = biomeTypeName.substring(0, biomeTypeName.length() - 2);
|
|
||||||
|
|
||||||
for (Entry<Biome, Float> entry : lands.entrySet()) {
|
for (Entry<Biome, Float> entry : lands.entrySet()) {
|
||||||
if (entry.getKey().name().startsWith(biomeTypeName)) {
|
if (entry.getKey().name().toLowerCase().startsWith(biomeTypeName)) {
|
||||||
return entry.getValue();
|
return entry.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,8 +136,13 @@ public class BiomeSelector {
|
|||||||
return lands.get(biome);
|
return lands.get(biome);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
public Biome getTransitionBiome(Biome from) {
|
* Attempts to procure a biome that helps transitionfrom one biome to another biome
|
||||||
|
* for given biome.
|
||||||
|
* @param from the biome to transition from.
|
||||||
|
* @return the resulting transition biome.
|
||||||
|
*/
|
||||||
|
public Biome getTransitionalBiome(Biome from) {
|
||||||
String biomeName = from.name().toLowerCase();
|
String biomeName = from.name().toLowerCase();
|
||||||
if (biomeName.contains("jungle")) {
|
if (biomeName.contains("jungle")) {
|
||||||
if (biomeName.contains("modified")) {
|
if (biomeName.contains("modified")) {
|
||||||
@ -146,6 +155,12 @@ public class BiomeSelector {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the shore biome from the given information.
|
||||||
|
* @param from land biome that connects to it.
|
||||||
|
* @param temperature the Minecraft temperature of this shore.
|
||||||
|
* @return the shore biome associated with it.
|
||||||
|
*/
|
||||||
public Biome getShoreBiome(Biome from, float temperature) {
|
public Biome getShoreBiome(Biome from, float temperature) {
|
||||||
String biomeName = from.name().toLowerCase();
|
String biomeName = from.name().toLowerCase();
|
||||||
if (biomeName.contains("mushroom")) {
|
if (biomeName.contains("mushroom")) {
|
||||||
@ -153,12 +168,17 @@ public class BiomeSelector {
|
|||||||
} else if (biomeName.contains("mountains")) {
|
} else if (biomeName.contains("mountains")) {
|
||||||
return Biome.STONE_SHORE;
|
return Biome.STONE_SHORE;
|
||||||
}
|
}
|
||||||
if (temperature >= 0.8) {
|
if (temperature < 0.05) {
|
||||||
return Biome.BEACH;
|
return Biome.SNOWY_BEACH;
|
||||||
}
|
}
|
||||||
return Biome.SNOWY_BEACH;
|
return Biome.BEACH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Randomly selects a land biome that fits in given temperature.
|
||||||
|
* @param temperature Minecraft temperature to select biome from.
|
||||||
|
* @return The randomly selected biome.
|
||||||
|
*/
|
||||||
public Biome getLandBiome(float temperature) {
|
public Biome getLandBiome(float temperature) {
|
||||||
ArrayList<Biome> biomes = null;
|
ArrayList<Biome> biomes = null;
|
||||||
if (temperature <= 0.05f) {
|
if (temperature <= 0.05f) {
|
||||||
@ -174,6 +194,11 @@ public class BiomeSelector {
|
|||||||
return biomes.get((int) random.nextFloat() * biomes.size());
|
return biomes.get((int) random.nextFloat() * biomes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Randomly selects an ocean biome that fits in given temperature.
|
||||||
|
* @param temperature Minecraft temperature to select biome from.
|
||||||
|
* @return The randomly selected biome.
|
||||||
|
*/
|
||||||
public Biome getOceanBiome(float temperature) {
|
public Biome getOceanBiome(float temperature) {
|
||||||
ArrayList<Biome> biomes = null;
|
ArrayList<Biome> biomes = null;
|
||||||
if (temperature <= 0.00f) {
|
if (temperature <= 0.00f) {
|
@ -1,4 +1,4 @@
|
|||||||
package ca.recrown.islandsurvivalcraft.worldgen;
|
package ca.recrown.islandsurvivalcraft.worldgeneration;
|
||||||
|
|
||||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package ca.recrown.islandsurvivalcraft.worldgen;
|
package ca.recrown.islandsurvivalcraft.worldgeneration;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package ca.recrown.islandsurvivalcraft.worldgen;
|
package ca.recrown.islandsurvivalcraft.worldgeneration;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package ca.recrown.islandsurvivalcraft.worldgen;
|
package ca.recrown.islandsurvivalcraft.worldgeneration;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
@ -1,40 +1,23 @@
|
|||||||
package ca.recrown.islandsurvivalcraft;
|
package ca.recrown.islandsurvivalcraft;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import junit.framework.TestCase;
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import junit.framework.TestSuite;
|
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for simple App.
|
* Unit test for simple App.
|
||||||
*/
|
*/
|
||||||
public class UtilitiesTest
|
@TestInstance(Lifecycle.PER_CLASS)
|
||||||
extends TestCase
|
public class UtilitiesTest {
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create the test case
|
|
||||||
*
|
|
||||||
* @param testName name of the test case
|
|
||||||
*/
|
|
||||||
public UtilitiesTest( String testName )
|
|
||||||
{
|
|
||||||
super( testName );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the suite of tests being tested
|
|
||||||
*/
|
|
||||||
public static Test suite()
|
|
||||||
{
|
|
||||||
return new TestSuite( UtilitiesTest.class );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic hashmap inversion test.
|
* Basic hashmap inversion test.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testInvertHashMap()
|
public void testInvertHashMap()
|
||||||
{
|
{
|
||||||
HashMap<String, Integer> hashMap = new HashMap<>();
|
HashMap<String, Integer> hashMap = new HashMap<>();
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
package ca.recrown.islandsurvivalcraft.pathfinding;
|
package ca.recrown.islandsurvivalcraft.pathfinding;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import junit.framework.TestCase;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import junit.framework.TestSuite;
|
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.TestInstance;
|
||||||
|
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for simple App.
|
* Unit test for simple App.
|
||||||
*/
|
*/
|
||||||
public class DepthFirstSearchTest extends TestCase
|
@TestInstance(Lifecycle.PER_CLASS)
|
||||||
{
|
public class DepthFirstSearchTest {
|
||||||
|
|
||||||
private class Validator implements CoordinateValidatable {
|
private class Validator implements CoordinateValidatable {
|
||||||
private boolean[][] map;
|
private boolean[][] map;
|
||||||
@ -59,29 +64,11 @@ public class DepthFirstSearchTest extends TestCase
|
|||||||
{true, false, false, false},
|
{true, false, false, false},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
@BeforeAll
|
||||||
* Create the test case
|
protected void setUp() {
|
||||||
*
|
|
||||||
* @param testName name of the test case
|
|
||||||
*/
|
|
||||||
public DepthFirstSearchTest( String testName )
|
|
||||||
{
|
|
||||||
super( testName );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the suite of tests being tested
|
|
||||||
*/
|
|
||||||
public static Test suite()
|
|
||||||
{
|
|
||||||
return new TestSuite( DepthFirstSearchTest.class );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDFSMapAValid()
|
public void testDFSMapAValid()
|
||||||
{
|
{
|
||||||
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapA));
|
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapA));
|
||||||
@ -89,6 +76,7 @@ public class DepthFirstSearchTest extends TestCase
|
|||||||
assertTrue(dfs.buildTree());
|
assertTrue(dfs.buildTree());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDFSMapBValid()
|
public void testDFSMapBValid()
|
||||||
{
|
{
|
||||||
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapB));
|
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapB));
|
||||||
@ -96,6 +84,7 @@ public class DepthFirstSearchTest extends TestCase
|
|||||||
assertTrue(dfs.buildTree());
|
assertTrue(dfs.buildTree());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDFSMapDValid()
|
public void testDFSMapDValid()
|
||||||
{
|
{
|
||||||
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapD));
|
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapD));
|
||||||
@ -103,6 +92,7 @@ public class DepthFirstSearchTest extends TestCase
|
|||||||
assertTrue(dfs.buildTree());
|
assertTrue(dfs.buildTree());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDFSMapCInvalid()
|
public void testDFSMapCInvalid()
|
||||||
{
|
{
|
||||||
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapC));
|
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapC));
|
||||||
@ -110,6 +100,7 @@ public class DepthFirstSearchTest extends TestCase
|
|||||||
assertFalse(dfs.buildTree());
|
assertFalse(dfs.buildTree());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDFSMapEInvalid()
|
public void testDFSMapEInvalid()
|
||||||
{
|
{
|
||||||
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapE));
|
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapE));
|
||||||
|
Loading…
Reference in New Issue
Block a user