Ejemplo n.º 1
0
        public void InitializeFrom_GivenNullPattern_ThrowsException()
        {
            // arrange
            var mockRules = new Mock <RulesBase>(new[] { 1 }, new[] { 2 });
            var game      = new LinqGame(mockRules.Object);

            // act:ish
            Action action = () => game.InitializeFrom(null);

            // assert
            AssertExtension.Throws <ArgumentNullException>(action);
        }
Ejemplo n.º 2
0
        public void InitializeFrom_GivenPattern_InitializesGameCorrectly()
        {
            // arrange
            var mockRules = new Mock <RulesBase>(new[] { 1 }, new[] { 2 });
            var game      = new LinqGame(mockRules.Object);
            var pattern   = new FivePoint();

            // act
            game.InitializeFrom(pattern.GetPattern());

            // assert
            Assert.AreEqual(
                expected: 5,
                actual: game.Population,
                message: "The universe population was not initialized correctly.");
        }
        public void StepForward_GivenFivePointAndEventHandler_ResultsInPopulationOfFourAndFiveRemoved()
        {
            // arrange
            var pattern = new FivePoint();
            var game    = new LinqGame(new StandardRules());

            object            sender    = null;
            GameStepEventArgs eventArgs = null;
            EventHandler <GameStepEventArgs> handler = (object s, GameStepEventArgs e) =>
            {
                sender    = s;
                eventArgs = e;
            };

            game.InitializeFrom(pattern.GetPattern());
            game.GameStepEvent += handler;

            // act
            game.StepForward();

            // assert
            Assert.AreEqual(
                expected: 4,
                actual: game.Population,
                message: "The universe does not contain exactly 4 cells.");

            Assert.AreSame(
                expected: game,
                actual: sender,
                message: "Incorrect sender reference in event handler.");

            Assert.AreEqual(
                expected: 5,
                actual: eventArgs.DeadCells.Count(),
                message: "The set of removed cells does not contain exactly 5 cells.");

            Assert.AreEqual(
                expected: 4,
                actual: eventArgs.NewCells.Count(),
                message: "The set of added cells does not contain exactly 4 cells.");
        }
        public void StepForward_GivenFivePoint_ResultsInPopulationOfFour()
        {
            // arrange
            var pattern = new FivePoint();
            var game    = new LinqGame(new StandardRules());

            game.InitializeFrom(pattern.GetPattern());

            // act
            game.StepForward();

            // assert
            Assert.AreEqual(
                expected: 4,
                actual: game.Population,
                message: "The universe does not contain exactly 4 cells.");

            Assert.AreEqual(
                expected: 1,
                actual: game.Generation,
                message: "The game did not progress by one generation.");
        }