/// <summary>
        /// Initializes a new instance of the <see cref="CooperationStrategyMatchupSimulationResult"/> class.
        /// </summary>
        /// <param name="matchup">The cooperation strategy matchup.</param>
        /// <param name="matchupResults">The matchup results.</param>
        public CooperationStrategyMatchupSimulationResult(CooperationStrategyMatchup matchup, IList<CooperationStrategyMatchupResult> matchupResults)
        {
            Requires.NotNull(matchup, "matchup");
            Requires.NotNull(matchupResults, "matchupResults");

            this.Matchup = matchup;
            this.MatchupResults = matchupResults;
        }
        public void SimulateWillReturnSimulationResultsWithNumberOfMatchupResultsEqualToSuppliedNumberOfRounds()
        {
            // Arrange
            var matchup = new CooperationStrategyMatchup(new NaiveCooperationStrategy(), new EvilCooperationStrategy(), new CooperationChoicesPayoff());
            var matchupSimulation = new CooperationStrategyMatchupSimulation(matchup);
            const int NumberOfRounds = 20;

            // Act
            var simulationResults = matchupSimulation.Simulate(NumberOfRounds);

            // Assert
            Assert.Equal(NumberOfRounds, simulationResults.MatchupResults.Count);
        }
        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 SimulateWillReturnCorrectMatchupResults()
        {
            // Arrange
            var matchup = new CooperationStrategyMatchup(new TitForTatCooperationStrategy(), new EvilCooperationStrategy(), new CooperationChoicesPayoff());
            var matchupSimulation = new CooperationStrategyMatchupSimulation(matchup);
            const int NumberOfRounds = 2;

            // Act
            var simulationResults = matchupSimulation.Simulate(NumberOfRounds);

            // Assert
            Assert.Equal(CooperationChoice.Cooperate, simulationResults.MatchupResults[0].StrategyAResult.ChoiceMade);
            Assert.Equal(CooperationChoice.Defect, simulationResults.MatchupResults[1].StrategyBResult.ChoiceMade);
        }
        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 SimulateWithNumberOfRoundsEqualToZeroThrowsArgumentException()
        {
            // Arrange
            var matchup = new CooperationStrategyMatchup(new NaiveCooperationStrategy(), new EvilCooperationStrategy(), new CooperationChoicesPayoff());
            var matchupSimulation = new CooperationStrategyMatchupSimulation(matchup);
            const int NumberOfRounds = 0;

            // Act

            // Assert
            Assert.Throws<ArgumentException>(() => matchupSimulation.Simulate(NumberOfRounds));
        }
        public void EqualsWithFlippedStrategiesCooperationStrategyMatchupInstancesReturnsTrue()
        {
            // Arrange
            var cooperationStrategyMatchup = new CooperationStrategyMatchup(
                new NaiveCooperationStrategy(), new EvilCooperationStrategy(), new CooperationChoicesPayoff());
            var otherCooperationStrategyMatchup = new CooperationStrategyMatchup(
                new EvilCooperationStrategy(), new NaiveCooperationStrategy(), new CooperationChoicesPayoff());

            // Act
            var objectsAreEqual = cooperationStrategyMatchup.Equals(otherCooperationStrategyMatchup);

            // Assert
            Assert.True(objectsAreEqual);
        }
        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 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 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 GetHashCodeWithFlippedStrategiesReturnsSameHashCodes()
        {
            // Arrange
            var cooperationStrategyMatchup = new CooperationStrategyMatchup(
                new NaiveCooperationStrategy(), new EvilCooperationStrategy(), new CooperationChoicesPayoff());
            var otherCooperationStrategyMatchup = new CooperationStrategyMatchup(
                new EvilCooperationStrategy(), new NaiveCooperationStrategy(), new CooperationChoicesPayoff());

            // Act
            var hashCode = cooperationStrategyMatchup.GetHashCode();
            var otherHashCode = otherCooperationStrategyMatchup.GetHashCode();

            // Assert
            Assert.Equal(hashCode, otherHashCode);
        }
        public void GetHashCodeWithDifferentStrategyBReturnsDifferentHashCodes()
        {
            // Arrange
            var cooperationStrategyMatchup = new CooperationStrategyMatchup(
                new NaiveCooperationStrategy(), new EvilCooperationStrategy(), new CooperationChoicesPayoff());
            var otherCooperationStrategyMatchup = new CooperationStrategyMatchup(
                new NaiveCooperationStrategy(), new TitForTatCooperationStrategy(), new CooperationChoicesPayoff());

            // Act
            var hashCode = cooperationStrategyMatchup.GetHashCode();
            var otherHashCode = otherCooperationStrategyMatchup.GetHashCode();

            // Assert
            Assert.NotEqual(hashCode, otherHashCode);
        }
        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 EqualsWithSameObjectInstanceReturnsTrue()
        {
            // Arrange
            var cooperationStrategyMatchup = new CooperationStrategyMatchup(
                new NaiveCooperationStrategy(), new EvilCooperationStrategy(), new CooperationChoicesPayoff());

            // Act
            var objectsAreEqual = cooperationStrategyMatchup.Equals((object)cooperationStrategyMatchup);

            // Assert
            Assert.True(objectsAreEqual);
        }
        public void EqualsWithNullObjectReturnsFalse()
        {
            // Arrange
            var cooperationStrategyMatchup = new CooperationStrategyMatchup(
                new NaiveCooperationStrategy(), new EvilCooperationStrategy(), new CooperationChoicesPayoff());
            CooperationStrategyMatchup comparisonCooperationStrategyMatchup = null;

            // Act
            var objectsAreEqual = cooperationStrategyMatchup.Equals((object)comparisonCooperationStrategyMatchup);

            // Assert
            Assert.False(objectsAreEqual);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CooperationStrategyMatchupSimulation"/> class.
        /// </summary>
        /// <param name="matchup">The matchup.</param>
        public CooperationStrategyMatchupSimulation(CooperationStrategyMatchup matchup)
        {
            Requires.NotNull(matchup, "matchup");

            this.Matchup = matchup;
        }