Refactored and updated to JUnit 5. Fixed biome selector.

This commit is contained in:
Harrison Deng 2020-04-20 18:54:49 -05:00
parent 78cd32106f
commit c6001bdfea
11 changed files with 83 additions and 92 deletions

38
pom.xml
View File

@ -12,20 +12,12 @@
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</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>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
@ -34,19 +26,19 @@
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</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>
<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>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -4,7 +4,7 @@ import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.java.JavaPlugin;
import ca.recrown.islandsurvivalcraft.worldgen.IslandSurvivalCraftWorldGenerator;
import ca.recrown.islandsurvivalcraft.worldgeneration.IslandSurvivalCraftWorldGenerator;
public class IslandSurvivalCraft extends JavaPlugin {
IslandSurvivalCraftWorldGenerator generator;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.worldgen;
package ca.recrown.islandsurvivalcraft.worldgeneration;
import java.util.Random;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.worldgen;
package ca.recrown.islandsurvivalcraft.worldgeneration;
import org.bukkit.World;
import org.bukkit.block.Biome;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.worldgen;
package ca.recrown.islandsurvivalcraft.worldgeneration;
import java.util.ArrayList;
import java.util.HashMap;
@ -114,26 +114,35 @@ 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) {
String biomeName = biome.name().toLowerCase();
if (biomeName.endsWith("hills") || biomeName.endsWith("beach") || biomeName.endsWith("shore")) {
String biomeTypeName = biomeName;
biomeTypeName = biomeTypeName.replace("hills", "");
biomeTypeName = biomeTypeName.replace("beach", "");
biomeTypeName = biomeTypeName.replace("shore", "");
biomeTypeName = biomeTypeName.substring(0, biomeTypeName.length() - 2);
biomeTypeName = biomeTypeName.replace("_hills", "");
biomeTypeName = biomeTypeName.replace("_beach", "");
biomeTypeName = biomeTypeName.replace("_shore", "");
for (Entry<Biome, Float> entry : lands.entrySet()) {
if (entry.getKey().name().startsWith(biomeTypeName)) {
if (entry.getKey().name().toLowerCase().startsWith(biomeTypeName)) {
return entry.getValue();
}
}
}
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();
if (biomeName.contains("jungle")) {
if (biomeName.contains("modified")) {
@ -146,6 +155,12 @@ public class BiomeSelector {
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) {
String biomeName = from.name().toLowerCase();
if (biomeName.contains("mushroom")) {
@ -153,12 +168,17 @@ public class BiomeSelector {
} else if (biomeName.contains("mountains")) {
return Biome.STONE_SHORE;
}
if (temperature >= 0.8) {
return Biome.BEACH;
if (temperature < 0.05) {
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) {
ArrayList<Biome> biomes = null;
if (temperature <= 0.05f) {
@ -174,6 +194,11 @@ public class BiomeSelector {
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) {
ArrayList<Biome> biomes = null;
if (temperature <= 0.00f) {

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.worldgen;
package ca.recrown.islandsurvivalcraft.worldgeneration;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.worldgen;
package ca.recrown.islandsurvivalcraft.worldgeneration;
import java.util.Random;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.worldgen;
package ca.recrown.islandsurvivalcraft.worldgeneration;
import java.util.Random;

View File

@ -1,4 +1,4 @@
package ca.recrown.islandsurvivalcraft.worldgen;
package ca.recrown.islandsurvivalcraft.worldgeneration;
import java.util.Random;

View File

@ -1,40 +1,23 @@
package ca.recrown.islandsurvivalcraft;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
/**
* Unit test for simple App.
*/
public class UtilitiesTest
extends TestCase
{
/**
* 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 );
}
@TestInstance(Lifecycle.PER_CLASS)
public class UtilitiesTest {
/**
* Basic hashmap inversion test.
*/
@Test
public void testInvertHashMap()
{
HashMap<String, Integer> hashMap = new HashMap<>();

View File

@ -1,14 +1,19 @@
package ca.recrown.islandsurvivalcraft.pathfinding;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
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.
*/
public class DepthFirstSearchTest extends TestCase
{
@TestInstance(Lifecycle.PER_CLASS)
public class DepthFirstSearchTest {
private class Validator implements CoordinateValidatable {
private boolean[][] map;
@ -59,29 +64,11 @@ public class DepthFirstSearchTest extends TestCase
{true, false, false, false},
};
/**
* Create the test case
*
* @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();
@BeforeAll
protected void setUp() {
}
@Test
public void testDFSMapAValid()
{
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapA));
@ -89,6 +76,7 @@ public class DepthFirstSearchTest extends TestCase
assertTrue(dfs.buildTree());
}
@Test
public void testDFSMapBValid()
{
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapB));
@ -96,6 +84,7 @@ public class DepthFirstSearchTest extends TestCase
assertTrue(dfs.buildTree());
}
@Test
public void testDFSMapDValid()
{
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapD));
@ -103,6 +92,7 @@ public class DepthFirstSearchTest extends TestCase
assertTrue(dfs.buildTree());
}
@Test
public void testDFSMapCInvalid()
{
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapC));
@ -110,6 +100,7 @@ public class DepthFirstSearchTest extends TestCase
assertFalse(dfs.buildTree());
}
@Test
public void testDFSMapEInvalid()
{
DepthFirstSearch dfs = new DepthFirstSearch(new Validator(mapE));