예제 #1
0
        public bool compareGrid(LifeGrid inputGrid)
        {
            for (int yVal = 0; yVal < Grid.GetLength(0); yVal++)
            {
                for (int xVal = 0; xVal < Grid.GetLength(1); xVal++)
                {
                    if (inputGrid.Grid[yVal, xVal] != this.grid[yVal, xVal])
                        return false;

                }
            }
            return true;
        }
예제 #2
0
        static void Main(string[] args)
        {
            /*
             * Very, very simple tester. Mostly for the sake of visualization.
             *
             */
            Console.WriteLine("===================");

            LifeGrid grid = new LifeGrid(new char[,] {
                    { '.', '.', '.', '.', '.', '.', '.', '.'  },
                    { '.', '.', '.', '.', '*', '.', '.', '.'  },
                    { '.', '.', '.', '*', '*', '.', '.', '.'  },
                    { '.', '.', '.', '.', '.', '.', '.', '.'  }
                    });

            GameOfLife test = new GameOfLife(grid);

            test.printGrid();
            test.produceNextGeneration();
            test.printGrid();

            Console.WriteLine("===================");

            grid = new LifeGrid(new char[,] {
                { '*', '.', '.', '.'  },
                { '.', '.', '.', '.'  },
                { '.', '*', '.', '.'  },
                { '.', '.', '.', '.'  }
            }) ;

            test.GameGrid = grid;

            test.printGrid();
            test.produceNextGeneration();
            test.printGrid();

            Console.WriteLine("===================");

            grid = new LifeGrid(new char[,] {
                { '*', '*', '.', '.' , '.' },
                { '.', '.', '.', '.' , '.' },
                { '.', '*', '.', '.' , '.' }
            });

            test.GameGrid = grid;
            test.printGrid();
            test.produceNextGeneration();
            test.printGrid();
        }
예제 #3
0
        public void TestOutput1()
        {
            // Test input and output as given in task text
            GameOfLife localSut = new GameOfLife(new LifeGrid(new char[,] {
                    { '.', '.', '.', '.', '.', '.', '.', '.'  },
                    { '.', '.', '.', '.', '*', '.', '.', '.'  },
                    { '.', '.', '.', '*', '*', '.', '.', '.'  },
                    { '.', '.', '.', '.', '.', '.', '.', '.'  }
                    }));

            LifeGrid expectedResult = new LifeGrid(  new char[,] {
                    { '.', '.', '.', '.', '.', '.', '.', '.'  },
                    { '.', '.', '.', '*', '*', '.', '.', '.'  },
                    { '.', '.', '.', '*', '*', '.', '.', '.'  },
                    { '.', '.', '.', '.', '.', '.', '.', '.'  }
                    });

            localSut.produceNextGeneration();

            Assert.IsTrue(localSut.GameGrid.compareGrid(expectedResult));
        }
예제 #4
0
 // Constructor
 public GameOfLife(LifeGrid grid)
 {
     this.localGrid = grid;
 }
예제 #5
0
        public void TestOutput2()
        {
            // Testing a few more patterns and expected results i found on the intertube.
            GameOfLife localSut = new GameOfLife(new LifeGrid(new char[,] {
                    { '.', '.', '.', '.', '.', '.', '.', '.'  },
                    { '.', '*', '.', '.', '.', '.', '.', '.'  },
                    { '*', '*', '*', '.', '.', '.', '.', '.'  },
                    { '.', '*', '.', '.', '.', '.', '.', '.'  },
                    { '.', '.', '.', '.', '.', '.', '.', '.'  },
                    { '.', '.', '.', '.', '*', '*', '.', '.'  },
                    { '.', '.', '.', '.', '*', '*', '.', '.'  },
                    { '.', '.', '.', '.', '.', '.', '.', '.'  }
                    }));

            LifeGrid expectedResult = new LifeGrid(  new char[,] {
                    { '.', '.', '.', '.', '.', '.', '.', '.'  },
                    { '*', '*', '*', '.', '.', '.', '.', '.'  },
                    { '*', '.', '*', '.', '.', '.', '.', '.'  },
                    { '*', '*', '*', '.', '.', '.', '.', '.'  },
                    { '.', '.', '.', '.', '.', '.', '.', '.'  },
                    { '.', '.', '.', '.', '*', '*', '.', '.'  },
                    { '.', '.', '.', '.', '*', '*', '.', '.'  },
                    { '.', '.', '.', '.', '.', '.', '.', '.'  }
                    });

            localSut.produceNextGeneration();

            Assert.IsTrue(localSut.GameGrid.compareGrid(expectedResult));
        }