Example #1
0
        public void TestNChooseK()
        {
            int    n = 100;
            int    k = 50;
            double d = MathX.NChooseK(n, k);

            AssertEquals("NChooseK ", 1.00891344545564E29, d);

            n = -1; k = 1;
            d = MathX.NChooseK(n, k);
            AssertEquals("NChooseK ", Double.NaN, d);

            n = 1; k = -1;
            d = MathX.NChooseK(n, k);
            AssertEquals("NChooseK ", Double.NaN, d);

            n = 0; k = 1;
            d = MathX.NChooseK(n, k);
            AssertEquals("NChooseK ", Double.NaN, d);

            n = 1; k = 0;
            d = MathX.NChooseK(n, k);
            AssertEquals("NChooseK ", 1, d);

            n = 10; k = 9;
            d = MathX.NChooseK(n, k);
            AssertEquals("NChooseK ", 10, d);

            n = 10; k = 10;
            d = MathX.NChooseK(n, k);
            AssertEquals("NChooseK ", 1, d);

            n = 10; k = 1;
            d = MathX.NChooseK(n, k);
            AssertEquals("NChooseK ", 10, d);

            n = 1000; k = 1;
            d = MathX.NChooseK(n, k);
            AssertEquals("NChooseK ", 1000, d); // awesome ;)

            n = 1000; k = 2;
            d = MathX.NChooseK(n, k);
            AssertEquals("NChooseK ", 499500, d); // awesome ;)

            n = 13; k = 7;
            d = MathX.NChooseK(n, k);
            AssertEquals("NChooseK ", 1716, d);
        }