public void Testing_NeighbourCellsForThreexThreeGridRowIndex0AndColIndex2()
        {
            var neighbourCalc = new NeighbourCalculator { Grid = TestObjects.ThreexThreeGrid };
            var neighbours = neighbourCalc.RetrieveNeighbours(0, 2);

            Assert.That(neighbours.Count(), Is.EqualTo(3), "Should have 3 neighbours");
            CollectionAssert.Contains(neighbours, TestObjects.ThreexThreeGrid.Cells.ElementAt(1));
            CollectionAssert.Contains(neighbours, TestObjects.ThreexThreeGrid.Cells.ElementAt(4));
            CollectionAssert.Contains(neighbours, TestObjects.ThreexThreeGrid.Cells.ElementAt(5));
        }
Example #2
0
 static void Main(string[] args)
 {
     //fetch the dependencies - here we just create them
     var neighbourCalculator = new NeighbourCalculator();
     var gameRules = new GameRules(new LiveCellRule(), new DeadCellRule());
     var evolution = new Evolution(neighbourCalculator, gameRules);
     var gridRowColumnParser = new GridRowColumnParser();
     //typically we would create such an object and inject its dependencies
     //using an IoC container
     IGameOfLife gameOfLife = new GameOfLifeUI.GameOfLife(evolution, gridRowColumnParser);
     gameOfLife.Start();
 }
Example #3
0
        static void Main(string[] args)
        {
            //fetch the dependencies - here we just create them
            var neighbourCalculator = new NeighbourCalculator();
            var gameRules           = new GameRules(new LiveCellRule(), new DeadCellRule());
            var evolution           = new Evolution(neighbourCalculator, gameRules);
            var gridRowColumnParser = new GridParser();
            //typically we would create such an object and inject its dependencies
            //using an IoC container

            //Have to reference to via the namespace as the class and namespace are called the same thing.
            GameOfLifeInterface gameOfLife = new GameOfLife.UI.GameOfLife(evolution, gridRowColumnParser);

            gameOfLife.start();
        }
Example #4
0
            public void Should_IndicateIfAllCoords_AreInSimilarDirection(
                string[] coords,
                int direction,
                bool expectedOutcome)
            {
                // Ugly hack to be able to use Direction, which is internal
                // and can't be used as param due to protection level of test..
                var parsedDirection = (Direction)direction;

                var outcome = NeighbourCalculator.AreHits(
                    parsedDirection,
                    coords.ToList());

                Assert.Equal(expectedOutcome, outcome);
            }
Example #5
0
            public void ShouldGet_MaxVerticalNeighbours_FromGivenCoords(
                string[] coords,
                string expectedUp,
                string expectedDown,
                string expectedLeft,
                string expectedRight)
            {
                var neighbours = NeighbourCalculator.GetNeighbours(
                    coords.ToList(),
                    Direction.Vertical,
                    AI_lib.Range.Max);

                Assert.Equal(expectedUp, neighbours.NeighbourUp);
                Assert.Equal(expectedDown, neighbours.NeighbourDown);
                Assert.Equal(expectedLeft, neighbours.NeighbourLeft);
                Assert.Equal(expectedRight, neighbours.NeighbourRight);
            }
Example #6
0
        public void TearDown()
        {
            TestObjects.ThreexThreeGrid.GetCellByIndex(0, 0).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(0, 1).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(0, 2).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(1, 0).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(1, 1).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(1, 2).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(2, 0).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(2, 1).IsAlive = false;
            TestObjects.ThreexThreeGrid.GetCellByIndex(2, 2).IsAlive = false;
            //D D D
            //D D D
            //D D D

            _neighbourCalculator = null;
            _deadCellRule = null;
        }
Example #7
0
 public void SetUp()
 {
     _neighbourCalculator = new NeighbourCalculator { Grid = TestObjects.ThreexThreeGrid };
     _deadCellRule = new DeadCellRule{Grid = TestObjects.ThreexThreeGrid, NeighbourCalculator = _neighbourCalculator};
 }
        public void Test_RetrieveNeighbours_GridIsNotInitialized_ThrowsException()
        {
            var neighbourCalc = new NeighbourCalculator();
            Assert.That(neighbourCalc.Grid, Is.Null);

            Assert.Throws<Exception>(() => neighbourCalc.RetrieveNeighbours(0, 0),
                                     "When the grid is not initialized exception should be thrown.");
        }