Compare commits
10 Commits
ae07b4d719
...
5770d13cdc
| Author | SHA1 | Date |
|---|---|---|
|
|
5770d13cdc | |
|
|
3aa8897ff1 | |
|
|
b56813d6dc | |
|
|
c864f88e1c | |
|
|
d23f7097f7 | |
|
|
69c4e44671 | |
|
|
7ebfecc6c4 | |
|
|
993fa89371 | |
|
|
9e095418a2 | |
|
|
4c58eebc65 |
|
|
@ -33,13 +33,20 @@
|
||||||
<artifactId>chesslib</artifactId>
|
<artifactId>chesslib</artifactId>
|
||||||
<version>1.3.4</version>
|
<version>1.3.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- JUnit 3 (wie im Template, ggf. auf JUnit 4/5 upgraden für moderne Projekte) -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>5.10.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Mockito damit man Controller und Gui besser testen kann-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>5.11.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
package de.hs_mannheim.informatik.chess.test;
|
|
||||||
|
|
||||||
import junit.framework.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unit test for simple App.
|
|
||||||
*/
|
|
||||||
public class AppTest
|
|
||||||
extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Create the test case
|
|
||||||
*
|
|
||||||
* @param testName name of the test case
|
|
||||||
*/
|
|
||||||
public AppTest( String testName )
|
|
||||||
{
|
|
||||||
super( testName );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the suite of tests being tested
|
|
||||||
*/
|
|
||||||
public static TestSuite suite()
|
|
||||||
{
|
|
||||||
return new TestSuite( AppTest.class );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rigourous Test :-)
|
|
||||||
*/
|
|
||||||
public void testApp()
|
|
||||||
{
|
|
||||||
assertTrue( true );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,222 @@
|
||||||
|
package de.hs_mannheim.informatik.chess.test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
import de.hs_mannheim.informatik.chess.model.*;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ModelTest {
|
||||||
|
|
||||||
|
private ChessEngine engine;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() {
|
||||||
|
engine = new ChessEngine(); // Echte Instanz!
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ErkenntObZugLegalOderIllegal()
|
||||||
|
{
|
||||||
|
assertTrue(engine.move(new MoveDTO(6, 4, 4, 4)));
|
||||||
|
|
||||||
|
assertFalse(engine.move(new MoveDTO(7, 0, 5, 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void GibtLegaleMovesAn() {
|
||||||
|
List<MoveDTO> mvs = new ArrayList<>();
|
||||||
|
mvs.add(new MoveDTO(6,4,5,4));
|
||||||
|
mvs.add(new MoveDTO(6,4,4,4));
|
||||||
|
List<MoveDTO> moves = engine.getLegalDestinations("E2");
|
||||||
|
|
||||||
|
assertEquals(2, moves.size());
|
||||||
|
assertTrue(moves.stream().anyMatch(m -> m.getToRow() == 5 && m.getToCol() == 4));
|
||||||
|
assertTrue(moves.stream().anyMatch(m -> m.getToRow() == 4 && m.getToCol() == 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test //Stichprobenartige Kontrolle ob richtige Figur an richtiger Stelle
|
||||||
|
public void BoardWirdRichtigAufgebaut() {
|
||||||
|
BoardDTO board = engine.getBoardAsDTO();
|
||||||
|
PieceDTO a1 = board.getBoard()[7][0];
|
||||||
|
assertEquals("ROOK", a1.getType());
|
||||||
|
assertEquals("WHITE", a1.getColor());
|
||||||
|
|
||||||
|
PieceDTO e1 = board.getBoard()[7][4];
|
||||||
|
assertEquals("KING", e1.getType());
|
||||||
|
assertEquals("WHITE", e1.getColor());
|
||||||
|
|
||||||
|
PieceDTO a8 = board.getBoard()[0][0];
|
||||||
|
assertEquals("ROOK", a8.getType());
|
||||||
|
assertEquals("BLACK", a8.getColor());
|
||||||
|
|
||||||
|
PieceDTO e8 = board.getBoard()[0][4];
|
||||||
|
assertEquals("KING", e8.getType());
|
||||||
|
assertEquals("BLACK", e8.getColor());
|
||||||
|
|
||||||
|
PieceDTO e2 = board.getBoard()[6][4];
|
||||||
|
assertEquals("PAWN", e2.getType());
|
||||||
|
assertEquals("WHITE", e2.getColor());
|
||||||
|
|
||||||
|
PieceDTO d7 = board.getBoard()[1][3];
|
||||||
|
assertEquals("PAWN", d7.getType());
|
||||||
|
assertEquals("BLACK", d7.getColor());
|
||||||
|
|
||||||
|
PieceDTO e4 = board.getBoard()[4][4];
|
||||||
|
assertNull(e4);
|
||||||
|
|
||||||
|
PieceDTO d5 = board.getBoard()[3][3];
|
||||||
|
assertNull(d5);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void speichertMovesRichtigGruppiert() {
|
||||||
|
engine.move(new MoveDTO(6, 6, 4, 6));
|
||||||
|
engine.move(new MoveDTO(1, 4, 3, 4));
|
||||||
|
engine.move(new MoveDTO(7, 6, 5, 5)); //Züge um das speichern zu testen
|
||||||
|
engine.move(new MoveDTO(0, 1, 2, 2));
|
||||||
|
engine.move(new MoveDTO(7, 1, 5, 2));
|
||||||
|
|
||||||
|
|
||||||
|
List<String> gruppiertGespeichert = engine.getMoveListStringsGrouped(); //Moves in Liste gespeichert um zu testen
|
||||||
|
assertTrue(gruppiertGespeichert.size() >= 3, "Zu wenige gespeicherte Gruppen");
|
||||||
|
assertTrue(gruppiertGespeichert.get(0).startsWith("1."));
|
||||||
|
assertTrue(gruppiertGespeichert.get(1).startsWith("2."));
|
||||||
|
assertTrue(gruppiertGespeichert.get(2).startsWith("3."));
|
||||||
|
|
||||||
|
for (int i = 0; i < gruppiertGespeichert.size(); i++) {
|
||||||
|
String[] parts = gruppiertGespeichert.get(i).split(" ");
|
||||||
|
if (i == gruppiertGespeichert.size() - 1) {
|
||||||
|
assertTrue(parts.length == 2 || parts.length == 3);
|
||||||
|
} else {
|
||||||
|
assertEquals(3, parts.length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void erkenntMattKorrekt() {
|
||||||
|
|
||||||
|
assertFalse(engine.isMated()); //<--Test, dass nicht immer alles einfach Matt ist
|
||||||
|
engine.setPositionFromFEN("7k/6Q1/5K2/8/8/8/8/8 b - - 0 1"); //<--Matt position vorbereiten
|
||||||
|
|
||||||
|
System.out.println("Aktueller Spieler: " + engine.getCurrentPlayer());
|
||||||
|
System.out.println("isMated(): " + engine.isMated());
|
||||||
|
|
||||||
|
assertEquals("BLACK", engine.getCurrentPlayer());
|
||||||
|
assertTrue(engine.isMated()); //<Test ob nun spieler Matt ist
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void erkenntPattKorrekt() {
|
||||||
|
|
||||||
|
assertFalse(engine.isStalemate());
|
||||||
|
engine.setPositionFromFEN("7k/5Q2/6K1/8/8/8/8/8 b - - 0 1");
|
||||||
|
|
||||||
|
System.out.println("Aktueller Spieler: " + engine.getCurrentPlayer());
|
||||||
|
System.out.println("isStalemate(): " + engine.isStalemate());
|
||||||
|
|
||||||
|
assertEquals("BLACK", engine.getCurrentPlayer());
|
||||||
|
assertTrue(engine.isStalemate());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void erkenntUnentschieden() {
|
||||||
|
assertFalse(engine.isDraw());
|
||||||
|
engine.setPositionFromFEN("8/8/8/8/8/8/8/4K2k w - - 0 1"); // nur zwei Könige
|
||||||
|
assertTrue(engine.isDraw());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void MethodeGibtRichtigeFigurZurück() {
|
||||||
|
String type = "KING";
|
||||||
|
String color= "WHITE";
|
||||||
|
PieceDTO test = engine.getPieceAt("E1");
|
||||||
|
assertEquals(type, test.getType());
|
||||||
|
assertEquals(color, test.getColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void MethodeGibtRichtigenPlayerZurück() {
|
||||||
|
assertEquals("WHITE", engine.getCurrentPlayer());
|
||||||
|
engine.move(new MoveDTO(6, 4, 4, 4));
|
||||||
|
assertEquals("BLACK", engine.getCurrentPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void MethodeSetztBoardRichtigzurück() {
|
||||||
|
engine.move(new MoveDTO(6,4,4,4)); // e2-e4
|
||||||
|
engine.move(new MoveDTO(1,4,3,4)); // e7-e5
|
||||||
|
engine.setPositionToMoveIndex(1);
|
||||||
|
PieceDTO pawn = engine.getPieceAt("E4");
|
||||||
|
assertNotNull(pawn);
|
||||||
|
assertEquals("PAWN", pawn.getType());
|
||||||
|
assertNull(engine.getPieceAt("E5"));
|
||||||
|
assertEquals(1, engine.getCurrentMoveIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void FigurZurQueenBefördernklappt() {
|
||||||
|
engine.setPositionFromFEN("8/P7/8/8/8/8/8/k6K w - - 0 1"); // Weißer Bauer auf a7, Weiß am Zug
|
||||||
|
boolean moved = engine.moveWithPromotion(new MoveDTO(1, 0, 0, 0), "QUEEN"); // a7-a8=Dame
|
||||||
|
assertTrue(moved);
|
||||||
|
PieceDTO piece = engine.getPieceAt("A8");
|
||||||
|
assertEquals("QUEEN", piece.getType());
|
||||||
|
assertEquals("WHITE", piece.getColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fenAufbauFunktioniert() {
|
||||||
|
// Beispiel-FEN: Weißer König auf e1, schwarze Dame auf d8, schwarzer Bauer auf a7, Rest leer
|
||||||
|
String fen = "3q4/p7/8/8/8/8/8/4K3 w - - 0 1";
|
||||||
|
engine.setPositionFromFEN(fen);
|
||||||
|
|
||||||
|
// Kontrolliere schwarze Dame auf d8 (0,3)
|
||||||
|
PieceDTO d8 = engine.getPieceAt("D8");
|
||||||
|
assertEquals("QUEEN", d8.getType());
|
||||||
|
assertEquals("BLACK", d8.getColor());
|
||||||
|
|
||||||
|
// Kontrolliere schwarzen Bauern auf a7 (1,0)
|
||||||
|
PieceDTO a7 = engine.getPieceAt("A7");
|
||||||
|
assertEquals("PAWN", a7.getType());
|
||||||
|
assertEquals("BLACK", a7.getColor());
|
||||||
|
|
||||||
|
// Kontrolliere weißen König auf e1 (7,4)
|
||||||
|
PieceDTO e1 = engine.getPieceAt("E1");
|
||||||
|
assertEquals("KING", e1.getType());
|
||||||
|
assertEquals("WHITE", e1.getColor());
|
||||||
|
|
||||||
|
// Leeres Feld testen: e2 (6,4)
|
||||||
|
PieceDTO e2 = engine.getPieceAt("E2");
|
||||||
|
assertNull(e2);
|
||||||
|
|
||||||
|
// Leeres Feld testen: h5 (3,7)
|
||||||
|
PieceDTO h5 = engine.getPieceAt("H5");
|
||||||
|
assertNull(h5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void timerWirdRichtigErstellt() {
|
||||||
|
engine.initTimers(5, 30);
|
||||||
|
assertEquals(330, engine.getWhiteTimer().getSecondsLeft());
|
||||||
|
assertEquals(330, engine.getBlackTimer().getSecondsLeft());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>de.hs-mannheim.informatik.schach</groupId>
|
||||||
|
<artifactId>schach</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<name>schach</name>
|
||||||
|
<description>A simple schach.</description>
|
||||||
|
<url>http://www.example.com</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Schachlib (bhlangonijr) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.bhlangonijr</groupId>
|
||||||
|
<artifactId>chesslib</artifactId>
|
||||||
|
<version>1.3.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>5.10.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- Mockito damit man Controller und Gui besser testen kann-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>5.11.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>3.12.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.4.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>3.1.2</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
|
</project>
|
||||||
Loading…
Reference in New Issue