public void ChooseWithLastChoiceByOpponentIsNoneReturnsCooperate() { // Arrange var strategy = new NaiveCooperationStrategy(); // Act var choice = strategy.Choose(CooperationChoice.None); // Assert Assert.Equal(CooperationChoice.Cooperate, choice); }
public void StrategyReturnsStrategySuppliedToConstructor() { // Arrange var cooperationStrategy = new NaiveCooperationStrategy(); // Act var cooperationStrategyFitness = new CooperationStrategyFitness(cooperationStrategy, 0); // Assert Assert.Equal(cooperationStrategy, cooperationStrategyFitness.Strategy); }
public void ConstructorWithNullStrategyBThrowsArgumentNullException() { // Arrange var strategyA = new NaiveCooperationStrategy(); CooperationStrategy nullStrategyB = null; var cooperationChoicePayoff = new CooperationChoicesPayoff(); // Act // Assert Assert.Throws<ArgumentNullException>(() => new CooperationStrategyMatchup(strategyA, nullStrategyB, cooperationChoicePayoff)); }
public void CooperationChoicePayoffsReturnsCooperationChoicePayoffsSuppliedToConstructor() { // Arrange var strategyA = new NaiveCooperationStrategy(); var strategyB = new EvilCooperationStrategy(); var cooperationChoicePayoff = new CooperationChoicesPayoff(); // Act var cooperationStrategyMatchup = new CooperationStrategyMatchup(strategyA, strategyB, cooperationChoicePayoff); // Assert Assert.Equal(cooperationChoicePayoff, cooperationStrategyMatchup.CooperationChoicesPayoff); }
public void CooperationStrategyMatchupReturnsCooperationStrategyMatchupSuppliedToConstructor() { // Arrange var strategyA = new NaiveCooperationStrategy(); var strategyB = new EvilCooperationStrategy(); var cooperationChoicePayoff = new CooperationChoicesPayoff(); var matchup = new CooperationStrategyMatchup(strategyA, strategyB, cooperationChoicePayoff); // Act var simulation = new CooperationStrategyMatchupSimulation(matchup); // Assert Assert.Equal(matchup, simulation.Matchup); }
public void PlayReturnsCorrectCooperationStrategyMatchupResultForStrategyB() { // Arrange var strategyA = new NaiveCooperationStrategy(); var strategyB = new EvilCooperationStrategy(); var cooperationChoicePayoff = new CooperationChoicesPayoff(); var cooperationStrategyMatchup = new CooperationStrategyMatchup(strategyA, strategyB, cooperationChoicePayoff); // Act var cooperationStrategyMatchupResult = cooperationStrategyMatchup.Play(); // Assert var correctCooperationStrategyResultForStrategyB = new CooperationStrategyResult { Strategy = strategyB, ChoiceMade = CooperationChoice.Defect, Payoff = CooperationChoicesPayoff.DefaultPayoffForDefectAndCooperate, }; Assert.Equal(correctCooperationStrategyResultForStrategyB, cooperationStrategyMatchupResult.StrategyBResult); }
public void EqualsWithUnequalCooperationChoicesPayoffReturnsFalse() { // Arrange var strategyA = new NaiveCooperationStrategy(); var strategyB = new EvilCooperationStrategy(); var cooperationStrategyMatchup = new CooperationStrategyMatchup(strategyA, strategyB, new CooperationChoicesPayoff()); var unequalCooperationStrategyMatchup = new CooperationStrategyMatchup(strategyA, strategyB, new CooperationChoicesPayoff { PayoffForCooperateAndCooperate = 20 }); // Act var objectsAreEqual = cooperationStrategyMatchup.Equals(unequalCooperationStrategyMatchup); // Assert Assert.False(objectsAreEqual); }
public void EqualsWithEqualStrategyReturnsTrue() { // Arrange var strategy = new NaiveCooperationStrategy(); var cooperationStrategyResult = new CooperationStrategyResult { Strategy = strategy }; object equalCooperationStrategyResult = new CooperationStrategyResult { Strategy = strategy }; // Act var objectsAreEqual = cooperationStrategyResult.Equals(equalCooperationStrategyResult); // Assert Assert.True(objectsAreEqual); }
public void GetHashCodeWithEqualValuesReturnsEqualHashCodes() { // Arrange var strategy = new NaiveCooperationStrategy(); var cooperationStrategyResult = new CooperationStrategyResult { Strategy = strategy, ChoiceMade = CooperationChoice.Defect, Payoff = CooperationChoicesPayoff.DefaultPayoffForDefectAndDefect }; var otherCooperationStrategyResult = new CooperationStrategyResult { Strategy = strategy, ChoiceMade = CooperationChoice.Defect, Payoff = CooperationChoicesPayoff.DefaultPayoffForDefectAndDefect }; // Act var hashCode = cooperationStrategyResult.GetHashCode(); var otherHashCode = otherCooperationStrategyResult.GetHashCode(); // Assert Assert.Equal(hashCode, otherHashCode); }