예제 #1
0
        public void ThrowExceptionIfNumberOfCellsIsZero()
        {
            Ecosystem ecosystem = new Ecosystem();

            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            Assert.Throws <Exception>(() => gameOfLife.Play());
        }
예제 #2
0
        protected bool Equals(Ecosystem other)
        {
            if (this._currentGeneration.Count == other._currentGeneration.Count)
            {
                foreach (var cell in _currentGeneration)
                {
                    if (!other._currentGeneration.Contains(cell))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
예제 #3
0
        public void KeepRevivedCellsWhenYouIntroduceThreeInARow()
        {
            Ecosystem expectedEcosystem = new Ecosystem();

            expectedEcosystem.AddCell(1, 0);
            expectedEcosystem.AddCell(1, 1);
            expectedEcosystem.AddCell(1, -1);

            Ecosystem ecosystem = new Ecosystem();

            ecosystem.AddCell(0, 0);
            ecosystem.AddCell(2, 0);
            ecosystem.AddCell(1, 0);

            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            gameOfLife.Play();

            Assert.Equal(expectedEcosystem, ecosystem);
        }
예제 #4
0
        public void KeepAliveAllCellsWhenFirstGenerationIsASquare()
        {
            Ecosystem expectedEcosystem = new Ecosystem();

            expectedEcosystem.AddCell(0, 0);
            expectedEcosystem.AddCell(0, 1);
            expectedEcosystem.AddCell(1, 1);
            expectedEcosystem.AddCell(1, 0);

            Ecosystem ecosystem = new Ecosystem();

            ecosystem.AddCell(0, 0);
            ecosystem.AddCell(0, 1);
            ecosystem.AddCell(1, 1);
            ecosystem.AddCell(1, 0);

            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            gameOfLife.Play();

            Assert.Equal(expectedEcosystem, ecosystem);
        }
예제 #5
0
        public void ReturnSecondEvolvePatternWhenYouIntroduceABeaconPattern()
        {
            Ecosystem expectedEcosystem = new Ecosystem();

            expectedEcosystem.AddCell(0, 0);
            expectedEcosystem.AddCell(0, 1);
            expectedEcosystem.AddCell(2, 3);
            expectedEcosystem.AddCell(3, 2);
            expectedEcosystem.AddCell(3, 3);
            expectedEcosystem.AddCell(1, 1);
            expectedEcosystem.AddCell(2, 2);
            expectedEcosystem.AddCell(1, 0);



            Ecosystem ecosystem = new Ecosystem();

            ecosystem.AddCell(0, 0);
            ecosystem.AddCell(0, 1);
            ecosystem.AddCell(1, 1);
            ecosystem.AddCell(1, 0);
            ecosystem.AddCell(2, 2);
            ecosystem.AddCell(2, 3);
            ecosystem.AddCell(3, 2);
            ecosystem.AddCell(3, 3);

            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            gameOfLife.Play();

            GameOfLife gameOfLife2 = new GameOfLife(ecosystem);

            gameOfLife2.Play();

            Assert.Equal(expectedEcosystem, ecosystem);
        }
예제 #6
0
 public GameOfLife(Ecosystem ecosystem)
 {
     _ecosystem = ecosystem;
 }
예제 #7
0
 public GameOfLife Play()
 {
     _ecosystem = _ecosystem.NewGeneration();
     return(new GameOfLife(_ecosystem));
 }