Add files via upload

This commit is contained in:
fassband
2021-11-19 08:32:32 +01:00
committed by GitHub Enterprise
parent e9a9181cd0
commit f2fe06f720
19 changed files with 8166 additions and 0 deletions
+106
View File
@@ -0,0 +1,106 @@
package ch.zhaw.hexboard;
import java.awt.Point;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/***
* <p>
* This class performs tests for the class {@link Edge}.
* </p>
*
* @author tebe
*
**/
public class EdgeTest {
private Point[] hexagon22 = { new Point(2, 0), new Point(3, 1), new Point(3, 3), new Point(2, 4),
new Point(1, 3), new Point(1, 1) };
private Point[] hexagon75 = { new Point(7, 3), new Point(8, 4), new Point(8, 6), new Point(7, 7),
new Point(6, 6), new Point(6, 4) };
@Test
public void createValidEdge() {
new Edge(new Point(0, 0), new Point(1, 1));
}
@Test
public void edgeEqualityStartEndPointReversed() {
for (int i = 0; i < hexagon22.length - 1; i++) {
assertEquals(new Edge(hexagon22[i], hexagon22[i + 1]),
new Edge(hexagon22[i + 1], hexagon22[i]));
}
for (int i = 0; i < hexagon75.length - 1; i++) {
assertEquals(new Edge(hexagon75[i], hexagon75[i + 1]),
new Edge(hexagon75[i + 1], hexagon75[i]));
}
}
@Test
public void notEquals() {
assertNotEquals(new Edge(hexagon22[0], hexagon22[1]),
new Edge(hexagon22[1], hexagon22[2]));
}
@Test
public void createWithBothArgumentsNull() {
assertThrows(IllegalArgumentException.class, () -> new Edge(null, null));
}
@Test
public void createWithFirstArgumentNull() {
assertThrows(IllegalArgumentException.class, () -> new Edge(null, new Point(1, 0)));
}
@Test
public void createWithSecondArgumentNull() {
assertThrows(IllegalArgumentException.class, () -> new Edge(new Point(1, 0), null));
}
@Test
public void createWithStartAndEndpointIdentical() {
assertThrows(IllegalArgumentException.class, () -> new Edge(hexagon22[0], hexagon22[0]));
}
@Test
public void notAnEdgeHorizontalOddTop() {
assertThrows(IllegalArgumentException.class, () -> new Edge(new Point(5, 7), new Point(7, 7)));
}
@Test
public void notAnEdgeHorizontalOddMiddle() {
assertThrows(IllegalArgumentException.class, () -> new Edge(new Point(3, 2), new Point(5, 2)));
}
@Test
public void notAnEdgeHorizontalOddBottom() {
assertThrows(IllegalArgumentException.class, () -> new Edge(new Point(5, 3), new Point(7, 3)));
}
@Test
public void notAnEdgeHorizontalEvenTop() {
assertThrows(IllegalArgumentException.class, () -> new Edge(new Point(4, 4), new Point(6, 4)));
}
@Test
public void notAnEdgeHorizontalEvenMiddle() {
assertThrows(IllegalArgumentException.class, () -> new Edge(new Point(2, 5), new Point(4, 5)));
}
@Test
public void notAnEdgeHorizontalEvenBottom() {
assertThrows(IllegalArgumentException.class, () -> new Edge(new Point(4, 6), new Point(6, 6)));
}
@Test
public void notAnEdgeVerticalEven() {
assertThrows(IllegalArgumentException.class, () -> new Edge(new Point(7, 7), new Point(7, 3)));
}
@Test
public void notAnEdgeVerticalOdd() {
assertThrows(IllegalArgumentException.class, () -> new Edge(new Point(6, 4), new Point(6, 0)));
}
}
+121
View File
@@ -0,0 +1,121 @@
package ch.zhaw.hexboard;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.awt.Point;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/***
* <p>
* Tests for the class {@link HexBoard}.
* </p>
* @author tebe
*/
public class HexBoardTest {
private HexBoard<String, String, String, String> board;
private Point[] corner;
/**
* Setup for a test - Instantiates a board and adds one field at (7,5).
*
* <pre>
* 0 1 2 3 4 5 6 7 8
* | | | | | | | | | ...
*
* 0----
*
* 1----
*
* 2----
*
* 3---- C
* / \
* 4---- C C
*
* 5---- | F | ...
*
* 6---- C C
* \ /
* 7---- C
* </pre>
*/
@BeforeEach
public void setUp() {
board = new HexBoard<>();
board.addField(new Point(7, 5), "00");
Point[] singleField = { new Point(7, 3), new Point(8, 4), new Point(8, 6), new Point(7, 7),
new Point(6, 6), new Point(6, 4) };
this.corner = singleField;
}
// Edge retrieval
@Test
public void edgeTest() {
for (int i = 0; i < corner.length - 1; i++) {
assertNull(board.getEdge(corner[i], corner[i + 1]));
board.setEdge(corner[i], corner[i + 1], Integer.toString(i));
assertEquals(board.getEdge(corner[i], corner[i + 1]), Integer.toString(i));
}
}
@Test
public void noEdgeCoordinatesTest() {
assertThrows(IllegalArgumentException.class,
() -> board.getEdge(new Point(2, 2), new Point(0, 2)));
}
@Test
public void edgeDoesNotExistTest() {
assertThrows(IllegalArgumentException.class,
() -> board.getEdge(new Point(0, 2), new Point(3, 1)));
}
// Corner retrieval
@Test
public void cornerTest() {
for (Point p : corner) {
assertNull(board.getCorner(p));
board.setCorner(p, p.toString());
assertEquals(board.getCorner(p), p.toString());
}
}
@Test
public void noCornerCoordinateTest() {
assertThrows(IllegalArgumentException.class, () -> board.getCorner(new Point(2, 2)));
}
@Test
public void cornerDoesNotExistTest() {
assertThrows(IllegalArgumentException.class, () -> board.getCorner(new Point(2, 2)));
}
// Field addition/retrieval
@Test
public void fieldAreadyExistsErrorTest() {
board.addField(new Point(2, 2), "22");
assertThrows(IllegalArgumentException.class, () -> board.addField(new Point(2, 2), "22"));
}
@Test
public void fieldRetrievalTest() {
Point field = new Point(2, 2);
board.addField(field, new String("22"));
assertTrue(board.hasField(field));
assertEquals(board.getField(field), "22");
}
@Test
public void fieldRetrievalWrongCoordinatesOutsideTest() {
assertThrows(IllegalArgumentException.class, () -> board.getField(new Point(10, 10)));
}
@Test
public void fieldRetrievalWrongCoordinatesInsideTest() {
assertThrows(IllegalArgumentException.class, () -> board.getField(new Point(2, 2)));
}
}