mirror of
https://github.com/toolbox4minecraft/amidst.git
synced 2025-01-09 04:28:44 +08:00
added junit4 as testing dependency, converted coordinate conversion test to junit test
This commit is contained in:
parent
e0a6576631
commit
00eb5f0e6a
6
pom.xml
6
pom.xml
@ -125,5 +125,11 @@
|
||||
<artifactId>jgoogleanalytics</artifactId>
|
||||
<version>0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -38,28 +38,4 @@ public enum CoordinateUtils {
|
||||
private static long modulo(long a, long b) {
|
||||
return ((a % b) + b) % b;
|
||||
}
|
||||
|
||||
// TODO: convert to unit test
|
||||
public static void main(String[] args) {
|
||||
if (ensureCoordinateConversionWorks()) {
|
||||
System.out.println("Coordinate conversion is working!");
|
||||
} else {
|
||||
System.out.println("Coordinate conversion is faulty!");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean ensureCoordinateConversionWorks() {
|
||||
boolean successful = true;
|
||||
for (long inWorld = -1000; inWorld < 1000; inWorld++) {
|
||||
long inFragment = toFragmentRelative(inWorld);
|
||||
long inWorldOfFragment = toFragmentCorner(inWorld);
|
||||
long inWorld2 = toWorld(inWorldOfFragment, inFragment);
|
||||
if (inWorld != inWorld2) {
|
||||
successful = false;
|
||||
System.out.println(inWorld + " != " + inWorld2 + " ("
|
||||
+ inWorldOfFragment + " + " + inFragment + ")");
|
||||
}
|
||||
}
|
||||
return successful;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package amidst.mojangapi.world.coordinates;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CoordinateUtilsTest {
|
||||
@Test
|
||||
public void testCoordinateConversion() {
|
||||
Assert.assertTrue(ensureCoordinateConversionWorks());
|
||||
}
|
||||
|
||||
private static boolean ensureCoordinateConversionWorks() {
|
||||
for (long inWorld = -1000; inWorld < 1000; inWorld++) {
|
||||
long inFragment = CoordinateUtils.toFragmentRelative(inWorld);
|
||||
long inWorldOfFragment = CoordinateUtils.toFragmentCorner(inWorld);
|
||||
long actualInWorld = CoordinateUtils.toWorld(inWorldOfFragment,
|
||||
inFragment);
|
||||
if (inWorld != actualInWorld) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user