public void Given_a_number_of_rows_when_generate_then_should_constructed_as_pascal_triangle()
        {
            var solution = new PascalTriangle();
            var result   = solution.Generate(Number);

            Assert.Equal(_triangle, result);
        }
Exemplo n.º 2
0
    static void Main()
    {
        PascalTriangle pascalTriangle = new PascalTriangle(10);

        pascalTriangle.CalculateTriangle();
        pascalTriangle.PrintTriangle();
    }
Exemplo n.º 3
0
        public void PascalsTriangle()
        {
            PascalTriangle PascalTriangle = new PascalTriangle();
            var            answer         = PascalTriangle.Generate(5);

            // Assert.IsTrue(answer);
        }
Exemplo n.º 4
0
        public void TestMethod1()
        {
            // Arrange
            PascalTriangle question = new PascalTriangle();
            int            numRows  = 5;

            int[][] expected = new int[][]
            {
                new int[] { 1 },
                new int[] { 1, 1 },
                new int[] { 1, 2, 1 },
                new int[] { 1, 3, 3, 1 },
                new int[] { 1, 4, 6, 4, 1 },
            };

            // Act
            int[][] actual = question.Generate(numRows) as int[][];

            // Assert
            Assert.AreEqual(expected.Length, actual.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                CollectionAssert.AreEqual(expected[i], actual[i]);
            }
        }
Exemplo n.º 5
0
        public void EmptyCollectionTest()
        {
            var triangle = PascalTriangle.Triangle(0);


            CollectionAssert.AreEqual(new List <IList <int> >(), triangle.ToList());
        }
Exemplo n.º 6
0
        public void PascalTriangleTest()
        {
            var n = 100;

            foreach (var i in Enumerable.Range(0, n))
            {
                var triangle = PascalTriangle.Generate(i);
                Assert.Equal(i, triangle.Count);
                if (i == 0)
                {
                    Assert.Empty(triangle);
                    continue;
                }
                if (i == 1)
                {
                    Assert.Equal(1, triangle[0][0]);
                    continue;
                }
                var previousRow = triangle[0];
                for (var r = 1; r < triangle.Count; r++)
                {
                    var row = triangle[r];
                    Assert.Equal(1, row[0]);
                    for (var j = 1; j < r - 1; j++)
                    {
                        Assert.Equal(previousRow[j - 1] + previousRow[j], row[j]);
                    }
                    Assert.Equal(1, row[row.Count - 1]);
                    previousRow = row;
                }
            }
        }
Exemplo n.º 7
0
        public void GenerateTriangle_ShouldReturn_PascalTriangle_ForGivenRows()
        {
            // Arrange
            var numRows          = 5;
            var expectedTriangle = new List <IList <int> >
            {
                new List <int> {
                    1
                },
                new List <int> {
                    1, 1
                },
                new List <int> {
                    1, 2, 1
                },
                new List <int> {
                    1, 3, 3, 1
                },
                new List <int> {
                    1, 4, 6, 4, 1
                }
            };

            var pascalTriangle = new PascalTriangle();

            // Act
            var triangle = pascalTriangle.GenerateTriangle(numRows);

            // Assert
            triangle.Should().BeEquivalentTo(expectedTriangle);
        }
Exemplo n.º 8
0
        public void TestMethod1()
        {
            var r = PascalTriangle.Generate(5);

            Assert.AreEqual(r.Count, 5);
            Assert.AreEqual(r[4][0], 1);
            Assert.AreEqual(r[4][1], 4);
            Assert.AreEqual(r[4][2], 6);
        }
Exemplo n.º 9
0
        public void TestGetRow()
        {
            var r = PascalTriangle.GetRow(5);

            Assert.AreEqual(r[0], 1);
            Assert.AreEqual(r[1], 4);
            Assert.AreEqual(r[2], 6);

            //C(32,16)
            r = PascalTriangle.GetRow(33);
            Assert.AreEqual(r[16], 601080390);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Задание 1
        /// </summary>
        private static void Task1()
        {
            CL.BeginApp("Количество маршрутов с препятствиями");
            int row = 8;
            int col = 8;

            int[,] map = MazeGenerator.Map(row, col);
            CL.PrintArr(map);

            int[,] way = PascalTriangle.Build(row, col, map);
            CL.PrintArr(way);

            CL.ConsolePause();
            Menu();
        }
Exemplo n.º 11
0
        public void GetRow_ShouldReturn_PascalTriangleRow_ForGivenRowIndex()
        {
            // Arrange
            var rowIndex    = 3;
            var expectedRow = new List <int> {
                1, 3, 3, 1
            };

            var pascalTriangle = new PascalTriangle();

            // Act
            var row = pascalTriangle.GetRow(rowIndex);

            // Assert
            row.Should().BeEquivalentTo(expectedRow);
        }
Exemplo n.º 12
0
        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = string.Empty;
            int n = 0;

            int.TryParse(textBox2.Text, out n);
            PascalTriangle pascal = new PascalTriangle();
            Stopwatch      sw     = new Stopwatch();

            sw.Reset();
            sw.Start();
            pascal.CreatePascal_AnotherVersion(n, textBox1);
            sw.Stop();
            MessageBox.Show(string.Format("遞迴使用了{0}毫秒", sw.ElapsedMilliseconds.ToString()));
            sw.Reset();
            sw.Start();
            pascal.CreatePascal(n, textBox1);
            sw.Stop();
            MessageBox.Show(string.Format("矩陣使用了{0}毫秒", sw.ElapsedMilliseconds.ToString()));
        }
