00001 namespace Tests
00002 {
00003 using System;
00004 using Microsoft.VisualStudio.TestTools.UnitTesting;
00005 using NewGamePhysics.Mathematics;
00006
00010 [TestClass]
00011 public class UnitTestGamma
00012 {
00013 public UnitTestGamma()
00014 {
00015 }
00016
00017 private TestContext testContextInstance;
00018
00023 public TestContext TestContext
00024 {
00025 get
00026 {
00027 return testContextInstance;
00028 }
00029 set
00030 {
00031 testContextInstance = value;
00032 }
00033 }
00034
00035 [TestMethod]
00036 public void GammaLogFunction()
00037 {
00038 const int numTestdata = 20;
00039
00040 double[] x = {
00041 0.20E+00,
00042 0.40E+00,
00043 0.60E+00,
00044 0.80E+00,
00045 1.00E+00,
00046 1.10E+00,
00047 1.20E+00,
00048 1.30E+00,
00049 1.40E+00,
00050 1.50E+00,
00051 1.60E+00,
00052 1.70E+00,
00053 1.80E+00,
00054 1.90E+00,
00055 2.00E+00,
00056 3.00E+00,
00057 4.00E+00,
00058 10.00E+00,
00059 20.00E+00,
00060 30.00E+00 };
00061
00062
00063 double[] expected = {
00064 0.1524063822430784E+01,
00065 0.7966778177017837E+00,
00066 0.3982338580692348E+00,
00067 0.1520596783998375E+00,
00068 0.0000000000000000E+00,
00069 -0.4987244125983972E-01,
00070 -0.8537409000331584E-01,
00071 -0.1081748095078604E+00,
00072 -0.1196129141723712E+00,
00073 -0.1207822376352452E+00,
00074 -0.1125917656967557E+00,
00075 -0.9580769740706586E-01,
00076 -0.7108387291437216E-01,
00077 -0.3898427592308333E-01,
00078 0.00000000000000000E+00,
00079 0.69314718055994530E+00,
00080 0.17917594692280550E+01,
00081 0.12801827480081469E+02,
00082 0.39339884187199494E+02,
00083 0.71257038967168009E+02};
00084
00085 double error;
00086 double value;
00087 for (int i = 0; i < numTestdata; i++)
00088 {
00089 value = Gamma.LogFunction(x[i]);
00090 error = Math.Abs(value - expected[i]);
00091 Console.WriteLine(
00092 "Gamma.LogFunction({0}): expected {1} got {2} error {3}",
00093 x[i],
00094 expected[i],
00095 value,
00096 error);
00097 Assert.IsTrue(error <= 1e-10);
00098 }
00099 }
00100 }
00101 }