예제 #1
0
        public void StirlingNumber1SpecialCases()
        {
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(0, 0) == 1);
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(1, 0) == 0);
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(1, 1) == 1);
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(2, 0) == 0);
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(2, 1) == 1);
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(2, 2) == 1);

            foreach (int m in TestUtilities.GenerateIntegerValues(2, 100, 4))
            {
                Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(m, 0) == 0);
                Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(m, 1) == AdvancedIntegerMath.Factorial(m - 1));
                Assert.IsTrue(TestUtilities.IsNearlyEqual(
                                  AdvancedIntegerMath.StirlingNumber1(m, 2),
                                  AdvancedIntegerMath.Factorial(m - 1) * AdvancedIntegerMath.HarmonicNumber(m - 1)
                                  ));

                Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(m, m) == 1);
                Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(m, m - 1) == AdvancedIntegerMath.BinomialCoefficient(m, 2));
                Assert.IsTrue(TestUtilities.IsNearlyEqual(
                                  AdvancedIntegerMath.StirlingNumber1(m, m - 2),
                                  (3 * m - 1) * AdvancedIntegerMath.BinomialCoefficient(m, 3) / 4
                                  ));
            }
        }
예제 #2
0
 public void HarmonicPsiAgreement()
 {
     foreach (int n in TestUtilities.GenerateIntegerValues(1, 1000, 10))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
                           AdvancedIntegerMath.HarmonicNumber(n - 1),
                           AdvancedMath.Psi(n) + AdvancedMath.EulerGamma
                           ));
     }
 }
예제 #3
0
 public void HarmonicSpecialCases()
 {
     Assert.IsTrue(AdvancedIntegerMath.HarmonicNumber(0) == 0.0);
     Assert.IsTrue(AdvancedIntegerMath.HarmonicNumber(1) == 1.0);
     Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedIntegerMath.HarmonicNumber(2), 3.0 / 2.0));
 }