Ejemplo n.º 1
0
 public void IsDeadCount7()
 {
     GameBoard board = new GameBoard(10);
     board.MakeCellAlive(5, 5);
     int actual = board.NeighborsAlive(4, 5)[1];
     Assert.AreEqual(7, actual);
 }
Ejemplo n.º 2
0
 public void ChangeStatusAccordingToRules()
 {
     GameBoard board = new GameBoard(6);
     board.MakeCellAlive(5, 5);
     bool actual = board.ChangeStatus(5, 5, 0, 8);
     Assert.AreEqual(true, actual);
 }
Ejemplo n.º 3
0
 public void IsAliveCount1()
 {
     GameBoard board = new GameBoard(10);
     board.MakeCellAlive(5, 5);
     int actual = board.NeighborsAlive(4,5)[0];
     Assert.AreEqual(1, actual);
 }
Ejemplo n.º 4
0
 public void CanConvertCellsToBools()
 {
     GameBoard board = new GameBoard(10);
     List<List<bool>> boolList = board.CellsToBoolsConverter();
     bool actual = boolList[0][0];
     Assert.AreEqual(false, actual);
 }
Ejemplo n.º 5
0
 public void CanConvertNthCellToBool()
 {
     GameBoard board = new GameBoard(10);
     board.MakeCellAlive(5, 5);
     List<List<bool>> boolList = board.CellsToBoolsConverter();
     bool actual = boolList[5][5];
     Assert.AreEqual(true, actual);
 }
 public void CanApplyKillRules()
 {
     List<Cell> alive = new List<Cell>();
     alive.Add(new Cell ( 1, 2 ));
     alive.Add(new Cell ( 2, 2 ));
     alive.Add(new Cell ( 2, 3 ));
     alive.Add(new Cell ( 4, 3 ));
     GameBoard board = new GameBoard(alive);
     Cell cellToKill = new Cell(1, 2);
     board.ApplyKillRules(cellToKill, 4);
     Assert.IsTrue(cellToKill.MarkForChange);
 }
 public void BasicBlinkerOscilatesTwoTimes()
 {
     List<Cell> alive = new List<Cell>();
     alive.Add(new Cell(0, 0));
     alive.Add(new Cell(1, 0));
     alive.Add(new Cell(2, 0));
     GameBoard board = new GameBoard(alive);
     List<Cell> aliveNew = new List<Cell>();
     aliveNew.Add(new Cell(1, 0));
     aliveNew.Add(new Cell(0, 0));
     aliveNew.Add(new Cell(2, 0));
     board.Tick();
     board.Tick();
     CollectionAssert.AreEqual(aliveNew, board.AliveCells);
 }
        public MainWindow()
        {
            // currentBoard = new FauxGameOfLife();
            currentBoard = new GameBoard(10);
            currentBoard.MakeCellAlive(5, 5);
            currentBoard.MakeCellAlive(6, 5);
            currentBoard.MakeCellAlive(6, 6);
            currentBoard.MakeCellAlive(7, 6);
            currentBoard.MakeCellAlive(6, 7);
            currentBoard.MakeCellAlive(7, 7);
            dispatcherTimer = new DispatcherTimer();

            InitializeComponent();

            TheListView.ItemsSource = currentBoard.ToList();
            dispatcherTimer.Tick += dispatcherTimerClick;
            dispatcherTimer.Interval = TimeSpan.FromSeconds((double)RunSpeed.Value);
        }
Ejemplo n.º 9
0
        public void TestEmptyBoard()
        {
            var g = new GameBoard(new int[][]
            {
                new[] { 0, 0, 0 },
                new[] { 0, 0, 0 },
                new[] { 0, 0, 0 },
            });

            g.Tick();

            AssertEqualBoard(g, new int[][]
            {
                new[] { 0, 0, 0 },
                new[] { 0, 0, 0 },
                new[] { 0, 0, 0 },
            });
        }
Ejemplo n.º 10
0
        public void TestFourCornersReturnEmpty()
        {
            var g = new GameBoard(new int[][]
            {
                new [] { 1, 0, 1 },
                new [] { 0, 0, 0 },
                new [] { 1, 0, 1 },
            });

            g.Tick();

            AssertEqualBoard(g, new int[][]
            {
                new [] { 0, 0, 0 },
                new [] { 0, 0, 0 },
                new [] { 0, 0, 0 },
            });
        }
