예제 #1
0
        public void Constructor_WhenInvoked_PreparesFivePointCorrectly()
        {
            // act
            var fivePoint = new FivePoint();

            int oneSide   = fivePoint.GetPattern().Length;
            int otherSide = fivePoint.GetPattern().Max(x => x.Length);

            // assert
            Assert.IsTrue(
                oneSide == 4 && oneSide == otherSide,
                message: "The five point pattern was not of size 4x4.");

            Assert.IsTrue(
                fivePoint.IsStable,
                message: "The five point pattern was not stable.");

            Assert.AreEqual(
                expected: 1,
                actual: fivePoint.StabilizesAt,
                message: "The five point pattern stabilizes at the wrong time.");

            Assert.AreEqual(
                expected: 4,
                actual: fivePoint.StablePopulation,
                message: "The five point pattern has wrong number of cells in the stable population.");
        }
예제 #2
0
        public void Constructor_GivenSourceUniverse_PreparesCopy()
        {
            // arrange
            var pattern = new FivePoint();
            var other   = new Universe(pattern.GetPattern());

            // act
            var copy = new Universe(other);

            // assert
            Assert.AreEqual(
                expected: 5,
                actual: copy.Population,
                message: "The universe population was not initialized correctly.");

            Assert.IsTrue(
                copy.HasCell(0, 1),
                message: "An expected cell was not found.");

            Assert.IsTrue(
                copy.HasCell(0, 3),
                message: "An expected cell was not found.");

            Assert.IsTrue(
                copy.HasCell(1, 2),
                message: "An expected cell was not found.");

            Assert.IsTrue(
                copy.HasCell(2, 1),
                message: "An expected cell was not found.");

            Assert.IsTrue(
                copy.HasCell(2, 3),
                message: "An expected cell was not found.");
        }
예제 #3
0
        public void Constructor_GivenPattern_PreparesUniverseCorrectly()
        {
            // arrange
            var pattern = new FivePoint();

            // act
            var target = new Universe(pattern.GetPattern());

            // assert
            Assert.AreEqual(
                expected: 5,
                actual: target.Population,
                message: "The universe population was not initialized correctly.");

            Assert.IsTrue(
                target.HasCell(0, 1),
                message: "An expected cell was not found.");

            Assert.IsTrue(
                target.HasCell(0, 3),
                message: "An expected cell was not found.");

            Assert.IsTrue(
                target.HasCell(1, 2),
                message: "An expected cell was not found.");

            Assert.IsTrue(
                target.HasCell(2, 1),
                message: "An expected cell was not found.");

            Assert.IsTrue(
                target.HasCell(2, 3),
                message: "An expected cell was not found.");
        }
예제 #4
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.");
        }