Example #1
0
        private void LiveCellWithMoreThanThreeNeighboursDies_Wrapping()
        {
            var grid = new Grid(3, 3);

            // #  #
            //    #
            //    #  #
            grid.SetCellAliveAtCoords(new[] { 1, 1 });
            grid.SetCellAliveAtCoords(new[] { 2, 1 });
            grid.SetCellAliveAtCoords(new[] { 2, 2 });
            grid.SetCellAliveAtCoords(new[] { 2, 3 });
            grid.SetCellAliveAtCoords(new[] { 3, 3 });

            var game = new Game(grid);

            game.ProgressTime();

            const string expected = "         \n" +
                                    "         \n" +
                                    "         \n";

            var actual = GridFormatter.OutputWithoutGridLinesAndNumbers(grid);

            Assert.Equal(expected, actual);
        }
Example #2
0
        private void CorrectOutputWhenApplyingAllRulesSimultaneously_Wrapping()
        {
            var grid = new Grid(3, 3);

            // #  #
            // #  #
            // #    #

            grid.SetCellAliveAtCoords(new[] { 1, 1 });
            grid.SetCellAliveAtCoords(new[] { 2, 1 });
            grid.SetCellAliveAtCoords(new[] { 1, 2 });
            grid.SetCellAliveAtCoords(new[] { 2, 2 });
            grid.SetCellAliveAtCoords(new[] { 1, 3 });
            grid.SetCellAliveAtCoords(new[] { 3, 3 });

            var game = new Game(grid);

            game.ProgressTime();

            const string expected = "         \n" +
                                    "         \n" +
                                    "         \n";

            var actual = GridFormatter.OutputWithoutGridLinesAndNumbers(grid);

            Assert.Equal(expected, actual);
        }
Example #3
0
        private void DeadCellWithThreeLivesNeighboursBecomesAlive()
        {
            var grid = new Grid(4, 4);

            //
            //    #  #
            //    #
            //
            grid.SetCellAliveAtCoords(new[] { 2, 2 });
            grid.SetCellAliveAtCoords(new[] { 3, 2 });
            grid.SetCellAliveAtCoords(new[] { 2, 3 });

            var game = new Game(grid);

            game.ProgressTime();

            const string expected = "            \n" +
                                    "    #  #    \n" +
                                    "    #  #    \n" +
                                    "            \n";

            var actual = GridFormatter.OutputWithoutGridLinesAndNumbers(grid);

            Assert.Equal(expected, actual);
        }
