Example #1
0
 private void CalculateNextGeneration()
 {
     _universe = GameOfLife.CalculateStep(_universe);
     _generations++;
     SaveToHistory();
     UpdateCounters();
     if (_universe.IsEmpty)
     {
         ToggleTimer();
     }
 }
Example #2
0
        public void GameOfLife_WithExpectedNewborn_Succeeds()
        {
            var startUniverse = UniverseFactory.GetFromMatrixString(new[]
            {
                " x ",
                " xx"
            });
            var expectedUniverse = UniverseFactory.GetFromMatrixString(new[]
            {
                " xx",
                " xx"
            });

            var result = GameOfLife.CalculateStep(startUniverse);

            result.Cells.Should().BeEquivalentTo(expectedUniverse.Cells);
        }
Example #3
0
        public void GameOfLife_WithDyingConfiguration_Succeeds()
        {
            var lines = new[]
            {
                "x        x",
                "         x",
                "   x  ",
                "   x         x ",
                "             x",
                "x",
                "x"
            };
            var startUniverse = UniverseFactory.GetFromMatrixString(lines);

            var result = GameOfLife.CalculateStep(startUniverse);

            result.IsEmpty.Should().BeTrue();
        }
Example #4
0
        public void GameOfLife_WithStableConfiguration_Succeeds()
        {
            var lines = new[]
            {
                "         xx",
                "         xx",
                "   xx  ",
                "   xx         xx ",
                "              xx",
                "xx",
                "xx"
            };
            var startUniverse = UniverseFactory.GetFromMatrixString(lines);

            var result = GameOfLife.CalculateStep(startUniverse);

            result.Cells.Should().BeEquivalentTo(startUniverse.Cells);
        }