コード例 #1
0
ファイル: Program.cs プロジェクト: eoolsen/codingdojos
        static void Main(string[] args)
        {
            //en glider
              var firstrow =  new[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 };
              var secondrow = new[] { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
              var thirdrow =  new[] { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
              var nullrow =   new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

              GameOfLife game = new GameOfLife(10);
              game.PopulateRow(10, firstrow);
              game.PopulateRow(9, secondrow);
              game.PopulateRow(8, thirdrow);
              game.PopulateRow(7, nullrow);
              game.PopulateRow(6, nullrow);
              game.PopulateRow(5, nullrow);
              game.PopulateRow(4, nullrow);
              game.PopulateRow(3, nullrow);
              game.PopulateRow(2, nullrow);
              game.PopulateRow(1, nullrow);

              Console.WriteLine(game.ToString());

              while (true)
              {
            Thread.Sleep(1000);
            game.EvaluateLife();

            Console.WriteLine(game.ToString());
              }
        }
コード例 #2
0
ファイル: TestGameOfLife.cs プロジェクト: eoolsen/codingdojos
        public void TestPopulation()
        {
            GameOfLife g = new GameOfLife(3);
              g.PopulateRow(1, new[] { 0, 1, 1 });
              g.PopulateRow(2, new[] { 0, 0, 1 });
              g.PopulateRow(3, new[] { 0, 1, 1 });

              Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 1, 1 }), g.GetHorizontalLine(3));
        }
コード例 #3
0
ファイル: TestGameOfLife.cs プロジェクト: eoolsen/codingdojos
        public void TestTostring()
        {
            GameOfLife g = new GameOfLife(3);
              g.PopulateRow(1, new[] { 0, 1, 1 });
              g.PopulateRow(2, new[] { 0, 0, 1 });
              g.PopulateRow(3, new[] { 0, 1, 1 });

              StringBuilder result = new StringBuilder();
              result.AppendLine("------");
              result.AppendLine(" **");
              result.AppendLine("  *");
              result.AppendLine(" **");
              result.AppendLine("------");

              Assert.AreEqual(result.ToString(), g.ToString());
        }
コード例 #4
0
ファイル: TestGameOfLife.cs プロジェクト: eoolsen/codingdojos
        public void TestEvaluation1()
        {
            GameOfLife g = new GameOfLife(7);

              g.PopulateRow(7, new[] { 0, 1, 1, 1, 1, 1, 1 });
              g.PopulateRow(6, new[] { 0, 0, 1, 0, 1, 0, 1 });
              g.PopulateRow(5, new[] { 0, 1, 1, 1, 1, 0, 0 });
              g.PopulateRow(4, new[] { 0, 1, 1, 0, 0, 1, 1 });
              g.PopulateRow(3, new[] { 0, 0, 1, 1, 1, 0, 0 });
              g.PopulateRow(2, new[] { 0, 1, 1, 0, 0, 1, 1 });
              g.PopulateRow(1, new[] { 0, 1, 1, 1, 1, 1, 0 });

              g.EvaluateLife();
              Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 1, 1, 0, 1, 0, 1 }), g.GetHorizontalLine(7), "row 7");//ok
              Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 0, 0, 0, 0, 0, 1 }), g.GetHorizontalLine(6), "row 6"); //ok
              Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 0, 0, 0, 1, 0, 1 }), g.GetHorizontalLine(5), "row 5");//ok
              Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 0, 0, 0, 0, 1, 0 }), g.GetHorizontalLine(4), "row 4");//ok
              Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 0, 0, 0, 1, 0, 0 }), g.GetHorizontalLine(3), "row 3");//ok
              Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 0, 0, 0, 0, 0, 1 }), g.GetHorizontalLine(2), "row 2"); //ok
              Assert.AreEqual(CellFactory.CreateCells(new[] { 0, 1, 0, 1, 1, 1, 1 }), g.GetHorizontalLine(1), "row 1"); //ok
        }
コード例 #5
0
ファイル: TestGameOfLife.cs プロジェクト: eoolsen/codingdojos
 public void TestHorizontalLine()
 {
     var g = new GameOfLife(4);
       g.GetHorizontalLine(7);
 }
コード例 #6
0
ファイル: TestGameOfLife.cs プロジェクト: eoolsen/codingdojos
        public void TestTostringLength()
        {
            GameOfLife g = new GameOfLife(2);
              g.PopulateRow(2, new[] { 0, 0 });
              g.PopulateRow(1, new[] { 0, 1 });

              StringBuilder expectedResult = new StringBuilder();
              expectedResult.AppendLine("----");
              expectedResult.AppendLine("  ");
              expectedResult.AppendLine(" *");
              expectedResult.AppendLine("----");
              Assert.AreEqual(expectedResult.ToString(), g.ToString());
        }