Example #4
0
        private void CorrectOutputForXKCDRipJohnConwayPattern()
        {
            var grid = new Grid(8, 11);

            //
            //          #  #  #
            //          #     #
            //          #     #
            //             #
            //    #     #  #  #
            //       #     #     #
            //             #        #
            //          #     #
            //          #     #

            grid.SetCellAliveAtCoords(new[] { 4, 3 });
            grid.SetCellAliveAtCoords(new[] { 5, 3 });
            grid.SetCellAliveAtCoords(new[] { 6, 3 });
            grid.SetCellAliveAtCoords(new[] { 4, 4 });
            grid.SetCellAliveAtCoords(new[] { 6, 4 });
            grid.SetCellAliveAtCoords(new[] { 4, 5 });
            grid.SetCellAliveAtCoords(new[] { 6, 5 });
            grid.SetCellAliveAtCoords(new[] { 5, 6 });
            grid.SetCellAliveAtCoords(new[] { 2, 7 });
            grid.SetCellAliveAtCoords(new[] { 4, 7 });
            grid.SetCellAliveAtCoords(new[] { 5, 7 });
            grid.SetCellAliveAtCoords(new[] { 6, 7 });
            grid.SetCellAliveAtCoords(new[] { 3, 8 });
            grid.SetCellAliveAtCoords(new[] { 5, 8 });
            grid.SetCellAliveAtCoords(new[] { 7, 8 });
            grid.SetCellAliveAtCoords(new[] { 5, 9 });
            grid.SetCellAliveAtCoords(new[] { 8, 9 });
            grid.SetCellAliveAtCoords(new[] { 4, 10 });
            grid.SetCellAliveAtCoords(new[] { 6, 10 });
            grid.SetCellAliveAtCoords(new[] { 4, 11 });
            grid.SetCellAliveAtCoords(new[] { 6, 11 });

            var game = new Game(grid);

            game.ProgressTime();

            const string expected = "                        \n" +
                                    "             #          \n" +
                                    "          #     #       \n" +
                                    "       #  #     #  #    \n" +
                                    "          #     #       \n" +
                                    "       #                \n" +
                                    "       #                \n" +
                                    "       #           #    \n" +
                                    "             #     #    \n" +
                                    "          #     #  #    \n" +
                                    "                        \n";

            var actual = GridFormatter.OutputWithoutGridLinesAndNumbers(grid);

            Assert.Equal(expected, actual);
        }
        public void OutputsEmptyGridForNewGrid()
        {
            var          grid     = new Grid(3, 3);
            const string expected = "         \n" +
                                    "         \n" +
                                    "         \n";

            var actual = GridFormatter.OutputWithoutGridLinesAndNumbers(grid);

            Assert.Equal(expected, actual);
        }
        public GameOfLife(IInputReader inputReader, IOutputWriter outputWriter)
        {
            StateGenerator = new StateGenerator();
            var inputProcessor = new WorldBuilder(inputReader);

            GridFormatter = new GridFormatter();
            OutputWriter  = outputWriter;

            World = inputProcessor.GetWorld();

            DisplayInitialGameOutput();
        }
        public void outputsGridWithRowAndColumnNumbersAndGridLines()
        {
            var          grid     = new Grid(10, 10);
            const string expected = "     1  2  3  4  5  6  7  8  9 10 (x)\n" +
                                    "  1  .  .  .  .  .  .  .  .  .  . \n" +
                                    "  2  .  .  .  .  .  .  .  .  .  . \n" +
                                    "  3  .  .  .  .  .  .  .  .  .  . \n" +
                                    "  4  .  .  .  .  .  .  .  .  .  . \n" +
                                    "  5  .  .  .  .  .  .  .  .  .  . \n" +
                                    "  6  .  .  .  .  .  .  .  .  .  . \n" +
                                    "  7  .  .  .  .  .  .  .  .  .  . \n" +
                                    "  8  .  .  .  .  .  .  .  .  .  . \n" +
                                    "  9  .  .  .  .  .  .  .  .  .  . \n" +
                                    " 10  .  .  .  .  .  .  .  .  .  . \n" +
                                    "(y)";

            var actual = GridFormatter.OutputWithGridLinesAndNumbers(grid);

            Assert.Equal(expected, actual);
        }
        public void CanSortCommentsCorrectly()
        {
            IGridFormatter gridFormatter = new GridFormatter();

            var request = new JqGridRequest
            {
                sidx = "Comment",
                rows = 2,
                page = 1,
                sord = "desc"
            };

            var comments = new List<CommentDto>
                {new CommentDto {Comment = "Comment1", CommentDate = new DateTime(2012, 1, 1)},
                 new CommentDto {Comment = "Comment2", CommentDate = new DateTime(2012, 2, 1)},
                 new CommentDto {Comment = "Comment3", CommentDate = new DateTime(2012, 3, 1)},
                 new CommentDto {Comment = "Comment4", CommentDate = new DateTime(2012, 4, 1)}
                };

            var result = gridFormatter.FormatCommentsForGrid(comments, request);

            Assert.That(result.rows[0].cell[1], Is.EqualTo("01 Apr 2012"));
        }
        public void CanFormatCommentsCorrectly()
        {
            IGridFormatter gridFormatter = new GridFormatter();

            var request = new JqGridRequest
                              {
                                  sidx = "Date",
                                  rows = 2,
                                  page = 1,
                                  sord = "asc"
                              };

            var comments = new List<CommentDto>
                {new CommentDto {Comment = "Comment1", CommentDate = new DateTime(2012, 1, 1)},
                 new CommentDto {Comment = "Comment2", CommentDate = new DateTime(2012, 2, 1)},
                 new CommentDto {Comment = "Comment3", CommentDate = new DateTime(2012, 3, 1)},
                 new CommentDto {Comment = "Comment4", CommentDate = new DateTime(2012, 4, 1)}
                };

            var result = gridFormatter.FormatCommentsForGrid(comments, request);

            Assert.That(result.rows.Length, Is.EqualTo(2));
            Assert.That(result.records, Is.EqualTo(4));
        }
        private void DisplayWorldState()
        {
            var formattedWorld = GridFormatter.Format(World);

            OutputWriter.WriteAtTop(formattedWorld);
        }