Ejemplo n.º 11
0
        public void TestBoardGrowsLeft()
        {
            var g = new GameBoard(new int[][]
            {
                new [] { 1, 0, 0 },
                new [] { 1, 0, 0 },
                new [] { 1, 0, 0 },
            });

            g.Tick();

            AssertEqualBoard(g, new int[][]
            {
                new [] { 0, 0, 0, 0 },
                new [] { 1, 1, 0, 0 },
                new [] { 0, 0, 0, 0 },
            });
        }
 public void CanGenerateNeighborsList()
 {
     List<Cell> alive = new List<Cell>();
     alive.Add(new Cell (1, 2));
     alive.Add(new Cell(0, 1));
     alive.Add(new Cell(1, 4));
     alive.Add(new Cell(3, 2));
     GameBoard board = new GameBoard(alive);
     List<Cell> expected = new List<Cell>();
     expected.Add(new Cell(1, 1));
     expected.Add(new Cell(1, 2));
     expected.Add(new Cell(1, 3));
     expected.Add(new Cell(2, 1));
     expected.Add(new Cell(2, 3));
     expected.Add(new Cell(3, 1));
     expected.Add(new Cell(3, 2));
     expected.Add(new Cell(3, 3));
     List<Cell> neighbors = board.GenerateNeighborsList(new Cell(2, 2));
     CollectionAssert.AreEqual(expected, neighbors);
 }
 public void SqaureStaysASquare()
 {
     List<Cell> alive = new List<Cell>();
     alive.Add(new Cell(0, 0));
     alive.Add(new Cell(0, 1));
     alive.Add(new Cell(1, 0));
     alive.Add(new Cell(1, 1));
     GameBoard board = new GameBoard(alive);
     board.Tick();
     Assert.AreEqual(4, board.AliveCells.Count);
 }
 public void NewBoardIsNotNull()
 {
     GameBoard board = new GameBoard();
     Assert.IsNotNull(board);
 }
 public void NewBoardAcceptsAliveArgument()
 {
     List<Cell> alive = new List<Cell>();
     alive.Add(new Cell(1, 2));
     GameBoard board = new GameBoard(alive);
     Assert.AreEqual(1, board.AliveCells.Count);
     CollectionAssert.AreEqual(alive, board.AliveCells);
 }
 public void GetAliveCellRange()
 {
     List<Cell> alive = new List<Cell>();
     alive.Add(new Cell(1, 2));
     alive.Add(new Cell(1, 4));
     alive.Add(new Cell(3, 2));
     alive.Add(new Cell(0, 1));
     GameBoard board = new GameBoard(alive);
     Assert.AreEqual(0, board.Range.LowRow);
     Assert.AreEqual(1, board.Range.LowCol);
     Assert.AreEqual(3, board.Range.HighRow);
     Assert.AreEqual(4, board.Range.HighCol);
 }
Ejemplo n.º 17
0
        public void TestOneNeighborDies()
        {
            var g = new GameBoard(new int[][]
            {
                new [] { 0, 0, 0,},
                new [] { 0, 0, 1,},
                new [] { 0, 0, 1,},
            });

            g.Tick();

            AssertEqualBoard(g, new int[][]
            {
                new [] { 0, 0, 0,},
                new [] { 0, 0, 0,},
                new [] { 0, 0, 0,},
            });
        }
Ejemplo n.º 18
0
 public void CanCreateGameBoard()
 {
     GameBoard board = new GameBoard(4);
     Assert.IsNotNull(board);
 }
Ejemplo n.º 19
0
 public void CanCreateTableRowOfCorrectSize()
 {
     GameBoard board = new GameBoard(4);
     Assert.AreEqual(4, board.FillRow(0, 4).Count);
 }
Ejemplo n.º 20
0
        private static void AssertEqualBoard(GameBoard gameBoard, int[][] expectedState)
        {
            Assert.AreEqual(expectedState.Length, gameBoard.CurrentBoard.Length);

            for (int boardRow = 0; boardRow < gameBoard.CurrentBoard.Length; boardRow++)
            {
                CollectionAssert.AreEqual(expectedState[boardRow], gameBoard.CurrentBoard[boardRow],
                    string.Format("Row {0} does not match:  Expected:  {1}  Actual:  {2} ",
                                  boardRow,
                                  expectedState[boardRow].ListContents(),
                                  gameBoard.CurrentBoard[boardRow].ListContents()));
            }
        }
Ejemplo n.º 21
0
        public void TestUpperEdgeReturnsEmpty()
        {
            var g = new GameBoard(new int[][]
            {
                new [] { 0, 1, 0 },
                new [] { 0, 0, 0 },
                new [] { 0, 0, 0 },
            });

            g.Tick();

            AssertEqualBoard(g, new int[][]
            {
                new [] { 0, 0, 0 },
                new [] { 0, 0, 0 },
                new [] { 0, 0, 0 },
            });
        }
