public void DefaultConstructorUsesDefaultCooperationChoicesPayoffThrowsException() { // Arrange var defaultCooperationChoicesPayoff = new CooperationChoicesPayoff(); // Act var cooperationStrategiesFitnessEvaluator = new CooperationStrategiesFitnessEvaluator(); // Assert Assert.Equal(defaultCooperationChoicesPayoff, cooperationStrategiesFitnessEvaluator.CooperationChoicesPayoff); }
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 CalculatePayoffWithChangedPayoffForCooperationChoiceIsDefectAndOtherCooperationChoiceIsDefectReturnsCorrectPayoff() { // Arrange var cooperationChoicesPayoff = new CooperationChoicesPayoff(); const int NewPayoffForDefectAndDefect = 2 * CooperationChoicesPayoff.DefaultPayoffForDefectAndDefect; // Act cooperationChoicesPayoff.PayoffForDefectAndDefect = NewPayoffForDefectAndDefect; var payoff = cooperationChoicesPayoff.Calculate(CooperationChoice.Defect, CooperationChoice.Defect); // Assert Assert.Equal(NewPayoffForDefectAndDefect, payoff); }
public void CalculatePayoffWithChangedPayoffForCooperationChoiceIsCooperateAndOtherCooperationChoiceIsCooperateReturnsCorrectPayoff() { // Arrange var cooperationChoicesPayoff = new CooperationChoicesPayoff(); const int NewPayoffForCooperateAndCooperate = 2 * CooperationChoicesPayoff.DefaultPayoffForCooperateAndCooperate; // Act cooperationChoicesPayoff.PayoffForCooperateAndCooperate = NewPayoffForCooperateAndCooperate; var payoff = cooperationChoicesPayoff.Calculate(CooperationChoice.Cooperate, CooperationChoice.Cooperate); // Assert Assert.Equal(NewPayoffForCooperateAndCooperate, payoff); }
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 EqualsWithEqualObjectReturnsTrue() { // Arrange var cooperationChoicesPayoff = new CooperationChoicesPayoff(); var equalCooperationChoicesPayoff = new CooperationChoicesPayoff(); // Act var objectsAreEqual = cooperationChoicesPayoff.Equals((object)equalCooperationChoicesPayoff); // Assert Assert.True(objectsAreEqual); }
public void PlayWithLastMatchupResultReturnsCorrectCooperationStrategyMatchupResultForStrategyB() { // Arrange var strategyA = new TitForTatCooperationStrategy(); var strategyB = new TitForTatCooperationStrategy(); var cooperationChoicePayoff = new CooperationChoicesPayoff(); var cooperationStrategyMatchup = new CooperationStrategyMatchup(strategyA, strategyB, cooperationChoicePayoff); var lastMatchupResult = new CooperationStrategyMatchupResult( new CooperationStrategyResult { Strategy = strategyA, ChoiceMade = CooperationChoice.Cooperate, Payoff = cooperationChoicePayoff.Calculate( CooperationChoice.Cooperate, CooperationChoice.Cooperate), }, new CooperationStrategyResult { Strategy = strategyB, ChoiceMade = CooperationChoice.Cooperate, Payoff = cooperationChoicePayoff.Calculate( CooperationChoice.Cooperate, CooperationChoice.Cooperate), }); // Act var cooperationStrategyMatchupResult = cooperationStrategyMatchup.Play(lastMatchupResult); // Assert var correctCooperationStrategyResultForStrategyB = new CooperationStrategyResult { Strategy = strategyB, ChoiceMade = CooperationChoice.Cooperate, Payoff = CooperationChoicesPayoff.DefaultPayoffForCooperateAndCooperate }; Assert.Equal(correctCooperationStrategyResultForStrategyB, cooperationStrategyMatchupResult.StrategyBResult); }
public void PlayWithNullLastMatchupResultThrowsArgumentNullException() { // Arrange var strategyA = new TitForTatCooperationStrategy(); var strategyB = new TitForTatCooperationStrategy(); var cooperationChoicePayoff = new CooperationChoicesPayoff(); var cooperationStrategyMatchup = new CooperationStrategyMatchup(strategyA, strategyB, cooperationChoicePayoff); CooperationStrategyMatchupResult nullLastMatchupResult = null; // Act // Assert Assert.Throws<ArgumentNullException>(() => cooperationStrategyMatchup.Play(nullLastMatchupResult)); }
public void EqualsWithUnequalStrategyBReturnsFalse() { // Arrange var strategyA = new EvilCooperationStrategy(); var cooperationChoicesPayoff = new CooperationChoicesPayoff(); var cooperationStrategyMatchup = new CooperationStrategyMatchup(strategyA, new NaiveCooperationStrategy(), cooperationChoicesPayoff); var unequalCooperationStrategyMatchup = new CooperationStrategyMatchup(strategyA, new EvilCooperationStrategy(), cooperationChoicesPayoff); // Act var objectsAreEqual = cooperationStrategyMatchup.Equals(unequalCooperationStrategyMatchup); // Assert Assert.False(objectsAreEqual); }
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 CalculatePayoffWithCooperationChoiceIsCooperateAndOtherCooperationChoiceIsCooperateReturnsCorrectPayoff() { // Arrange var cooperationChoicesPayoff = new CooperationChoicesPayoff(); // Act var payoff = cooperationChoicesPayoff.Calculate(CooperationChoice.Cooperate, CooperationChoice.Cooperate); // Assert Assert.Equal(CooperationChoicesPayoff.DefaultPayoffForCooperateAndCooperate, payoff); }
public void EqualsWithNullObjectReturnsFalse() { // Arrange var cooperationChoicesPayoff = new CooperationChoicesPayoff(); CooperationChoicesPayoff comparisonCooperationChoicesPayoff = null; // Act var objectsAreEqual = cooperationChoicesPayoff.Equals((object)comparisonCooperationChoicesPayoff); // Assert Assert.False(objectsAreEqual); }
public void GetHashCodeWithUnchangedNewInstancesReturnsEqualHashCodes() { // Arrange var cooperationChoicesPayoff = new CooperationChoicesPayoff(); var otherCooperationChoicesPayoff = new CooperationChoicesPayoff(); // Act var hashCode = cooperationChoicesPayoff.GetHashCode(); var otherHashCode = otherCooperationChoicesPayoff.GetHashCode(); // Assert Assert.Equal(hashCode, otherHashCode); }
public void ConstructorInitializesPayoffForDefectAndDefectToDefaultValue() { // Arrange // Act var cooperationChoicesPayoff = new CooperationChoicesPayoff(); // Assert Assert.Equal(CooperationChoicesPayoff.DefaultPayoffForDefectAndDefect, cooperationChoicesPayoff.PayoffForDefectAndDefect); }
public void GetHashCodeWithEqualValuesReturnsEqualHashCodes() { // Arrange var cooperationChoicesPayoff = new CooperationChoicesPayoff { PayoffForCooperateAndCooperate = CooperationChoicesPayoff.DefaultPayoffForCooperateAndCooperate, PayoffForCooperateAndDefect = CooperationChoicesPayoff.DefaultPayoffForCooperateAndDefect, PayoffForDefectAndCooperate = CooperationChoicesPayoff.DefaultPayoffForDefectAndCooperate, PayoffForDefectAndDefect = CooperationChoicesPayoff.DefaultPayoffForDefectAndDefect, }; var otherCooperationChoicesPayoff = new CooperationChoicesPayoff { PayoffForCooperateAndCooperate = CooperationChoicesPayoff.DefaultPayoffForCooperateAndCooperate, PayoffForCooperateAndDefect = CooperationChoicesPayoff.DefaultPayoffForCooperateAndDefect, PayoffForDefectAndCooperate = CooperationChoicesPayoff.DefaultPayoffForDefectAndCooperate, PayoffForDefectAndDefect = CooperationChoicesPayoff.DefaultPayoffForDefectAndDefect, }; // Act var hashCode = cooperationChoicesPayoff.GetHashCode(); var otherHashCode = otherCooperationChoicesPayoff.GetHashCode(); // Assert Assert.Equal(hashCode, otherHashCode); }
public void GetHashCodeWithDifferentPayoffForDefectAndDefectReturnsDifferentHashCodes() { // Arrange var cooperationChoicesPayoff = new CooperationChoicesPayoff { PayoffForDefectAndDefect = CooperationChoicesPayoff.DefaultPayoffForDefectAndDefect, }; var otherCooperationChoicesPayoff = new CooperationChoicesPayoff { PayoffForDefectAndDefect = CooperationChoicesPayoff.DefaultPayoffForDefectAndDefect + 1, }; // Act var hashCode = cooperationChoicesPayoff.GetHashCode(); var otherHashCode = otherCooperationChoicesPayoff.GetHashCode(); // Assert Assert.NotEqual(hashCode, otherHashCode); }
public void EqualsWithUnequalPayoffForDefectAndDefectReturnsFalse() { // Arrange var cooperationChoicesPayoff = new CooperationChoicesPayoff { PayoffForDefectAndDefect = 1 }; var otherCooperationChoicesPayoff = new CooperationChoicesPayoff { PayoffForDefectAndDefect = 2 }; // Act var objectsAreEqual = cooperationChoicesPayoff.Equals(otherCooperationChoicesPayoff); // Assert Assert.False(objectsAreEqual); }
public void EqualsWithUnchangedNewObjectInstancesReturnsTrue() { // Arrange var cooperationChoicesPayoff = new CooperationChoicesPayoff(); var otherCooperationChoicesPayoff = new CooperationChoicesPayoff(); // Act var objectsAreEqual = cooperationChoicesPayoff.Equals((object)otherCooperationChoicesPayoff); // Assert Assert.True(objectsAreEqual); }
public void EqualsWithSameObjectInstanceReturnsTrue() { // Arrange var cooperationChoicesPayoff = new CooperationChoicesPayoff(); // Act var objectsAreEqual = cooperationChoicesPayoff.Equals((object)cooperationChoicesPayoff); // Assert Assert.True(objectsAreEqual); }