package de.schereSteinPapier.domain.impl;
import de.fhdw.gaming.core.domain.DefaultObserverFactoryProvider;
import de.fhdw.gaming.core.domain.GameException;
import de.fhdw.gaming.core.domain.ObserverFactoryProvider;
import de.schereSteinPapier.domain.*;
//import static org.junit.jupiter.api.Assertions.assertThrows;
//import org.junit.jupiter.api.Test;
//import de.fhdw.gaming.core.domain.GameException;
//import de.schereSteinPapier.domain.SSPGameBuilder;
import de.schereSteinPapier.domain.factory.SSPStrategyFactory;
import de.schereSteinPapier.moves.factory.SSPMoveFactory;
import de.schereSteinPapier.moves.impl.SSPDefaultMoveFactory;
import static de.schereSteinPapier.SSPConstants.AuswahlConstants.PAPIER;
import static de.schereSteinPapier.SSPConstants.AuswahlConstants.SCHERE;
import static de.schereSteinPapier.SSPConstants.AuswahlConstants.STEIN;
import de.schereSteinPapier.strategy.SSPSayEquilibriumStrategyFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Tests {@link class SSPGameBuilderImpl}.
*/
class SSPGameBuilderImplTest {
/**
* GameBuilder
*/
private SSPGameBuilderImpl sspGameBuilder;
/**
* Setup
*/
@BeforeEach
void setUp() {
this.sspGameBuilder = new SSPGameBuilderImpl();
}
/**
* Tries to create an SSP game with as much defaults as possible.
*/
@Test
void testCreateGameWithDefaults() throws GameException, InterruptedException {
final SSPGameBuilder builder = new SSPGameBuilderImpl();
final Map<String, Map<String, Double>> possibleOutcomes = new LinkedHashMap<>();
final Map<String, Double> possibleOutcomesPapier = new LinkedHashMap<>();
final Map<String, Double> possibleOutcomesStein = new LinkedHashMap<>();
final Map<String, Double> possibleOutcomesSchere = new LinkedHashMap<>();
possibleOutcomesSchere.put(SCHERE, 0.0);
possibleOutcomesSchere.put(STEIN, -1.0);
possibleOutcomesSchere.put(PAPIER, 1.0);
possibleOutcomesStein.put(SCHERE, 1.0);
possibleOutcomesStein.put(STEIN, 0.0);
possibleOutcomesStein.put(PAPIER, -1.0);
possibleOutcomesPapier.put(SCHERE, 1.0);
possibleOutcomesPapier.put(STEIN, -1.0);
possibleOutcomesPapier.put(PAPIER, 0.0);
possibleOutcomes.put(SCHERE, possibleOutcomesSchere);
possibleOutcomes.put(STEIN, possibleOutcomesStein);
possibleOutcomes.put(PAPIER, possibleOutcomesPapier);
final SSPPlayerBuilder playerBuilderA = builder.createPlayerBuilder().changeName("A")
.changePossibleOutcomes(possibleOutcomes);
final SSPPlayerBuilder playerBuilderB = builder.createPlayerBuilder().changeName("B")
.changePossibleOutcomes(possibleOutcomes);
try (SSPGame game = builder.addPlayer(playerBuilderA.build(),
new SSPStrategyStub(new SSPDefaultMoveFactory()))
.addPlayer(playerBuilderB.build(), new SSPStrategyStub(new SSPDefaultMoveFactory()))
.build(1)) {
assertThat(game.getPlayers().keySet(), containsInAnyOrder("A", "B"));
}
}
/**
* Test for method addPlayer.
*/
@Test
void addPlayer() throws GameException {
final Map<String, Map<String, Double>> possibleOutcomes = createPossibleOutcomes();
SSPPlayer firstPlayer = createPlayer("A", possibleOutcomes);
SSPPlayer secondPlayer = createPlayer("B", possibleOutcomes);
sspGameBuilder.addPlayer(firstPlayer, createEquilibriumStrategy());
sspGameBuilder.addPlayer(secondPlayer, createEquilibriumStrategy());
try {
SSPGame game = sspGameBuilder.build(1);
assertTrue(game.getPlayers().containsKey("A") && game.getPlayers().containsKey("B"));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
Map<String, Map<String, Double>> createPossibleOutcomes() {
final Map<String, Map<String, Double>> possibleOutcomes = new LinkedHashMap<>();
Map<String, Double> possibleOutcomesSchere = new LinkedHashMap<>();
Map<String, Double> possibleOutcomesStein = new LinkedHashMap<>();
Map<String, Double> possibleOutcomesPapier = new LinkedHashMap<>();
possibleOutcomesSchere.put(SCHERE, 0.0);
possibleOutcomesSchere.put(STEIN, 1.0);
possibleOutcomesSchere.put(PAPIER, -1.0);
possibleOutcomesStein.put(STEIN, 0.0);
possibleOutcomesStein.put(SCHERE, -1.0);
possibleOutcomesStein.put(PAPIER, 1.0);
possibleOutcomesPapier.put(PAPIER, 0.0);
possibleOutcomesPapier.put(SCHERE, 1.0);
possibleOutcomesPapier.put(STEIN, -1.0);
possibleOutcomes.put(SCHERE, possibleOutcomesSchere);
possibleOutcomes.put(STEIN, possibleOutcomesStein);
possibleOutcomes.put(PAPIER, possibleOutcomesPapier);
return possibleOutcomes;
}
/**
* Creates a player
*
* @param playerName name of the player
* @param possibleOutcomes Map with all possible outcomes
* @return SSPPlayer
*/
SSPPlayer createPlayer(String playerName, Map<String, Map<String, Double>> possibleOutcomes) {
Parameter 'playerName' is not assigned and could be declared final.
A method argument that is never re-assigned within the method can be declared final.
public void foo1 (String param) { // do stuff with param never assigning it
}
public void foo2 (final String param) { // better, do stuff with param never assigning it
}