Ejemplo n.º 22
0
        public void TestThreeNeighborsComesAlive()
        {
            var g = new GameBoard(new int[][]
            {
                new [] { 0, 1, 0 },
                new [] { 0, 1, 0 },
                new [] { 0, 1, 0 },
            });

            g.Tick();

            AssertEqualBoard(g, new int[][]
            {
                new [] { 0, 0, 0 },
                new [] { 1, 1, 1 },
                new [] { 0, 0, 0 },
            });
        }
 public void SumOfAliveNeighbors()
 {
     List<Cell> alive = new List<Cell>();
     alive.Add(new Cell ( 1, 2 ));
     alive.Add(new Cell ( 2, 2 ));
     alive.Add(new Cell ( 2, 3 ));
     alive.Add(new Cell ( 4, 3 ));
     GameBoard board = new GameBoard(alive);
     Assert.AreEqual(3, board.NeighborsAliveCount(new Cell(1, 3)));
 }
Ejemplo n.º 24
0
        public void TestFourNeigborsKillsYou()
        {
            var g = new GameBoard(new int[][]
            {
                new [] { 0, 0, 0, 0 },
                new [] { 0, 1, 1, 0 },
                new [] { 0, 1, 1, 0 },
                new [] { 0, 1, 0, 0 },
            });

            g.Tick();

            AssertEqualBoard(g, new int[][]
            {
                new [] { 0, 0, 0, 0 },
                new [] { 0, 1, 1, 0 },
                new [] { 1, 0, 0, 0 },
                new [] { 0, 1, 1, 0 },
            });
        }
 public void SumOfNeighborsFour()
 {
     List<Cell> alive = new List<Cell>();
     alive.Add(new Cell(0, 0));
     alive.Add(new Cell(1, 0));
     alive.Add(new Cell(2, 0));
     alive.Add(new Cell(2, 1));
     alive.Add(new Cell(1, 2));
     GameBoard board = new GameBoard(alive);
     Assert.AreEqual(3, board.NeighborsAliveCount(board.AliveCells[3]));
 }
 public void CorrectDeadCellCanComeToLife()
 {
     List<Cell> alive = new List<Cell>();
     alive.Add(new Cell(1, 2));
     alive.Add(new Cell(2, 2));
     alive.Add(new Cell(2, 3));
     alive.Add(new Cell(4, 3));
     GameBoard board = new GameBoard(alive);
     List<Cell> liveCellCandidates = new List<Cell>();
     liveCellCandidates.Add(new Cell ( 1, 3 ));
     liveCellCandidates.Add(new Cell ( 1, 3 ));
     liveCellCandidates.Add(new Cell ( 4, 1 ));
     liveCellCandidates.Add(new Cell ( 1, 3 ));
     board.CheckBringCellToLife(liveCellCandidates);
     Assert.AreEqual(5, board.AliveCells.Count);
 }
Ejemplo n.º 27
0
 public void CanCreateBoardWithCorrectNumberOfCells()
 {
     GameBoard board = new GameBoard(10);
     int actual = board.Cells.Count;
     Assert.AreEqual(10, actual);
 }
 public void EnsureTwoCellsAreEqualInList()
 {
     List<Cell> alive = new List<Cell>();
     alive.Add(new Cell(1, 2));
     alive.Add(new Cell(1, 2));
     GameBoard board = new GameBoard(alive);
     Assert.AreEqual(board.AliveCells[0], board.AliveCells[1]);
 }
 public void CellMarkedForChangeIsRemoved()
 {
     List<Cell> alive = new List<Cell>();
     alive.Add(new Cell(1, 2));
     alive.Add(new Cell(2, 2));
     alive.Add(new Cell(2, 3));
     alive.Add(new Cell(4, 3));
     GameBoard board = new GameBoard(alive);
     board.ApplyKillRules(board.AliveCells[0], 4);
     board.RemoveCellsThatDied();
     Assert.AreEqual(3, board.AliveCells.Count);
     //board.AliveCells = board.RemoveCellsThatDied();
     //Assert.AreEqual(3, board.AliveCells.Count);
 }
Ejemplo n.º 30
0
        public void TestOneAliveDies()
        {
            var g = new GameBoard(new int[][]
            {
                new [] { 0, 0, 0 },
                new [] { 0, 1, 0 },
                new [] { 0, 0, 0 },
            });

            g.Tick();

            AssertEqualBoard(g, new int[][]
            {
                new [] { 0, 0, 0 },
                new [] { 0, 0, 0 },
                new [] { 0, 0, 0 },
            });
        }