Exemplo n.º 13
0
        public void TriangleTest()
        {
            var triangle = PascalTriangle.Triangle(5);

            var result = new List <List <int> >()
            {
                new List <int>()
                {
                    1
                },
                new List <int>()
                {
                    1, 1
                },
                new List <int>()
                {
                    1, 2, 1
                },
                new List <int>()
                {
                    1, 3, 3, 1
                },
                new List <int>()
                {
                    1, 4, 6, 4, 1
                }
            };

            if (result.Count != triangle.Count)
            {
                Assert.Fail();
            }

            for (int i = 0; i < result.Count; i++)
            {
                CollectionAssert.AreEqual(result[i], triangle[i].ToList());
            }
        }
Exemplo n.º 14
0
        public void CanGenerate()
        {
            var result = PascalTriangle.Generate(4);

            Assert.Equal(4, result.Count);
        }
Exemplo n.º 15
0
        private static void PascalTriangleSequence()
        {
            Console.WriteLine("Input the size of pascal triangle:");
            int size = TryGetIntInput();

            PascalTriangle pascal = new PascalTriangle(size);
            string[] rows = pascal.GenerateTriangleStr();

            foreach (var row in rows)
            {
                Console.WriteLine(row);
            }
        }
Exemplo n.º 16
0
 static void Main()
 {
     PascalTriangle pascalTriangle = new PascalTriangle(10);
     pascalTriangle.CalculateTriangle();
     pascalTriangle.PrintTriangle();
 }
Exemplo n.º 17
0
        private static void PascalTriangleTest()
        {
            int num = 15;

            PascalTriangle.Draw(num);
        }
 public PascalTriangle_ShouldGenerate()
 {
     _pt = new PascalTriangle();
 }
Exemplo n.º 19
0
        public void TestConstraints(int row)
        {
            var    exception       = Assert.Throws <ArgumentOutOfRangeException>(() => PascalTriangle.getPascalRow(row));
            string expectedMessage = string.Format("Should be between 0 and 5000000 inclusive.{0}Parameter name: n", Environment.NewLine);

            Assert.That(exception.Message, Is.EqualTo(expectedMessage));
        }
Exemplo n.º 20
0
        public void BiggerNumberTest()
        {
            var expected = new List <List <int> >()
            {
                new List <int>()
                {
                    1
                },
                new List <int>()
                {
                    1, 1
                },
                new List <int>()
                {
                    1, 2, 1
                },
                new List <int>()
                {
                    1, 3, 3, 1
                },
                new List <int>()
                {
                    1, 4, 6, 4, 1
                },
                new List <int>()
                {
                    1, 5, 10, 10, 5, 1
                },
                new List <int>()
                {
                    1, 6, 15, 20, 15, 6, 1
                },
                new List <int>()
                {
                    1, 7, 21, 35, 35, 21, 7, 1
                },
                new List <int>()
                {
                    1, 8, 28, 56, 70, 56, 28, 8, 1
                },
                new List <int>()
                {
                    1, 9, 36, 84, 126, 126, 84, 36, 9, 1
                },
                new List <int>()
                {
                    1, 10, 45, 120, 210, 252, 210, 120, 45, 10, 1
                },
                new List <int>()
                {
                    1, 11, 55, 165, 330, 462, 462, 330, 165, 55, 11, 1
                },
                new List <int>()
                {
                    1, 12, 66, 220, 495, 792, 924, 792, 495, 220, 66, 12, 1
                },
                new List <int>()
                {
                    1, 13, 78, 286, 715, 1287, 1716, 1716, 1287, 715, 286, 78, 13, 1
                },
                new List <int>()
                {
                    1, 14, 91, 364, 1001, 2002, 3003, 3432, 3003, 2002, 1001, 364, 91, 14, 1
                },
            };

            var triangle = PascalTriangle.Triangle(15);

            for (int i = 0; i < expected.Count; i++)
            {
                CollectionAssert.AreEqual(expected[i], triangle[i].ToList());
            }
        }
Exemplo n.º 21
0
 public void TestRow(int row, int[] expected)
 {
     Assert.That(PascalTriangle.getPascalRow(row), Is.EqualTo(expected));
 }