/* * This Java source file was generated by the Gradle 'init' task. */ package chess; import org.junit.jupiter.api.Test; 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.Color; import chess.model.Game; class AppTest { @Test void functionalRollback(){ Game game = new Game(); 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(); CommandExecutor initialCommandExecutor = new CommandExecutor(initialGame); initialCommandExecutor.executeCommand(new NewGameCommand()); assert(game.getBoard().equals(initialGame.getBoard())); } }); commandExecutor.executeCommand(new NewGameCommand()); } @Test void functionalRollbacks(){ for (int i=0; i<100; i++) { functionalRollback(); } } }