Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lscgh committed Feb 9, 2024
1 parent f4ac6df commit 87b5733
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
45 changes: 45 additions & 0 deletions mavenmcserver/src/test/java/mavenmcserver/game/FieldPointTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package mavenmcserver.game;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class FieldPointTest {

@Test
public void testEquals() {
assertEquals(new FieldPoint(0, 0, 0), new FieldPoint(0, 0, 0));
assertEquals(new FieldPoint(0, 1, 2), new FieldPoint(0, 1, 2));
assertEquals(new FieldPoint(-58, 12, 48), new FieldPoint(-58, 12, 48));
assertEquals(new FieldPoint(-12, 3, 4), new FieldPoint(-12, 3, 4));
assertEquals(new FieldPoint(0, -4, 1), new FieldPoint(0, -4, 1));
assertEquals(new FieldPoint(3, -2, -1), new FieldPoint(3, -2, -1));
}

@Test
public void testOffsetBy() {
assertEquals(new FieldPoint(1, 2, 4), new FieldPoint(0, 0, 0).offsetBy(1, 2, 4));
assertEquals(new FieldPoint(1, 2, 4), new FieldPoint(-1, 3, 2).offsetBy(2, -1, 2));
assertEquals(new FieldPoint(0, 0, 0), new FieldPoint(3, -2, 5).offsetBy(-3, 2, -5));
assertEquals(new FieldPoint(-100, -200, 301), new FieldPoint(-152, 168, 2).offsetBy(52, -368, 299));
}

@Test
public void testHashCode() {
assertEquals(new FieldPoint(0, 1, 2).hashCode(), new FieldPoint(0, 1, 2).hashCode());
assertEquals(new FieldPoint(2, 1, 3).hashCode(), new FieldPoint(2, 1, 3).hashCode());
assertEquals(new FieldPoint(-4, -3, 5).hashCode(), new FieldPoint(-4, -3, 5).hashCode());
}

@Test
public void testCopy() {
FieldPoint point = new FieldPoint(1, 2, 3);
assertEquals(point, point.copy());
assertEquals(point, point.copy());

point = new FieldPoint(-2, 3, 65);
assertEquals(point, point.copy());
assertEquals(point, point.copy());
}

}
18 changes: 18 additions & 0 deletions mavenmcserver/src/test/java/mavenmcserver/game/GameConfigTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mavenmcserver.game;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;
Expand Down Expand Up @@ -40,4 +41,21 @@ public void testValidateNumbers() {

}


@Test
public void testGetLargestDimension() {
assertEquals(5, new GameConfig(null, null, new Vector3i(1, 4, 5), 0).getLargestDimension());
assertEquals(3, new GameConfig(null, null, new Vector3i(3, 2, 1), 0).getLargestDimension());
assertEquals(10, new GameConfig(null, null, new Vector3i(10, 4, 8), 0).getLargestDimension());
assertEquals(0, new GameConfig(null, null, new Vector3i(0, 0, 0), 0).getLargestDimension());
}

@Test
public void testGetSmallestDimension() {
assertEquals(1, new GameConfig(null, null, new Vector3i(1, 4, 5), 0).getSmallestDimension());
assertEquals(1, new GameConfig(null, null, new Vector3i(3, 2, 1), 0).getSmallestDimension());
assertEquals(4, new GameConfig(null, null, new Vector3i(10, 4, 8), 0).getSmallestDimension());
assertEquals(0, new GameConfig(null, null, new Vector3i(0, 0, 0), 0).getSmallestDimension());
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package mavenmcserver.game;

import static java.util.Map.entry;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Map;
import static java.util.Map.entry;

import org.joml.Vector3i;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -64,6 +64,37 @@ public void testStateAt() {

}

@Test
public void testFieldPointIsValid() {

GameState state = new GameState(new Vector3i(3, 3, 3));
assertTrue(state.fieldPointIsValid(new FieldPoint(0, 0, 0)));
assertTrue(state.fieldPointIsValid(new FieldPoint(1, 0, 0)));
assertTrue(state.fieldPointIsValid(new FieldPoint(0, 1, 0)));
assertTrue(state.fieldPointIsValid(new FieldPoint(0, 0, 1)));
assertTrue(state.fieldPointIsValid(new FieldPoint(1, 1, 0)));
assertTrue(state.fieldPointIsValid(new FieldPoint(0, 1, 1)));
assertTrue(state.fieldPointIsValid(new FieldPoint(1, 0, 1)));
assertTrue(state.fieldPointIsValid(new FieldPoint(1, 1, 1)));

assertTrue(state.fieldPointIsValid(new FieldPoint(2, 0, 0)));
assertTrue(state.fieldPointIsValid(new FieldPoint(1, 2, 0)));
assertTrue(state.fieldPointIsValid(new FieldPoint(0, 1, 2)));
assertTrue(state.fieldPointIsValid(new FieldPoint(2, 2, 0)));
assertTrue(state.fieldPointIsValid(new FieldPoint(0, 2, 2)));
assertTrue(state.fieldPointIsValid(new FieldPoint(2, 0, 2)));
assertTrue(state.fieldPointIsValid(new FieldPoint(2, 2, 2)));
assertTrue(state.fieldPointIsValid(new FieldPoint(2, 1, 2)));

assertFalse(state.fieldPointIsValid(new FieldPoint(-1, 0, 0)));
assertFalse(state.fieldPointIsValid(new FieldPoint(0, -1, 0)));
assertFalse(state.fieldPointIsValid(new FieldPoint(0, 0, -1)));
assertFalse(state.fieldPointIsValid(new FieldPoint(3, 0, 0)));
assertFalse(state.fieldPointIsValid(new FieldPoint(0, 0, 5)));
assertFalse(state.fieldPointIsValid(new FieldPoint(-2, 6, 0)));
assertFalse(state.fieldPointIsValid(new FieldPoint(1, 6, 1)));
}


@Test
public void testGetWinnerIfAny() {
Expand Down

0 comments on commit 87b5733

Please sign in to comment.