Browse Source

Special Functions: stronger unit tests for Gamma/GammaLn #196

pull/289/head
Christoph Ruegg 12 years ago
parent
commit
810b50cd21
  1. 105
      src/UnitTests/SpecialFunctionsTests/GammaTests.cs

105
src/UnitTests/SpecialFunctionsTests/GammaTests.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
// Copyright (c) 2009-2015 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -39,56 +39,67 @@ namespace MathNet.Numerics.UnitTests.SpecialFunctionsTests
[TestFixture, Category("Functions")]
public class GammaTests
{
/// <summary>
/// Log gamma.
/// </summary>
/// <param name="x">Input X value.</param>
/// <param name="f">Function result.</param>
[TestCase(Double.NaN, Double.NaN)]
[TestCase(0.1, 2.2527126517342059020062379568954763844479865649307379)]
[TestCase(1.0, 0.0)]
[TestCase(1.5, -0.12078223763524522234551844578164721225185272790259947)]
[TestCase(Constants.Pi / 2, -0.11590380084550241329912089415904874214542604767006895)]
[TestCase(2.0, 0.0)]
[TestCase(2.5, 0.28468287047291915963249466968270192432013769555989498)]
[TestCase(3.0, 0.693147180559945309417232121458176568075500134360255)]
[TestCase(Constants.Pi, 0.82769459232343710152957855845235995115350173412073715)]
[TestCase(3.5, 1.2009736023470742248160218814507129957702389154681574)]
[TestCase(4.0, 1.7917594692280550008124773583807022727229906921830034)]
[TestCase(4.5, 2.4537365708424422205041425034357161573318235106897606)]
[TestCase(5.0, 3.1780538303479456196469416012970554088739909609035161)]
[TestCase(5.5, 3.9578139676187162938774008558225909985513044919750065)]
[TestCase(10.1, 13.02752673863323715481371189614224148681183971709386)]
public void GammaLn(double x, double f)
[TestCase(Double.NaN, Double.NaN, 14)]
[TestCase(1.000001e-35, 9.9999900000099999900000099999899999522784235098567139293e+34, 14)]
[TestCase(1.000001e-10, 9.99998999943278432519738283781280989934496494539074049002e+9, 14)]
[TestCase(1.000001e-5, 99999.32279432557746387178953902739303931424932435387031653234, 14)]
[TestCase(1.000001e-2, 99.43248512896257405886134437203369035261893114349805309870831, 14)]
[TestCase(-4.8, -0.06242336135475955314181664931547009890495158793105543559676, 12)]
[TestCase(-1.5, 2.363271801207354703064223311121526910396732608163182837618410, 13)]
[TestCase(-0.5, -3.54490770181103205459633496668229036559509891224477425642761, 13)]
[TestCase(1.0e-5 + 1.0e-16, 99999.42279322556767360213300482199406241771308740302819426480, 10)]
[TestCase(0.1, 9.513507698668731836292487177265402192550578626088377343050000, 13)]
[TestCase(1.0 - 1.0e-14, 1.000000000000005772156649015427511664653698987042926067639529, 15)]
[TestCase(1.0, 1.0, 15)]
[TestCase(1.0 + 1.0e-14, 0.99999999999999422784335098477029953441189552403615306268023, 14)]
[TestCase(1.5, 0.886226925452758013649083741670572591398774728061193564106903, 13)]
[TestCase(Constants.Pi/2, 0.890560890381539328010659635359121005933541962884758999762766, 14)]
[TestCase(2.0, 1.0, 16)]
[TestCase(2.5, 1.329340388179137020473625612505858887098162092091790346160355, 14)]
[TestCase(3.0, 2.0, 13)]
[TestCase(Constants.Pi, 2.288037795340032417959588909060233922889688153356222441199380, 13)]
[TestCase(3.5, 3.323350970447842551184064031264647217745405230229475865400889, 14)]
[TestCase(4.0, 6.0, 13)]
[TestCase(4.5, 11.63172839656744892914422410942626526210891830580316552890311, 13)]
[TestCase(5.0 - 1.0e-14, 23.99999999999963853175957637087420162718107213574617032780374, 14)]
[TestCase(5.0, 24.0, 13)]
[TestCase(5.0 + 1.0e-14, 24.00000000000036146824042363510111050137786752408660789873592, 13)]
[TestCase(5.5, 52.34277778455352018114900849241819367949013237611424488006401, 13)]
[TestCase(10.1, 454760.7514415859508673358368319076190405047458218916492282448, 12)]
[TestCase(150 + 1.0e-12, 3.8089226376496421386707466577615064443807882167327097140e+260, 12)]
public void Gamma(double z, double expected, int decimalPlaces)
{
AssertHelpers.AlmostEqualRelative(f, SpecialFunctions.GammaLn(x), 13);
AssertHelpers.AlmostEqualRelative(expected, SpecialFunctions.Gamma(z), decimalPlaces);
}
/// <summary>
/// Gamma function.
/// </summary>
/// <param name="x">Input X value.</param>
/// <param name="f">Function result.</param>
[TestCase(Double.NaN, Double.NaN)]
[TestCase(-1.5, 2.3632718012073547030642233111215269103967326081631802)]
[TestCase(-0.5, -3.544907701811032054596334966682290365595098912244773)]
[TestCase(0.1, 9.5135076986687312858079798958252325009137161063903012)]
[TestCase(1.0, 1.0)]
[TestCase(1.5, 0.88622692545275801364908374167057259139877472806119326)]
[TestCase(Constants.Pi / 2, 0.89056089038153932801065963535912100593354196288475879)]
[TestCase(2.0, 1.0)]
[TestCase(2.5, 1.3293403881791370204736256125058588870981620920917912)]
[TestCase(3.0, 2.0)]
[TestCase(Constants.Pi, 2.2880377953400324179595889090602339228896881533562229)]
[TestCase(3.5, 3.3233509704478425511840640312646472177454052302294767)]
[TestCase(4.0, 6.0)]
[TestCase(4.5, 11.631728396567448929144224109426265262108918305803166)]
[TestCase(5.0, 24.0)]
[TestCase(5.5, 52.342777784553520181149008492418193679490132376114268)]
[TestCase(10.1, 454760.75144158558537612486797710217749925965322893332)]
public void Gamma(double x, double f)
[TestCase(Double.NaN, Double.NaN, 14)]
[TestCase(1.000001e-35, 80.59047725479209894029636783061921392709972287131139201585211, 16)]
[TestCase(1.000001e-10, 23.02584992988323521564308637407936081168344192865285883337793, 15)]
[TestCase(1.000001e-5, 11.51291869289055371493077240324332039045238086972508869965363, 15)]
[TestCase(1.000001e-2, 4.599478872433667224554543378460164306444416156144779542513592, 16)]
[TestCase(0.1, 2.252712651734205959869701646368495118615627222294953765041739, 14)]
[TestCase(1.0 - 1.0e-14, 5.772156649015410852768463312546533565566459794933360600e-15, 0)]
[TestCase(1.0, 0.0, 14)]
[TestCase(1.0 + 1.0e-14, -5.77215664901524635936177848990288632404978978079827014e-15, 0)]
[TestCase(1.5, -0.12078223763524522234551844578164721225185272790259946836386, 13)]
[TestCase(Constants.Pi/2, -0.11590380084550241329912089415904874214542604767006895, 13)]
[TestCase(2.0, 0.0, 14)]
[TestCase(2.5, 0.284682870472919159632494669682701924320137695559894729250145, 13)]
[TestCase(3.0, 0.693147180559945309417232121458176568075500134360255254120680, 13)]
[TestCase(Constants.Pi, 0.82769459232343710152957855845235995115350173412073715, 13)]
[TestCase(3.5, 1.200973602347074224816021881450712995770238915468157197042113, 14)]
[TestCase(4.0, 1.791759469228055000812477358380702272722990692183004705855374, 14)]
[TestCase(4.5, 2.453736570842442220504142503435716157331823510689763131380823, 13)]
[TestCase(5.0 - 1.0e-14, 3.178053830347930558470257283303394288448414225994179545985931, 14)]
[TestCase(5.0, 3.178053830347945619646941601297055408873990960903515214096734, 14)]
[TestCase(5.0 + 1.0e-14, 3.178053830347960680823625919312848824873279228348981287761046, 13)]
[TestCase(5.5, 3.957813967618716293877400855822590998551304491975006780729532, 14)]
[TestCase(10.1, 13.02752673863323795851370097886835481188051062306253294740504, 14)]
[TestCase(150 + 1.0e-12, 600.0094705553324354062157737572509902987070089159051628001813, 13)]
[TestCase(1.001e+7, 1.51342135323817913130119829455205139905331697084416059779e+8, 13)]
public void GammaLn(double x, double expected, int decimalPlaces)
{
AssertHelpers.AlmostEqualRelative(f, SpecialFunctions.Gamma(x), 12);
AssertHelpers.AlmostEqualRelative(expected, SpecialFunctions.GammaLn(x), decimalPlaces);
}
/// <summary>

Loading…
Cancel
Save