Files
3DChess/app/src/test/java/chess/AppTest.java
2025-04-16 10:55:27 +02:00

60 lines
1.7 KiB
Java

/*
* This Java source file was generated by the Gradle 'init' task.
*/
package chess;
import chess.ai.DumbAI;
import chess.controller.Command;
import chess.controller.CommandExecutor;
import chess.controller.commands.NewGameCommand;
import chess.controller.commands.UndoCommand;
import chess.controller.event.GameAdaptator;
import chess.model.*;
import chess.model.pieces.*;
import chess.simulator.Simulator;
import chess.view.simplerender.Window;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Objects;
class AppTest {
@Test void functionalRollback(){
Game game = new Game(new ChessBoard());
CommandExecutor commandExecutor = new CommandExecutor(game);
DumbAI ai = new DumbAI(commandExecutor, Color.Black);
commandExecutor.addListener(ai);
DumbAI ai2 = new DumbAI(commandExecutor, Color.White);
commandExecutor.addListener(ai2);
commandExecutor.addListener(new GameAdaptator() {
@Override
public void onGameEnd() {
Command.CommandResult result;
do {
result = commandExecutor.executeCommand(new UndoCommand());
} while (result != Command.CommandResult.NotAllowed);
Game initialGame = new Game(new ChessBoard());
CommandExecutor initialCommandExecutor = new CommandExecutor(initialGame);
commandExecutor.executeCommand(new NewGameCommand());
assert(game.getBoard().equals(initialGame.getBoard()));
}
});
commandExecutor.executeCommand(new NewGameCommand());
}
@Test void functionalRollbacks(){
for (int i=0; i<100; i++) {
functionalRollback();
}
}
}