public void testMistrustStrategy() {
this.execute(1, new DilemmaMistrustStrategyFactory(), new DilemmaAlwaysConfessStrategyFactory(),
(game, player1, player2, m1, m2) -> assertEquals(this.mf.createNoMove(), m1));
this.execute(9, new DilemmaMistrustStrategyFactory(), new DilemmaAlwaysConfessStrategyFactory(),
(game, player1, player2, m1, m2) -> assertEquals(this.getMove(player2, 1, 0), m1));
}
/**
* Testing the Nasty Strategy.
*/
@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void testNastyStrategy() {
this.execute(10, new DilemmaNastyStrategyFactory(), new DilemmaStaySilentStrategyFactory(),
(game, player1, player2, m1, m2) -> {
assertEquals(game % 3 == 0 ? this.mf.createYesMove() : this.mf.createNoMove(), m1);
});
}
/**
* Game Test for the pavlov strategy.
*/
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
@Test
public void testPavlovStrategy() {
this.execute(10, new DilemmaPavlovStrategyFactory(), new DilemmaStaySilentStrategyFactory(),
(game, player1, player2, m1, m2) -> assertEquals(
game == 1 ? this.mf.createYesMove() : this.getMove(player2, 1, 0), m1));
}
/**
* Game Test for the pavlov strategy.
*/
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
@Test
public void testPavlovAgainstKindStrategy() {
this.execute(10, new DilemmaPavlovStrategyFactory(), new DilemmaAlwaysConfessStrategyFactory(),
(game, player1, player2, m1, m2) -> {
if (game == 1) {
assertEquals(this.mf.createYesMove(), m1);
}
if (game == 2) {
assertEquals(this.mf.createNoMove(), m1);
}
});
}
/**
* Game Test for the periodically kind strategy.
*/
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
@Test
public void testPeriodicallyKindStrategy() {
this.execute(10, new DilemmaPeriodicallyKindStrategyFactory(), new DilemmaStaySilentStrategyFactory(),
(game, player1, player2, m1,
m2) -> assertEquals(game % 3 == 0 ? this.mf.createNoMove() : this.mf.createYesMove(), m1));
}
/**
* Game Test for the prober strategy.
*/
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
@Test
public void testProberStrategy() {
this.execute(1, new DilemmaProberStrategyFactory(), new DilemmaStaySilentStrategyFactory(),
(game, player1, player2, m1, m2) -> assertEquals(this.mf.createYesMove(), m1));
this.execute(2, new DilemmaProberStrategyFactory(), new DilemmaStaySilentStrategyFactory(),
(game, player1, player2, m1, m2) -> assertEquals(this.mf.createNoMove(), m1));
this.execute(7, new DilemmaProberStrategyFactory(), new DilemmaStaySilentStrategyFactory(),
(game, player1, player2, m1, m2) -> assertEquals(this.mf.createNoMove(), m1));
}
/**
* Game Test for the punisher strategy.
*/
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
@Test
public void testPunisherStrategy() {
// TODO Implement
}
/**
* Testing the Spite Strategy against the Always Silent Strategy.
*/
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
@Test
public void testSpiteVsStaySilentStrategy() {
this.execute(10, new DilemmaSpiteStrategyFactory(), new DilemmaStaySilentStrategyFactory(),
(game, player1, player2, m1, m2) -> assertEquals(this.mf.createYesMove(), m1));
}
/**
* Testing the Spite Strategy against the Always Confess Strategy.
*/
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
@Test
public void testSpiteVsAlwaysConfessStrategy() {
this.execute(1, new DilemmaSpiteStrategyFactory(), new DilemmaAlwaysConfessStrategyFactory(),
(game, player1, player2, m1, m2) -> assertEquals(this.mf.createYesMove(), m1));
this.execute(9, new DilemmaSpiteStrategyFactory(), new DilemmaAlwaysConfessStrategyFactory(),
(game, player1, player2, m1, m2) -> assertEquals(this.mf.createNoMove(), m1));
}
/**
* Create a PlayerBuilder which uses the same inputs then before. It stays the same object.
*
* @author Robby Rabbitman
*
*/
private class SamePlayerBuilder implements DilemmaPlayerBuilder {
/**
* proxied pb.
*/
private DilemmaPlayerBuilder pb;
/**
* proxied p.
*/
private ModifiablePlayer player;
/**
* The Constructor.
*
* @param pb
*/
public SamePlayerBuilder(final DilemmaPlayerBuilder pb) {
this.pb = pb;
}
@Override
public DilemmaPlayerBuilder changeName(final String newName) {
return this.pb.changeName(newName);
}
@Override
public DilemmaPlayerBuilder changePossibleOutcomes(
final Map<AbstractDilemmaMove, Map<AbstractDilemmaMove, Double>> possibleOutcomes) {
return this.pb.changePossibleOutcomes(possibleOutcomes);
}
@Override
public DilemmaPlayer build(final DilemmaState state) throws GameException {
if (this.player == null) {
this.player = new ModifiablePlayer(this.pb.build(state), state);
}
this.player.setState(state);
return this.player;
}
@Override
public DilemmaPlayerBuilder defaultPlayerBuilder() {
this.pb = this.pb.defaultPlayerBuilder();
return this;
}
/**
* The Player of the PlayerBuilder.
*
* @return
*/
public DilemmaPlayer getPlayer() {
return this.player;
}
/**
* Testcase to clear pmd violation. Class should be moved into own file!
*/
@Test
public void test() {
assertEquals(1, 1);
}
}
/**
* A Modifiable Player for tests.
*
* @author Robby Rabbitman
*
*/
private class ModifiablePlayer implements DilemmaPlayer {
/**
* proxied p.
*/
private DilemmaPlayer player;
/**
* The GameHistory of a Player.
*/
private final GameHistoryCollection collection;
/**
* The Constructor.
*
* @param player
* @param state
*/
public ModifiablePlayer(final DilemmaPlayer player, final DilemmaState state) {
super();
this.collection = player.getGameHistoryCollection();
this.player = player;
this.player = this.deepCopy(state);
}
@Override
public GameHistoryCollection getGameHistoryCollection() {
return this.collection;
}
@Override
public void setGameHistoryCollection(final GameHistoryCollection gameHistoryCollection) {
this.player.setGameHistoryCollection(gameHistoryCollection);
}
@Override
public String getName() {
return this.player.getName();
}
@Override
public PlayerState getState() {
return this.player.getState();
}
@Override
public Optional<Double> getOutcome() {
return this.player.getOutcome();
}
@Override
public Map<AbstractDilemmaMove, Map<AbstractDilemmaMove, Double>> getPossibleOutcomes() {
return this.player.getPossibleOutcomes();
}
@Override
public final DilemmaPlayer deepCopy(final DilemmaState newGameState) {
return this.player.deepCopy(newGameState);
}
@Override
public void setMove(final AbstractDilemmaMove abstractMove) {
this.player.setMove(abstractMove);
}
@Override
public AbstractDilemmaMove getMove() {
return this.player.getMove();
}
/**
* Set a game state to this player.
*
* @param state
*/
public void setState(final DilemmaState state) {
this.player = this.deepCopy(state);
}
/**
* Testcase to clear pmd violation. Class should be moved into own file!
*/
@Test
public void test() {
assertEquals(1, 1);
}
}
/**
* Callback for writing tests, after a Game is finished.
*
* @author Robby Rabbitman
*
*/
@FunctionalInterface
private interface GameFinishedCallback {
/**
* A Callback can execute a Game(DilemmaGame).
* After this game is finished the Callback will hold all players and there moves.
*
* @param game
* @param p1
* @param p2
* @param m1
* @param m2
*/
void execute(int game, DilemmaPlayer p1, DilemmaPlayer p2, DilemmaMove m1, DilemmaMove m2);
}
}