public void SetRandomCells_EmptyRGBGrid_GridHasSomeCellsInEachState()
        {
            var grid = new RGBGrid(100, false);

            int redCellsBefore   = GridTestHelper.GetStateCount(grid, State.RED);
            int greenCellsBefore = GridTestHelper.GetStateCount(grid, State.GREEN);
            int blueCellsBefore  = GridTestHelper.GetStateCount(grid, State.BLUE);
            int deadCellsBefore  = GridTestHelper.GetStateCount(grid, State.DEAD);

            Assert.AreEqual(redCellsBefore, 0);
            Assert.AreEqual(greenCellsBefore, 0);
            Assert.AreEqual(blueCellsBefore, 0);
            Assert.AreEqual(deadCellsBefore, 10000);

            grid.SetRandomInitialCells();

            int redCellsAfter   = GridTestHelper.GetStateCount(grid, State.RED);
            int greenCellsAfter = GridTestHelper.GetStateCount(grid, State.GREEN);
            int blueCellsAfter  = GridTestHelper.GetStateCount(grid, State.BLUE);
            int deadCellsAfter  = GridTestHelper.GetStateCount(grid, State.DEAD);

            Assert.IsTrue(redCellsAfter > 0);
            Assert.IsTrue(greenCellsAfter > 0);
            Assert.IsTrue(blueCellsAfter > 0);
            Assert.IsTrue(deadCellsAfter > 0);
        }
        public void Clear_RGBGridWithLiveCells_AllCellsBecomeDead()
        {
            var grid = new RGBGrid(4, false);

            var coords = new Dictionary <Point, State>
            {
                { new Point {
                      X = 1, Y = 1
                  }, State.RED },
                { new Point {
                      X = 1, Y = 2
                  }, State.GREEN },
                { new Point {
                      X = 3, Y = 3
                  }, State.BLUE }
            };

            grid.SetInitialCells(coords);

            int deadCellsBefore = GridTestHelper.GetStateCount(grid, State.DEAD);

            Assert.AreEqual(deadCellsBefore, 13);

            grid.Clear();

            var deadCellsAfter = GridTestHelper.GetStateCount(grid, State.DEAD);

            Assert.AreEqual(deadCellsAfter, grid.Data.Length);
        }
        public void RGBGrid_NewCyclicRGBGrid_InitializesCellsAsDead()
        {
            var grid      = new RGBGrid(4, true);
            int deadCells = GridTestHelper.GetStateCount(grid, State.DEAD);

            Assert.AreEqual(deadCells, grid.Data.Length);
        }
        public void SetInitialCells_EmptyRGBGrid_OnlyChosenCellsStateChanged()
        {
            var grid = new RGBGrid(4, false);

            int deadCellsBefore = GridTestHelper.GetStateCount(grid, State.DEAD);

            Assert.AreEqual(deadCellsBefore, grid.Data.Length);

            // set chosen cells
            var coords = new Dictionary <Point, State>
            {
                { new Point {
                      X = 1, Y = 1
                  }, State.RED },
                { new Point {
                      X = 1, Y = 2
                  }, State.GREEN },
                { new Point {
                      X = 1, Y = 3
                  }, State.BLUE },
            };

            grid.SetInitialCells(coords);

            int redCellsAfter   = GridTestHelper.GetStateCount(grid, State.RED);
            int greenCellsAfter = GridTestHelper.GetStateCount(grid, State.GREEN);
            int blueCellsAfter  = GridTestHelper.GetStateCount(grid, State.BLUE);
            int deadCellsAfter  = GridTestHelper.GetStateCount(grid, State.DEAD);

            Assert.AreEqual(redCellsAfter, 1);
            Assert.AreEqual(greenCellsAfter, 1);
            Assert.AreEqual(blueCellsAfter, 1);
            Assert.AreEqual(deadCellsAfter, 13);
        }
        public void Cycle_ScatteredLoneCells_AllCellsDie()
        {
            var grid   = new Grid(10);
            var coords = new Dictionary <Point, State>
            {
                { new Point {
                      X = 9, Y = 8
                  }, State.ALIVE },
                { new Point {
                      X = 1, Y = 2
                  }, State.ALIVE },
                { new Point {
                      X = 5, Y = 4
                  }, State.ALIVE },
                { new Point {
                      X = 7, Y = 1
                  }, State.ALIVE }
            };

            grid.SetInitialCells(coords);

            grid.Cycle();

            Assert.AreEqual(GridTestHelper.GetStateCount(grid, State.ALIVE), 0);
            Assert.AreEqual(GridTestHelper.GetStateCount(grid, State.DEAD), 100);
        }
        public void Cycle_4CellBlock_RemainsStable4CellBlock()
        {
            var grid   = new Grid(10);
            var coords = new Dictionary <Point, State>
            {
                { new Point {
                      X = 4, Y = 4
                  }, State.ALIVE },
                { new Point {
                      X = 4, Y = 5
                  }, State.ALIVE },
                { new Point {
                      X = 5, Y = 4
                  }, State.ALIVE },
                { new Point {
                      X = 5, Y = 5
                  }, State.ALIVE }
            };

            grid.SetInitialCells(coords);

            grid.Cycle();
            // check block remains live, and no other cells become live
            var expectedLiveCellsBlock = new List <Cell> {
                grid.Data[4, 4], grid.Data[4, 5], grid.Data[5, 4], grid.Data[5, 5]
            };
            var numLiveCellsInBlock = expectedLiveCellsBlock.Where(cell => cell.CurrentState == State.ALIVE).Count();

            Assert.IsTrue(numLiveCellsInBlock == 4);

            Assert.AreEqual(GridTestHelper.GetStateCount(grid, State.ALIVE), 4);
            Assert.AreEqual(GridTestHelper.GetStateCount(grid, State.DEAD), 96);
        }
        public void Cycle_3CellRow_Becomes3CellColumn()
        {
            var grid   = new Grid(10);
            var coords = new Dictionary <Point, State>
            {
                { new Point {
                      X = 4, Y = 5
                  }, State.ALIVE },
                { new Point {
                      X = 5, Y = 5
                  }, State.ALIVE },
                { new Point {
                      X = 6, Y = 5
                  }, State.ALIVE }
            };

            grid.SetInitialCells(coords);

            grid.Cycle();

            /* check grid evolves from a 3-cell live row to a 3-cell live column,
             * and that no other cells become live */
            var expectedLiveCellsRow = new List <Cell> {
                grid.Data[4, 5], grid.Data[5, 5], grid.Data[6, 5]
            };
            var numLiveCellsInRow = expectedLiveCellsRow.Where(cell => cell.CurrentState == State.ALIVE).Count();

            Assert.IsTrue(numLiveCellsInRow == 3);

            Assert.AreEqual(GridTestHelper.GetStateCount(grid, State.ALIVE), 3);
            Assert.AreEqual(GridTestHelper.GetStateCount(grid, State.DEAD), 97);
        }
        public void SetInitialCells_EmptyGrid_OnlyChosenCellsStateChanged()
        {
            var grid = new Grid(4);

            int liveCellsBefore = GridTestHelper.GetStateCount(grid, State.ALIVE);
            int deadCellsBefore = GridTestHelper.GetStateCount(grid, State.DEAD);

            Assert.AreEqual(liveCellsBefore, 0);
            Assert.AreEqual(deadCellsBefore, 16);

            // set chosen cells
            var coords = new Dictionary <Point, State>
            {
                { new Point {
                      X = 1, Y = 1
                  }, State.ALIVE },
                { new Point {
                      X = 1, Y = 2
                  }, State.ALIVE }
            };

            grid.SetInitialCells(coords);

            int liveCellsAfter = GridTestHelper.GetStateCount(grid, State.ALIVE);
            int deadCellsAfter = GridTestHelper.GetStateCount(grid, State.DEAD);

            Assert.AreEqual(liveCellsAfter, 2);
            Assert.AreEqual(deadCellsAfter, 14);
        }
        public void Cycle_3BlueCyclicRGBCells_AllCellsEventuallyBecomeBlue()
        {
            var grid = new RGBGrid(10, true);

            GridTestHelper.make3CellColumn(grid, State.BLUE, new Point {
                X = 5, Y = 5
            });

            GridTestHelper.PerformGridCycles(grid, 100);

            var blueCells = GridTestHelper.GetStateCount(grid, State.BLUE);

            Assert.AreEqual(blueCells, grid.Data.Length);
        }
        public void Cycle_3GreenRGBCells_AllCellsEventuallyBecomeGreen()
        {
            var grid = new RGBGrid(10, false);

            GridTestHelper.make3CellColumn(grid, State.GREEN, new Point {
                X = 5, Y = 5
            });

            GridTestHelper.PerformGridCycles(grid, 100);

            var greenCells = GridTestHelper.GetStateCount(grid, State.GREEN);

            Assert.AreEqual(greenCells, grid.Data.Length);
        }
        public void Cycle_3Red3GreenCyclicRGBCells_AllCellsEventuallyBecomeRed()
        {
            var grid = new RGBGrid(10, true);

            GridTestHelper.make3CellColumn(grid, State.RED, new Point {
                X = 5, Y = 5
            });
            GridTestHelper.make3CellColumn(grid, State.GREEN, new Point {
                X = 6, Y = 5
            });

            GridTestHelper.PerformGridCycles(grid, 100);

            var redCells = GridTestHelper.GetStateCount(grid, State.RED);

            Assert.AreEqual(redCells, grid.Data.Length);
        }
        public void SetRandomCells_EmptyGrid_GridHasLiveAndDeadCells()
        {
            var grid = new Grid(50);

            var liveCellsBefore = GridTestHelper.GetStateCount(grid, State.ALIVE);
            var deadCellsBefore = GridTestHelper.GetStateCount(grid, State.DEAD);

            Assert.AreEqual(liveCellsBefore, 0);
            Assert.AreEqual(deadCellsBefore, 2500);

            grid.SetRandomInitialCells();

            var liveCellsAfter = GridTestHelper.GetStateCount(grid, State.ALIVE);
            var deadCellsAfter = GridTestHelper.GetStateCount(grid, State.DEAD);

            Assert.IsTrue(liveCellsAfter > 0);
            Assert.IsTrue(deadCellsAfter > 0);
        }
        public void Cycle_3Red3Green3BlueCyclicRGBCells_AllCellsEventuallyBecomeRed()
        {
            var grid = new RGBGrid(10, true);

            GridTestHelper.make3CellColumn(grid, State.RED, new Point {
                X = 0, Y = 5
            });                                                                                         // left edge
            GridTestHelper.make3CellColumn(grid, State.GREEN, new Point {
                X = 5, Y = 5
            });                                                                                         // central
            GridTestHelper.make3CellColumn(grid, State.BLUE, new Point {
                X = 9, Y = 5
            });                                                                                        // right edge

            GridTestHelper.PerformGridCycles(grid, 100);

            /* Since Red eats Green eats Blue, Red should finally dominate:
             * - Green eats 'rightwards', and eats all the Blue
             * - Red eats 'rightwards' at the same rate, finally eating all the Green. */

            var redCells = GridTestHelper.GetStateCount(grid, State.RED);

            Assert.AreEqual(redCells, grid.Data.Length);
        }