コード例 #1
0
        public void OverpopulationTest([Values(4, 5, 6, 7, 8)] int neighborCount)
        {
            // Given
            var cell = new LiveCell(neighborCount);

            // When
            var nextGenDeath = cell.WillThisCellSurvive();

            // Then
            Assert.IsTrue(nextGenDeath, "Cell should have died, but lived");
        }
コード例 #2
0
        public void ContinueToLiveTest(int neighorCount)
        {
            // Given
            var cell = new LiveCell(neighorCount);

            // When
            var nextGenDeath = cell.WillThisCellSurvive();

            // Then
            Assert.IsFalse(nextGenDeath, "Cell should lived but it died");
        }
コード例 #3
0
        public void UnderPopulationTest(int neighorCount)
        {
            // Given
            var cell = new LiveCell(neighorCount);

            // When
            var nextGenDeath = cell.WillThisCellSurvive();

            // Then
            Assert.IsTrue(nextGenDeath, "Cell should have died but it lived.");
        }
コード例 #4
0
ファイル: WorldTests.cs プロジェクト: feedfood/GameOfLife
        public void World_no_neighbor_around_1x1_then_dead()
        {
            World world = new World(new Dimension(3, 3));
            LiveCell[] cells = new LiveCell[1] {
                new LiveCell(1, 1)
            };
            world.SetLiveCells(cells);

            world.Advance();

            cells = world.GetLiveCells();
            Assert.AreEqual(0,cells.Length);
        }
コード例 #5
0
ファイル: WorldTests.cs プロジェクト: feedfood/GameOfLife
        public void World_3_neighbors_around_dead_0x0_then_live()
        {
            World world = new World(new Dimension(3, 3));
            LiveCell[] cells = new LiveCell[3] {
                new LiveCell(0, 1),
                new LiveCell(1, 0),
                new LiveCell(1, 1)
            };
            world.SetLiveCells(cells);

            world.Advance();

            Assert.AreEqual(true, HasCell(world, 0, 0));
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: paulhoulston/GameOfLife
 private static IAmACell[] randomGridCells()
 {
     var rand = new Random();
     var seedCells = new IAmACell[GridWidth*GridHeight];
     for (var x = 0; x < GridWidth; x++)
         for (var y = 0; y < GridHeight; y++)
         {
             if (rand.NextDouble() > 0.5)
                 seedCells[x + GridWidth*y] = new LiveCell(x, y);
             else
                 seedCells[x + GridWidth*y] = new DeadCell(x, y);
         }
     return seedCells;
 }
コード例 #7
0
ファイル: WorldTests.cs プロジェクト: feedfood/GameOfLife
        public void World_put1x2_no_advance_return1x2()
        {
            World world = new World(new Dimension(3,3));
            LiveCell[] cells = new LiveCell[1] {
                new LiveCell(1, 2)
            };
            world.SetLiveCells(cells);

            cells = world.GetLiveCells();
            Assert.AreEqual(1, cells.Length);
            Assert.AreEqual(cells[0].X, 1);
            Assert.AreEqual(cells[0].Y, 2);
        }
コード例 #8
0
ファイル: WorldTests.cs プロジェクト: feedfood/GameOfLife
        public void World_put_two_neightbors_around_1x1_then_alive()
        {
            World world = new World(new Dimension(3, 3));
            LiveCell[] cells = new LiveCell[3] {
                new LiveCell(0, 0),
                new LiveCell(0, 2),
                new LiveCell(1, 1)};
            world.SetLiveCells(cells);

            //Assert.AreEqual(2, world.GetLiveNeighbors(new LiveCell(1, 1)));

            world.Advance();

            Assert.AreEqual(true, HasCell(world, 1, 1));
        }
コード例 #9
0
ファイル: WorldTests.cs プロジェクト: feedfood/GameOfLife
        public void World_put_four_neightbors_around_1x1_then_dead()
        {
            World world = new World(new Dimension(3, 3));
            LiveCell[] cells = new LiveCell[5] {
                new LiveCell(0, 0),
                new LiveCell(0, 2),
                new LiveCell(1, 1),
                new LiveCell(2, 0),
                new LiveCell(0, 1)};
            world.SetLiveCells(cells);

            //Assert.AreEqual(4, world.GetLiveNeighbors(new LiveCell(1, 1)));

            world.Advance();

            Assert.AreEqual(false, HasCell(world, 1, 1));
        }
コード例 #10
0
ファイル: CellTests.cs プロジェクト: beneb/GameOfLife
 public void TestLiveCellWith4NeighborsDiesInNextGeneration()
 {
     ICell cell = new LiveCell();
     cell = cell.NextGeneration(4);
     Assert.True(cell is DeadCell);
 }
コード例 #11
0
ファイル: CellTests.cs プロジェクト: beneb/GameOfLife
 public void TestLiveCellWith3NeighborsLivesInNextGeneration()
 {
     ICell cell = new LiveCell();
     cell = cell.NextGeneration(3);
     Assert.True(cell is LiveCell);
 }
コード例 #12
0
ファイル: Program.cs プロジェクト: feedfood/GameOfLife
 public void SetLiveCells(LiveCell[] liveCell)
 {
     foreach (var cell in liveCell)
         LifeMap[cell.X, cell.Y] = true;
 }
コード例 #13
0
ファイル: Program.cs プロジェクト: feedfood/GameOfLife
        private LiveCell[] InternalParseLiveCells(string[] config)
        {
            List<LiveCell> liveCells = new List<LiveCell>();

            string cellConfig = (from configItem in config
                                 let keyValue = configItem.Split(':')
                                 where keyValue.Length == 2 && keyValue[0].Trim() == "live_cell"
                                 select keyValue[1]).FirstOrDefault();

            if (string.IsNullOrEmpty(cellConfig))
                return liveCells.ToArray();

            foreach (var cellItem in cellConfig.Split(','))
            {
                string[] cellXY = cellItem.Split('x');

                LiveCell cell = new LiveCell();
                if( int.TryParse(cellXY[0], out cell.X) &&
                    int.TryParse(cellXY[1], out cell.Y) )
                {
                    if (cell.X >= 0 && cell.X < _dimension.X &&
                        cell.Y >= 0 && cell.Y < _dimension.Y)
                    {
                        liveCells.Add(cell);
                        continue;
                    }
                }

                _hasBadCells = true;
            }
            return liveCells.ToArray();
        }
コード例 #14
0
ファイル: GameTests.cs プロジェクト: feedfood/GameOfLife
        public LiveCell[] GetLiveCells()
        {
            if (!IsGoodConfig())
                return new LiveCell[0];

            LiveCell[] livecells = new LiveCell[1];
            LiveCell cell = new LiveCell();
            cell.X = 1;
            cell.Y = 1;
            livecells[0] = cell;

            return livecells;
        }