예제 #1
0
            public void GliderMovesBoundsUp()
            {
                var initial = new[]
                {
                    1, 1, 1,
                    0, 0, 1,
                    0, 1, 0,
                };
                var step1 = new[]
                {
                    0, 1, 0,
                    0, 1, 1,
                    1, 0, 1,
                    0, 0, 0,
                };

                var universe = new Universe(3, 3);

                universe.SetUniverse(initial);

                universe.Tick();

                UniverseAssert.Equal(step1, universe);
                UniverseAssert.BoundsEqual(-1, -2, 3, 4, universe);
            }
예제 #2
0
            public void BarOscillates()
            {
                var step1 = new[]
                {
                    0, 0, 0, 0, 0,
                    0, 0, 1, 0, 0,
                    0, 0, 1, 0, 0,
                    0, 0, 1, 0, 0,
                    0, 0, 0, 0, 0,
                };
                var step2 = new[]
                {
                    0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0,
                    0, 1, 1, 1, 0,
                    0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0,
                };

                var universe = new Universe(5, 5);

                universe.SetUniverse(step1);

                var changed = universe.Tick();

                Assert.True(changed);

                UniverseAssert.Equal(step2, universe);

                changed = universe.Tick();
                Assert.True(changed);

                UniverseAssert.Equal(step1, universe);
            }
예제 #3
0
            public void CellWithFourNeighborsStaysAlive()
            {
                var initial = new[]
                {
                    0, 0, 0, 0, 0,
                    0, 0, 1, 0, 0,
                    0, 1, 1, 1, 0,
                    0, 0, 1, 0, 0,
                    0, 0, 0, 0, 0,
                };

                var universe = new Universe(5, 5);

                universe.SetUniverse(initial);

                var changed = universe.Tick();

                Assert.True(changed);
                var expected = new[]
                {
                    0, 0, 0, 0, 0,
                    0, 1, 1, 1, 0,
                    0, 1, 0, 1, 0,
                    0, 1, 1, 1, 0,
                    0, 0, 0, 0, 0,
                };

                UniverseAssert.Equal(expected, universe);
            }
예제 #4
0
            public void IndexerChangesBounds(int x, int y, int minX, int minY, int width, int height)
            {
                var universe = new Universe(3, 3);

                universe[x, y] = CellState.Alive;

                UniverseAssert.BoundsEqual(minX, minY, width, height, universe);
            }
예제 #5
0
            public void GliderMovesBoundsMultipleTimes()
            {
                var initial = new[]
                {
                    0, 1, 0,
                    0, 0, 1,
                    1, 1, 1,
                };
                var step1 = new[]
                {
                    0, 0, 0,
                    1, 0, 1,
                    0, 1, 1,
                    0, 1, 0,
                };
                var step2 = new[]
                {
                    0, 0, 0,
                    0, 0, 1,
                    1, 0, 1,
                    0, 1, 1,
                };
                var step3 = new[]
                {
                    0, 0, 0, 0,
                    0, 1, 0, 0,
                    0, 0, 1, 1,
                    0, 1, 1, 0,
                };

                var universe = new Universe(3, 3);

                universe.SetUniverse(initial);

                universe.Tick();
                UniverseAssert.Equal(step1, universe);
                UniverseAssert.BoundsEqual(-1, -1, 3, 4, universe);

                universe.Tick();
                UniverseAssert.Equal(step2, universe);
                UniverseAssert.BoundsEqual(-1, -1, 3, 4, universe);

                universe.Tick();
                UniverseAssert.Equal(step3, universe);
                UniverseAssert.BoundsEqual(-1, -1, 4, 4, universe);
            }
예제 #6
0
            public void DiamondPatternStaysTheSame()
            {
                var initial = new[]
                {
                    0, 0, 0, 0, 0, 0,
                    0, 0, 1, 1, 0, 0,
                    0, 1, 0, 0, 1, 0,
                    0, 0, 1, 1, 0, 0,
                    0, 0, 0, 0, 0, 0,
                };

                var universe = new Universe(6, 5);

                universe.SetUniverse(initial);

                var changed = universe.Tick();

                Assert.False(changed);
                UniverseAssert.Equal(initial, universe);
            }
예제 #7
0
            public void CellWithOnlyThreeNeighborsStaysAlive()
            {
                var initial = new[]
                {
                    0, 0, 0, 0, 0,
                    0, 1, 1, 0, 0,
                    0, 1, 1, 0, 0,
                    0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0,
                };

                var universe = new Universe(5, 5);

                universe.SetUniverse(initial);

                var changed = universe.Tick();

                Assert.False(changed);
                UniverseAssert.Equal(initial, universe);
            }