Beispiel #1
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);
        }
Beispiel #2
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();
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public void Universe_ZipUnzipUniverse_Succeeds()
        {
            var plainData = new[]
            {
                "xx  x ",
                "  xxxx",
                "    xx",
                " x x x",
                "x x x ",
                "  xx  ",
                "      ",
                "   x  "
            };
            var universe = UniverseFactory.GetFromMatrixString(plainData);
            var zipped   = universe.Zip();
            var result   = zipped.UnzipToUniverse();

            result.Should().BeEquivalentTo(universe);
        }
Beispiel #5
0
        public void Universe_ToStringFormString_Succeeds()
        {
            var plainData = new[]
            {
                "xx  x ",
                "  xxxx",
                "    xx",
                " x x x",
                "x x x ",
                "  xx  ",
                "      ",
                "   x  "
            };
            var universe = UniverseFactory.GetFromMatrixString(plainData);
            var text     = universe.ToString();
            var result   = new Universe(text);

            result.Should().BeEquivalentTo(universe);
        }
Beispiel #6
0
        public void Universe_GetFromRleGliderGun_Succeeds()
        {
            var rleData =
                @"x = 36, y = 9, rule = B3/S23
24bo$22bobo$12b2o6b2o12b2o$11bo3bo4b2o12b2o$2o8bo5bo3b2o$2o8bo3bob2o4bobo$10bo5bo7bo$11bo3bo$12b2o!";
            var plainData =
                @"                        x           
                      x x           
            xx      xx            xx
           x   x    xx            xx
xx        x     x   xx              
xx        x   x xx    x x           
          x     x       x           
           x   x                    
            xx                      ";

            var universeFromRle  = UniverseFactory.GetFromRleString(rleData);
            var universeFromText = UniverseFactory.GetFromMatrixString(plainData);

            universeFromRle.Should().BeEquivalentTo(universeFromText);
        }
Beispiel #7
0
        public void UniverseFactory_WithLineArray_ReturnsValidUniverse()
        {
            var lines = new[]
            {
                "  x xx x",
                "xxxxxxxx",
                "x       ",
                "        ",
                "       x"
            };
            var universe = UniverseFactory.GetFromMatrixString(lines);

            for (var y = 0; y < lines.Length; y++)
            {
                var line = lines[y];
                for (var x = 0; x < line.Length; x++)
                {
                    var shouldBeAlive = line[x] != ' ';
                    var isAlive       = universe.IsCellAlive(x, y);
                    shouldBeAlive.Should().Be(isAlive);
                }
            }
        }