Пример #1
0
        public void Should_Result_In_A_Empty_Grid_With_Diehard_Seed_At_130th_Tick()
        {
            var grid = @"------X-XX-------X---XXX";

            var generation = new Generation(grid, 3, 8);

            // Run 129 ticks.
            for (int i = 0; i < 129; i++)
                generation = generation.Tick();

            Assert.NotEqual(0, generation.TotalAlive);

            // Run the 130th tick.
            generation = generation.Tick();

            Assert.Equal(0, generation.TotalAlive);
        }
Пример #2
0
        public void Should_Give_Proper_Output_For_Specific_Input(string inputGrid, string outputGrid)
        {
            inputGrid = inputGrid.Trim();
            outputGrid = outputGrid.Trim();

            var generation = new Generation(inputGrid.Replace(Environment.NewLine, ""), inputGrid.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Count(), inputGrid.IndexOf(Environment.NewLine));

            var next = generation.Tick();

            Assert.Equal(outputGrid, next.ToString());
        }
Пример #3
0
        public void Tick_Should_Kill_Of_A_Lone_Cell()
        {
            var generation = new Generation(new Coordinate(1, 1));

            var next = generation.Tick();

            Assert.Equal(0, next.TotalAlive);
        }
Пример #4
0
        public void Tick_Should_Kill_Of_A_Cell_With_More_Than_3_Neighbours()
        {
            var generation = new Generation(new Coordinate(1, 1), new Coordinate(0, 0), new Coordinate(2, 2), new Coordinate(0, 2), new Coordinate(2, 0));

            var next = generation.Tick();

            Assert.Equal(4, next.TotalAlive);
            Assert.False(next.IsAlive(1, 1));
        }
Пример #5
0
        public void Tick_Should_Kill_Of_A_Cell_With_Less_Than_2_Neighbours()
        {
            var generation = new Generation(new Coordinate(1, 1), new Coordinate(2, 2));

            var next = generation.Tick();

            Assert.Equal(0, next.TotalAlive);
        }
Пример #6
0
        public void Tick_Should_Create_A_Cell_With_Exactly_3_Neighbours_If_Already_Dead()
        {
            var generation = new Generation(new Coordinate(0, 1), new Coordinate(1, 1), new Coordinate(2, 1));

            var next = generation.Tick();

            Assert.Equal(3, next.TotalAlive);
            new List<Coordinate> { new Coordinate(1, 0), new Coordinate(1, 1), new Coordinate(1, 2) }.ForEach(c => Assert.True(next.IsAlive(c.X, c.Y)));
        }