tests + ado equals override

This commit is contained in:
Janet-Doe
2025-04-16 10:55:27 +02:00
parent 3f06a9eb17
commit 076288a400
9 changed files with 89 additions and 4 deletions

View File

@@ -3,12 +3,57 @@
*/
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 static org.junit.jupiter.api.Assertions.*;
import java.util.List;
import java.util.Objects;
class AppTest {
@Test void appHasAGreeting() {
// App classUnderTest = new App();
// assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
@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();
}
}
}