Browse Source

Fixed unit tests for Silverlight

Signed-off-by: abratiychuk <18.05.2011>
pull/36/head
Abratiychuk 15 years ago
committed by Marcus Cuda
parent
commit
3f470bc0bc
  1. 792
      src/Numerics/Properties/Resources1.Designer.cs
  2. 4
      src/Numerics/Threading/CommonParallel.cs
  3. BIN
      src/Silverlight/MathNet.Numerics.snk
  4. 2
      src/Silverlight/Properties/AssemblyInfo.cs
  5. 26
      src/Silverlight/Silverlight.csproj
  6. 2
      src/SilverlightUnitTests/SilverlightUnitTests.Web/Properties/AssemblyInfo.cs
  7. 6
      src/SilverlightUnitTests/SilverlightUnitTests.Web/SilverlightUnitTests.Web.csproj
  8. BIN
      src/SilverlightUnitTests/SilverlightUnitTests/MathNet.Numerics.snk
  9. 4
      src/SilverlightUnitTests/SilverlightUnitTests/Properties/AssemblyInfo.cs
  10. 42
      src/SilverlightUnitTests/SilverlightUnitTests/SilverlightUnitTests.csproj
  11. 75
      src/UnitTests/ArrayHelpers.cs
  12. 2
      src/UnitTests/AssertHelpers.cs
  13. 126
      src/UnitTests/CombinatoricsTests/CombinatoricsCountingTest.cs
  14. 128
      src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs
  15. 27
      src/UnitTests/ComplexTests/Complex32Test.cs
  16. 77
      src/UnitTests/ComplexTests/ComplexTest.TextHandling.cs
  17. 17
      src/UnitTests/ComplexTests/ComplexTest.cs
  18. 20
      src/UnitTests/DistributionTests/CommonDistributionTests.cs
  19. 202
      src/UnitTests/DistributionTests/Continuous/BetaTests.cs
  20. 102
      src/UnitTests/DistributionTests/Continuous/CauchyTests.cs
  21. 156
      src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs
  22. 148
      src/UnitTests/DistributionTests/Continuous/ChiTests.cs
  23. 112
      src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs
  24. 190
      src/UnitTests/DistributionTests/Continuous/ErlangTests.cs
  25. 156
      src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs
  26. 217
      src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs
  27. 193
      src/UnitTests/DistributionTests/Continuous/GammaTests.cs
  28. 116
      src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs
  29. 179
      src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs
  30. 294
      src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs
  31. 168
      src/UnitTests/DistributionTests/Continuous/NormalTests.cs
  32. 131
      src/UnitTests/DistributionTests/Continuous/ParetoTests.cs
  33. 115
      src/UnitTests/DistributionTests/Continuous/RayleighTests.cs
  34. 175
      src/UnitTests/DistributionTests/Continuous/StableTests.cs
  35. 205
      src/UnitTests/DistributionTests/Continuous/StudentTTests.cs
  36. 164
      src/UnitTests/DistributionTests/Continuous/WeibullTests.cs
  37. 99
      src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs
  38. 105
      src/UnitTests/DistributionTests/Discrete/BinomialTests.cs
  39. 89
      src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs
  40. 102
      src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs
  41. 82
      src/UnitTests/DistributionTests/Discrete/GeometricTests.cs
  42. 138
      src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs
  43. 79
      src/UnitTests/DistributionTests/Discrete/NegativeBinomialTests.cs
  44. 95
      src/UnitTests/DistributionTests/Discrete/PoissonTests.cs
  45. 86
      src/UnitTests/DistributionTests/Discrete/ZipfTests.cs
  46. 15
      src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs
  47. 55
      src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs
  48. 90
      src/UnitTests/DistributionTests/Multivariate/MatrixNormalTests.cs
  49. 42
      src/UnitTests/DistributionTests/Multivariate/MultinomialTests.cs
  50. 100
      src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs
  51. 56
      src/UnitTests/DistributionTests/Multivariate/WishartTests.cs
  52. 10
      src/UnitTests/IntegralTransformsTests/FourierTest.cs
  53. 36
      src/UnitTests/IntegralTransformsTests/HartleyTest.cs
  54. 58
      src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs
  55. 98
      src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs
  56. 12
      src/UnitTests/IntegralTransformsTests/ParsevalTheoremTest.cs
  57. 85
      src/UnitTests/IntegrationTests/IntegrationTest.cs
  58. 41
      src/UnitTests/InterpolationTests/AkimaSplineTest.cs
  59. 36
      src/UnitTests/InterpolationTests/BulirschStoerRationalTest.cs
  60. 77
      src/UnitTests/InterpolationTests/CubicSplineTest.cs
  61. 48
      src/UnitTests/InterpolationTests/EquidistantPolynomialTest.cs
  62. 45
      src/UnitTests/InterpolationTests/FloaterHormannRationalTest.cs
  63. 28
      src/UnitTests/InterpolationTests/LinearInterpolationCase.cs
  64. 41
      src/UnitTests/InterpolationTests/LinearSplineTest.cs
  65. 41
      src/UnitTests/InterpolationTests/NevillePolynomialTest.cs
  66. 25
      src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs
  67. 54
      src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs
  68. 28
      src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs
  69. 28
      src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs
  70. 24
      src/UnitTests/LinearAlgebraTests/Complex/DenseMatrixTests.cs
  71. 40
      src/UnitTests/LinearAlgebraTests/Complex/DenseVectorTest.TextHandling.cs
  72. 2
      src/UnitTests/LinearAlgebraTests/Complex/DenseVectorTests.cs
  73. 40
      src/UnitTests/LinearAlgebraTests/Complex/DiagonalMatrixTests.cs
  74. 59
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/CholeskyTests.cs
  75. 35
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/EvdTests.cs
  76. 59
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs
  77. 68
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/LUTests.cs
  78. 59
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs
  79. 74
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/SvdTests.cs
  80. 59
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserCholeskyTests.cs
  81. 80
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserEvdTests.cs
  82. 59
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserGramSchmidtTests.cs
  83. 68
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserLUTests.cs
  84. 59
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserQRTests.cs
  85. 74
      src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserSvdTests.cs
  86. 6
      src/UnitTests/LinearAlgebraTests/Complex/IO/DelimitedReaderTests.cs
  87. 2
      src/UnitTests/LinearAlgebraTests/Complex/IO/DelimitedWriterTests.cs
  88. 2
      src/UnitTests/LinearAlgebraTests/Complex/IO/MatlabReaderTests.cs
  89. 2
      src/UnitTests/LinearAlgebraTests/Complex/IO/MatlabWriterTests.cs
  90. 14
      src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs
  91. 123
      src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs
  92. 234
      src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.cs
  93. 39
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/BiCgStabTest.cs
  94. 39
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/GpBiCgTest.cs
  95. 38
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/MlkBiCgStabTest.cs
  96. 38
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/TFQMRTest.cs
  97. 121
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/IteratorTest.cs
  98. 26
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs
  99. 10
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs
  100. 55
      src/UnitTests/LinearAlgebraTests/Complex/Solvers/StopCriterium/DivergenceStopCriteriumTest.cs

792
src/Numerics/Properties/Resources1.Designer.cs

@ -0,0 +1,792 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.225
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MathNet.Numerics.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MathNet.Numerics.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to The array arguments must have the same length..
/// </summary>
internal static string ArgumentArraysSameLength {
get {
return ResourceManager.GetString("ArgumentArraysSameLength", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The given array is the wrong length. Should be {0}..
/// </summary>
internal static string ArgumentArrayWrongLength {
get {
return ResourceManager.GetString("ArgumentArrayWrongLength", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The argument must be between 0 and 1..
/// </summary>
internal static string ArgumentBetween0And1 {
get {
return ResourceManager.GetString("ArgumentBetween0And1", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value cannot be in the range -1 &lt; x &lt; 1..
/// </summary>
internal static string ArgumentCannotBeBetweenOneAndNegativeOne {
get {
return ResourceManager.GetString("ArgumentCannotBeBetweenOneAndNegativeOne", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value must be even..
/// </summary>
internal static string ArgumentEven {
get {
return ResourceManager.GetString("ArgumentEven", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The histogram does not contains the value..
/// </summary>
internal static string ArgumentHistogramContainsNot {
get {
return ResourceManager.GetString("ArgumentHistogramContainsNot", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value is expected to be between {0} and {1} (including {0} and {1})..
/// </summary>
internal static string ArgumentInIntervalXYInclusive {
get {
return ResourceManager.GetString("ArgumentInIntervalXYInclusive", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to At least one item of {0} is a null reference (Nothing in Visual Basic)..
/// </summary>
internal static string ArgumentItemNull {
get {
return ResourceManager.GetString("ArgumentItemNull", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value must be greater than or equal to one..
/// </summary>
internal static string ArgumentLessThanOne {
get {
return ResourceManager.GetString("ArgumentLessThanOne", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to han the given upper bound..
/// </summary>
internal static string ArgumentLowerBoundLargerThanUpperBound {
get {
return ResourceManager.GetString("ArgumentLowerBoundLargerThanUpperBound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix dimensions must agree..
/// </summary>
internal static string ArgumentMatrixDimensions {
get {
return ResourceManager.GetString("ArgumentMatrixDimensions", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The requested matrix does not exist..
/// </summary>
internal static string ArgumentMatrixDoesNotExist {
get {
return ResourceManager.GetString("ArgumentMatrixDoesNotExist", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The matrix indices must not be out of range of the given matrix..
/// </summary>
internal static string ArgumentMatrixIndexOutOfRange {
get {
return ResourceManager.GetString("ArgumentMatrixIndexOutOfRange", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix must not be rank deficient..
/// </summary>
internal static string ArgumentMatrixNotRankDeficient {
get {
return ResourceManager.GetString("ArgumentMatrixNotRankDeficient", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix must not be singular..
/// </summary>
internal static string ArgumentMatrixNotSingular {
get {
return ResourceManager.GetString("ArgumentMatrixNotSingular", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix must be positive definite..
/// </summary>
internal static string ArgumentMatrixPositiveDefinite {
get {
return ResourceManager.GetString("ArgumentMatrixPositiveDefinite", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix column dimensions must agree..
/// </summary>
internal static string ArgumentMatrixSameColumnDimension {
get {
return ResourceManager.GetString("ArgumentMatrixSameColumnDimension", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix row dimensions must agree..
/// </summary>
internal static string ArgumentMatrixSameRowDimension {
get {
return ResourceManager.GetString("ArgumentMatrixSameRowDimension", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix must have exactly one column..
/// </summary>
internal static string ArgumentMatrixSingleColumn {
get {
return ResourceManager.GetString("ArgumentMatrixSingleColumn", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix must have exactly one column and row, thus have only one cell..
/// </summary>
internal static string ArgumentMatrixSingleColumnRow {
get {
return ResourceManager.GetString("ArgumentMatrixSingleColumnRow", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix must have exactly one row..
/// </summary>
internal static string ArgumentMatrixSingleRow {
get {
return ResourceManager.GetString("ArgumentMatrixSingleRow", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix must be square..
/// </summary>
internal static string ArgumentMatrixSquare {
get {
return ResourceManager.GetString("ArgumentMatrixSquare", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix must be symmetric..
/// </summary>
internal static string ArgumentMatrixSymmetric {
get {
return ResourceManager.GetString("ArgumentMatrixSymmetric", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Matrix must be symmetric positive definite..
/// </summary>
internal static string ArgumentMatrixSymmetricPositiveDefinite {
get {
return ResourceManager.GetString("ArgumentMatrixSymmetricPositiveDefinite", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to In the specified range, the minimum is greater than maximum..
/// </summary>
internal static string ArgumentMinValueGreaterThanMaxValue {
get {
return ResourceManager.GetString("ArgumentMinValueGreaterThanMaxValue", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value must be positive..
/// </summary>
internal static string ArgumentMustBePositive {
get {
return ResourceManager.GetString("ArgumentMustBePositive", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value must neither be infinite nor NaN..
/// </summary>
internal static string ArgumentNotInfinityNaN {
get {
return ResourceManager.GetString("ArgumentNotInfinityNaN", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value must not be negative (zero is ok)..
/// </summary>
internal static string ArgumentNotNegative {
get {
return ResourceManager.GetString("ArgumentNotNegative", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} is a null reference (Nothing in Visual Basic)..
/// </summary>
internal static string ArgumentNull {
get {
return ResourceManager.GetString("ArgumentNull", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value must be odd..
/// </summary>
internal static string ArgumentOdd {
get {
return ResourceManager.GetString("ArgumentOdd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} must be greater than {1}..
/// </summary>
internal static string ArgumentOutOfRangeGreater {
get {
return ResourceManager.GetString("ArgumentOutOfRangeGreater", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} must be greater than or equal to {1}..
/// </summary>
internal static string ArgumentOutOfRangeGreaterEqual {
get {
return ResourceManager.GetString("ArgumentOutOfRangeGreaterEqual", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The chosen parameter set is invalid (probably some value is out of range)..
/// </summary>
internal static string ArgumentParameterSetInvalid {
get {
return ResourceManager.GetString("ArgumentParameterSetInvalid", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The given expression does not represent a complex number..
/// </summary>
internal static string ArgumentParseComplexNumber {
get {
return ResourceManager.GetString("ArgumentParseComplexNumber", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value must be positive (and not zero)..
/// </summary>
internal static string ArgumentPositive {
get {
return ResourceManager.GetString("ArgumentPositive", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Size must be a Power of Two..
/// </summary>
internal static string ArgumentPowerOfTwo {
get {
return ResourceManager.GetString("ArgumentPowerOfTwo", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Size must be a Power of Two in every dimension..
/// </summary>
internal static string ArgumentPowerOfTwoEveryDimension {
get {
return ResourceManager.GetString("ArgumentPowerOfTwoEveryDimension", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The range between {0} and {1} must be less than or equal to {2}..
/// </summary>
internal static string ArgumentRangeLessEqual {
get {
return ResourceManager.GetString("ArgumentRangeLessEqual", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Arguments must be different objects..
/// </summary>
internal static string ArgumentReferenceDifferent {
get {
return ResourceManager.GetString("ArgumentReferenceDifferent", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Array must have exactly one dimension (and not be null)..
/// </summary>
internal static string ArgumentSingleDimensionArray {
get {
return ResourceManager.GetString("ArgumentSingleDimensionArray", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value is too large..
/// </summary>
internal static string ArgumentTooLarge {
get {
return ResourceManager.GetString("ArgumentTooLarge", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Value is too large for the current iteration limit..
/// </summary>
internal static string ArgumentTooLargeForIterationLimit {
get {
return ResourceManager.GetString("ArgumentTooLargeForIterationLimit", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Type mismatch..
/// </summary>
internal static string ArgumentTypeMismatch {
get {
return ResourceManager.GetString("ArgumentTypeMismatch", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Array length must be a multiple of {0}..
/// </summary>
internal static string ArgumentVectorLengthsMultipleOf {
get {
return ResourceManager.GetString("ArgumentVectorLengthsMultipleOf", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to All vectors must have the same dimensionality..
/// </summary>
internal static string ArgumentVectorsSameLength {
get {
return ResourceManager.GetString("ArgumentVectorsSameLength", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The vector must have 3 dimensions..
/// </summary>
internal static string ArgumentVectorThreeDimensional {
get {
return ResourceManager.GetString("ArgumentVectorThreeDimensional", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The given array is too small. It must be at least {0} long..
/// </summary>
internal static string ArrayTooSmall {
get {
return ResourceManager.GetString("ArrayTooSmall", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Big endian files are not supported..
/// </summary>
internal static string BigEndianNotSupported {
get {
return ResourceManager.GetString("BigEndianNotSupported", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The supplied collection is empty..
/// </summary>
internal static string CollectionEmpty {
get {
return ResourceManager.GetString("CollectionEmpty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Complex matrices are not supported..
/// </summary>
internal static string ComplexMatricesNotSupported {
get {
return ResourceManager.GetString("ComplexMatricesNotSupported", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An algorithm failed to converge..
/// </summary>
internal static string ConvergenceFailed {
get {
return ResourceManager.GetString("ConvergenceFailed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to This feature is not implemented yet (but is planned)..
/// </summary>
internal static string FeaturePlannedButNotImplementedYet {
get {
return ResourceManager.GetString("FeaturePlannedButNotImplementedYet", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The given file doesn&apos;t exist..
/// </summary>
internal static string FileDoesNotExist {
get {
return ResourceManager.GetString("FileDoesNotExist", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Invalid parameterization for the distribution..
/// </summary>
internal static string InvalidDistributionParameters {
get {
return ResourceManager.GetString("InvalidDistributionParameters", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Invalid Left Boundary Condition..
/// </summary>
internal static string InvalidLeftBoundaryCondition {
get {
return ResourceManager.GetString("InvalidLeftBoundaryCondition", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The operation could not be performed because the accumulator is empty..
/// </summary>
internal static string InvalidOperationAccumulatorEmpty {
get {
return ResourceManager.GetString("InvalidOperationAccumulatorEmpty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The operation could not be performed because the histogram is empty..
/// </summary>
internal static string InvalidOperationHistogramEmpty {
get {
return ResourceManager.GetString("InvalidOperationHistogramEmpty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Not enough points in the distribution..
/// </summary>
internal static string InvalidOperationHistogramNotEnoughPoints {
get {
return ResourceManager.GetString("InvalidOperationHistogramNotEnoughPoints", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No Samples Provided. Preparation Required..
/// </summary>
internal static string InvalidOperationNoSamplesProvided {
get {
return ResourceManager.GetString("InvalidOperationNoSamplesProvided", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Invalid Right Boundary Condition..
/// </summary>
internal static string InvalidRightBoundaryCondition {
get {
return ResourceManager.GetString("InvalidRightBoundaryCondition", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to ddd MMM dd HH:mm:ss yyyy.
/// </summary>
internal static string MatlabDateHeaderFormat {
get {
return ResourceManager.GetString("MatlabDateHeaderFormat", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The number of columns of a matrix must be positive..
/// </summary>
internal static string MatrixColumnsMustBePositive {
get {
return ResourceManager.GetString("MatrixColumnsMustBePositive", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The number of rows of a matrix must be positive..
/// </summary>
internal static string MatrixRowsMustBePositive {
get {
return ResourceManager.GetString("MatrixRowsMustBePositive", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The number of rows or columns of a matrix must be positive..
/// </summary>
internal static string MatrixRowsOrColumnsMustBePositive {
get {
return ResourceManager.GetString("MatrixRowsOrColumnsMustBePositive", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Only 1 and 2 dimensional arrays are supported..
/// </summary>
internal static string MoreThan2D {
get {
return ResourceManager.GetString("MoreThan2D", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Data must contain at least {0} values..
/// </summary>
internal static string MustContainAtLeast {
get {
return ResourceManager.GetString("MustContainAtLeast", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Name cannot contain a space. name: {0}.
/// </summary>
internal static string NameCannotContainASpace {
get {
return ResourceManager.GetString("NameCannotContainASpace", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} is not a supported type..
/// </summary>
internal static string NotSupportedType {
get {
return ResourceManager.GetString("NotSupportedType", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The two arguments can&apos;t be compared (maybe they are part of a partial ordering?).
/// </summary>
internal static string PartialOrderException {
get {
return ResourceManager.GetString("PartialOrderException", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The integer array does not represent a valid permutation..
/// </summary>
internal static string PermutationAsIntArrayInvalid {
get {
return ResourceManager.GetString("PermutationAsIntArrayInvalid", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The sampler&apos;s proposal distribution is not upper bounding the target density..
/// </summary>
internal static string ProposalDistributionNoUpperBound {
get {
return ResourceManager.GetString("ProposalDistributionNoUpperBound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The number of rows must greater than or equal to the number of columns..
/// </summary>
internal static string RowsLessThanColumns {
get {
return ResourceManager.GetString("RowsLessThanColumns", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The singular vectors were not computed..
/// </summary>
internal static string SingularVectorsNotComputed {
get {
return ResourceManager.GetString("SingularVectorsNotComputed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to This special case is not supported yet (but is planned)..
/// </summary>
internal static string SpecialCasePlannedButNotImplementedYet {
get {
return ResourceManager.GetString("SpecialCasePlannedButNotImplementedYet", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The given stop criterium already exist in the collection..
/// </summary>
internal static string StopCriteriumDuplicate {
get {
return ResourceManager.GetString("StopCriteriumDuplicate", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to There is no stop criterium in the collection..
/// </summary>
internal static string StopCriteriumMissing {
get {
return ResourceManager.GetString("StopCriteriumMissing", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to String parameter cannot be empty or null..
/// </summary>
internal static string StringNullOrEmpty {
get {
return ResourceManager.GetString("StringNullOrEmpty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to We only support sparse matrix with less than int.MaxValue elements..
/// </summary>
internal static string TooManyElements {
get {
return ResourceManager.GetString("TooManyElements", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The moment of the distribution is undefined..
/// </summary>
internal static string UndefinedMoment {
get {
return ResourceManager.GetString("UndefinedMoment", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to A user defined provider has not been specified..
/// </summary>
internal static string UserDefinedProviderNotSpecified {
get {
return ResourceManager.GetString("UserDefinedProviderNotSpecified", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The given work array is too small. Check work[0] for the corret size..
/// </summary>
internal static string WorkArrayTooSmall {
get {
return ResourceManager.GetString("WorkArrayTooSmall", resourceCulture);
}
}
}
}

4
src/Numerics/Threading/CommonParallel.cs

@ -362,7 +362,7 @@ namespace MathNet.Numerics.Threading
fromInclusive,
toExclusive,
() => 0.0,
(i, localData) => localData += body(i, localData),
(i, localData) => localData = body(i, localData),
localResult =>
{
lock (syncLock)
@ -415,7 +415,7 @@ namespace MathNet.Numerics.Threading
fromInclusive,
toExclusive,
() => 0.0f,
(i, localData) => localData += body(i, localData),
(i, localData) => localData = body(i, localData),
localResult =>
{
lock (syncLock)

BIN
src/Silverlight/MathNet.Numerics.snk

Binary file not shown.

2
src/Silverlight/Properties/AssemblyInfo.cs

@ -29,6 +29,7 @@
using System;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Math.NET Numerics for Silverlight")]
@ -42,6 +43,7 @@ using System.Runtime.InteropServices;
[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]
[assembly: Guid("7b66646f-f0ee-425d-9065-910d1937a2df")]
[assembly: InternalsVisibleTo("SilverlightUnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100ed2314a577643d859571b8b9307c6ff2670525c4598fbb307e57ea65ebf5d4417284cb3da9181636480b623f4db8cc3c1947244ba069df0df86e2431621f51a488f9929519a1c5d0ae595f6e2d0e4094685f0c1229ff658360acbb9f63f1a0258e984dda00dc7ad4fd16dbb550ec1ef8a11df138402b7c1998ee224e652c839b")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: AssemblyVersion("2011.04.17.0")]
[assembly: AssemblyFileVersion("2011.04.17")]

26
src/Silverlight/Silverlight.csproj

@ -61,6 +61,12 @@
<WarningLevel>4</WarningLevel>
<DocumentationFile>..\..\out\lib\SL4\MathNet.Numerics.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>MathNet.Numerics.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="System.Numerics, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
@ -186,6 +192,9 @@
<Compile Include="..\Numerics\Distributions\Discrete\NegativeBinomial.cs">
<Link>Distributions\Discrete\NegativeBinomial.cs</Link>
</Compile>
<Compile Include="..\Numerics\Distributions\Discrete\Poisson.cs">
<Link>Distributions\Discrete\Poisson.cs</Link>
</Compile>
<Compile Include="..\Numerics\Distributions\Discrete\Zipf.cs">
<Link>Distributions\Continuous\Zipf.cs</Link>
</Compile>
@ -915,6 +924,9 @@
<Compile Include="..\Numerics\NumberTheory\IntegerTheory.cs">
<Link>NumberTheory\IntegerTheory.cs</Link>
</Compile>
<Compile Include="..\Numerics\NumberTheory\IntegerTheory.Euclid.Big.cs">
<Link>NumberTheory\IntegerTheory.Euclid.Big.cs</Link>
</Compile>
<Compile Include="..\Numerics\NumberTheory\IntegerTheory.Euclid.cs">
<Link>NumberTheory\IntegerTheory.Euclid.cs</Link>
</Compile>
@ -924,8 +936,11 @@
<Compile Include="..\Numerics\Precision.cs">
<Link>Precision.cs</Link>
</Compile>
<Compile Include="..\Numerics\Properties\Resources.Designer.cs">
<Link>Resources.Designer.cs</Link>
<Compile Include="..\Numerics\Properties\Resources1.Designer.cs">
<Link>Properties\Resources1.Designer.cs</Link>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="..\Numerics\Random\AbstractRandomNumberGenerator.cs">
<Link>Random\AbstractRandomNumberGenerator.cs</Link>
@ -1037,7 +1052,9 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\Numerics\Properties\Resources.resx">
<Link>Resources.resx</Link>
<Link>Properties\Resources.resx</Link>
<LastGenOutput>Resources1.Designer.cs</LastGenOutput>
<Generator>ResXFileCodeGenerator</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
@ -1055,6 +1072,9 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="MathNet.Numerics.snk" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>

2
src/SilverlightUnitTests/SilverlightUnitTests.Web/Properties/AssemblyInfo.cs

@ -1,6 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Resources;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
@ -33,3 +34,4 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en")]

6
src/SilverlightUnitTests/SilverlightUnitTests.Web/SilverlightUnitTests.Web.csproj

@ -51,8 +51,14 @@
<Reference Include="System.EnterpriseServices" />
</ItemGroup>
<ItemGroup>
<Content Include="ClientBin\SilverlightTest1.xap" />
<Content Include="ClientBin\SilverlightTest2.xap" />
<Content Include="ClientBin\SilverlightUnitTests.xap" />
<Content Include="Silverlight.js" />
<Content Include="SilverlightTest1TestPage.aspx" />
<Content Include="SilverlightTest1TestPage.html" />
<Content Include="SilverlightTest2TestPage.aspx" />
<Content Include="SilverlightTest2TestPage.html" />
<Content Include="SilverlightUnitTestsTestPage.aspx" />
<Content Include="SilverlightUnitTestsTestPage.html" />
<Content Include="Web.config" />

BIN
src/SilverlightUnitTests/SilverlightUnitTests/MathNet.Numerics.snk

Binary file not shown.

4
src/SilverlightUnitTests/SilverlightUnitTests/Properties/AssemblyInfo.cs

@ -3,6 +3,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Resources;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
@ -34,4 +35,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en")]

42
src/SilverlightUnitTests/SilverlightUnitTests/SilverlightUnitTests.csproj

@ -87,16 +87,20 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>MathNet.Numerics.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="MathNet.Numerics">
<HintPath>..\..\..\out\debug\SL4\MathNet.Numerics.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.Silverlight.Testing">
<HintPath>$(MSBuildExtensionsPath)\..\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Testing\Microsoft.Silverlight.Testing.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight">
<HintPath>$(MSBuildExtensionsPath)\..\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Testing\Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll</HintPath>
</Reference>
<Reference Include="NUnit.Silverlight.Compatibility">
<HintPath>..\..\..\lib\NUnit.Silverlight.2.5.8\NUnit.Silverlight.Compatibility.dll</HintPath>
</Reference>
@ -107,15 +111,30 @@
<HintPath>..\..\..\lib\NUnit.Silverlight.2.5.8\NUnit.Silverlight.Metadata.dll</HintPath>
</Reference>
<Reference Include="System.Numerics, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Windows" />
<Reference Include="System.Windows">
<Private>True</Private>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="system" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Xml" />
<Reference Include="System.Windows.Browser" />
<Reference Include="system">
<Private>True</Private>
</Reference>
<Reference Include="System.Core">
<Private>True</Private>
</Reference>
<Reference Include="System.Net">
<Private>True</Private>
</Reference>
<Reference Include="System.Xml">
<Private>True</Private>
</Reference>
<Reference Include="System.Windows.Browser">
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\UnitTests\ArrayHelpers.cs">
<Link>ArrayHelpers.cs</Link>
</Compile>
<Compile Include="..\..\UnitTests\AssertHelpers.cs">
<Link>AssertHelpers.cs</Link>
</Compile>
@ -929,9 +948,9 @@
</ApplicationDefinition>
</ItemGroup>
<ItemGroup>
<None Include="MathNet.Numerics.snk" />
<None Include="Properties\AppManifest.xml" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
@ -944,6 +963,9 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="Properties\OutOfBrowserSettings.xml" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
<Import Condition="$(SilverlightVersion)=='v3.0'" Project="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SilverlightToolkit\Tools\v3.0)Microsoft.Silverlight.Toolkit.Build.targets" />
<Import Condition="$(SilverlightVersion)=='v4.0'" Project="$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SilverlightToolkit\Tools\v4.0)Microsoft.Silverlight.Toolkit.Build.targets" />

75
src/UnitTests/ArrayHelpers.cs

@ -0,0 +1,75 @@
// <copyright file="ArrayHelpers.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.UnitTests
{
using System;
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// Array and List helper/extention for Silverlight
/// </summary>
internal static class ArrayHelpers
{
/// <summary>
/// Converts an array of one type to an array of another type.
/// </summary>
/// <typeparam name="TInput">The type of the elements of the source array.</typeparam>
/// <typeparam name="TOutput">The type of the elements of the target array.</typeparam>
/// <param name="array">The one-dimensional, zero-based Array to convert to a target type.</param>
/// <param name="converter">A Converter that converts each element from one type to another type.</param>
/// <returns>An array of the target type containing the converted elements from the source array.</returns>
public static TOutput[] ConvertAll<TInput, TOutput>(TInput[] array, Converter<TInput, TOutput> converter)
{
#if SILVERLIGHT
if (array == null)
throw new ArgumentException();
return (from item in array select converter(item)).ToArray();
#else
return Array.ConvertAll(array, converter);
#endif
}
#if SILVERLIGHT
/// <summary>
/// Determines whether the specified array contains elements that match the conditions defined by the specified predicate.
/// </summary>
/// <typeparam name="T">The type of the elements of the array.</typeparam>
/// <param name="list">The one-dimensional, zero-based Array to search.</param>
/// <param name="match">The Predicate<> that defines the conditions of the elements to search for.</param>
/// <returns>true if array contains one or more elements that match the conditions defined by the specified predicate; otherwise, false.</returns>
public static bool Exists<T>(this List<T> list, Predicate<T> match)
{
if (list == null)
throw new ArgumentException();
return list.Any(item => match(item));
}
#endif
}
}

2
src/UnitTests/AssertHelpers.cs

@ -1,4 +1,4 @@
// <copyright file="AssertHelpers.cs" company="Math.NET">
// <copyright file="AssertHelpers.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics

126
src/UnitTests/CombinatoricsTests/CombinatoricsCountingTest.cs

@ -1,4 +1,4 @@
// <copyright file="CombinatoricsCountingTest.cs" company="Math.NET">
// <copyright file="CombinatoricsCountingTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -40,12 +40,19 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests
/// <param name="n">N parameter.</param>
/// <param name="k">K parameter.</param>
/// <param name="expected">Expected value.</param>
[Test, Sequential]
public void CanCountVariations([Values(0, 1, 10, 10, 10, 10, 10, 10)] int n, [Values(0, 0, 0, 2, 4, 6, 9, 10)] int k, [Values(1, 1, 1, 90, 5040, 151200, 3628800, 3628800)] long expected)
[TestCase(0, 0, 1)]
[TestCase(1, 0, 1)]
[TestCase(10, 0, 1)]
[TestCase(10, 2, 90)]
[TestCase(10, 4, 5040)]
[TestCase(10, 6, 151200)]
[TestCase(10, 9, 3628800)]
[TestCase(10, 10, 3628800)]
public void CanCountVariations(int n, int k, long expected)
{
Assert.AreEqual(
expected,
Combinatorics.Variations(n, k),
expected,
Combinatorics.Variations(n, k),
"Count the number of variations without repetition");
}
@ -54,12 +61,17 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests
/// </summary>
/// <param name="n">N parameter.</param>
/// <param name="k">K parameter.</param>
[Test, Sequential]
public void OutOfRangeVariationsCountToZero([Values(0, 10, 0, 1, -1, -1)] int n, [Values(1, 11, -1, -1, 0, 1)] int k)
[TestCase(0, 1)]
[TestCase(10, 11)]
[TestCase(0, -1)]
[TestCase(1, -1)]
[TestCase(-1, 0)]
[TestCase(-1, 1)]
public void OutOfRangeVariationsCountToZero(int n, int k)
{
Assert.AreEqual(
0,
Combinatorics.Variations(n, k),
0,
Combinatorics.Variations(n, k),
"The number of variations without repetition but out of the range must be 0.");
}
@ -69,12 +81,20 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests
/// <param name="n">N parameter.</param>
/// <param name="k">K parameter.</param>
/// <param name="expected">Expected value.</param>
[Test, Sequential]
public void CanCountVariationsWithRepetition([Values(0, 1, 10, 10, 10, 10, 10, 10, 10)] int n, [Values(0, 0, 0, 2, 4, 6, 9, 10, 11)] int k, [Values(1, 1, 1, 100, 10000, 1000000, 1000000000, 10000000000, 100000000000)] long expected)
[TestCase(0, 0, 1)]
[TestCase(1, 0, 1)]
[TestCase(10, 0, 1)]
[TestCase(10, 2, 100)]
[TestCase(10, 4, 10000)]
[TestCase(10, 6, 1000000)]
[TestCase(10, 9, 1000000000)]
[TestCase(10, 10, 10000000000)]
[TestCase(10, 11, 100000000000)]
public void CanCountVariationsWithRepetition(int n, int k, long expected)
{
Assert.AreEqual(
expected,
Combinatorics.VariationsWithRepetition(n, k),
expected,
Combinatorics.VariationsWithRepetition(n, k),
"Count the number of variations with repetition");
}
@ -83,12 +103,16 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests
/// </summary>
/// <param name="n">N parameter.</param>
/// <param name="k">K parameter.</param>
[Test, Sequential]
public void OutOfRangeVariationsWithRepetitionCountToZero([Values(0, 0, 1, -1, -1)] int n, [Values(1, -1, -1, 0, 1)] int k)
[TestCase(0, 1)]
[TestCase(0, -1)]
[TestCase(1, -1)]
[TestCase(-1, 0)]
[TestCase(-1, 1)]
public void OutOfRangeVariationsWithRepetitionCountToZero(int n, int k)
{
Assert.AreEqual(
0,
Combinatorics.VariationsWithRepetition(n, k),
0,
Combinatorics.VariationsWithRepetition(n, k),
"The number of variations with repetition but out of the range must be 0.");
}
@ -98,12 +122,19 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests
/// <param name="n">N parameter.</param>
/// <param name="k">K parameter.</param>
/// <param name="expected">Expected value.</param>
[Test, Sequential]
public void CanCountCombinations([Values(0, 1, 10, 10, 10, 10, 10, 10)] int n, [Values(0, 0, 0, 2, 4, 6, 9, 10)] int k, [Values(1, 1, 1, 45, 210, 210, 10, 1)] long expected)
[TestCase(0, 0, 1)]
[TestCase(1, 0, 1)]
[TestCase(10, 0, 1)]
[TestCase(10, 2, 45)]
[TestCase(10, 4, 210)]
[TestCase(10, 6, 210)]
[TestCase(10, 9, 10)]
[TestCase(10, 10, 1)]
public void CanCountCombinations(int n, int k, long expected)
{
Assert.AreEqual(
expected,
Combinatorics.Combinations(n, k),
expected,
Combinatorics.Combinations(n, k),
"Count the number of combinations without repetition");
}
@ -112,12 +143,17 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests
/// </summary>
/// <param name="n">N parameter.</param>
/// <param name="k">K parameter.</param>
[Test, Sequential]
public void OutOfRangeCombinationsCountToZero([Values(0, 10, 0, 1, -1, -1)] int n, [Values(1, 11, -1, -1, 0, 1)] int k)
[TestCase(0, 1)]
[TestCase(10, 11)]
[TestCase(0, -1)]
[TestCase(1, -1)]
[TestCase(-1, 0)]
[TestCase(-1, 1)]
public void OutOfRangeCombinationsCountToZero(int n, int k)
{
Assert.AreEqual(
0,
Combinatorics.Combinations(n, k),
0,
Combinatorics.Combinations(n, k),
"The number of combinations without repetition but out of the range must be 0.");
}
@ -127,12 +163,20 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests
/// <param name="n">N parameter.</param>
/// <param name="k">K parameter.</param>
/// <param name="expected">Expected value.</param>
[Test, Sequential]
public void CanCountCombinationsWithRepetition([Values(0, 1, 10, 10, 10, 10, 10, 10, 10)] int n, [Values(0, 0, 0, 2, 4, 6, 9, 10, 11)] int k, [Values(1, 1, 1, 55, 715, 5005, 48620, 92378, 167960)] long expected)
[TestCase(0, 0, 1)]
[TestCase(1, 0, 1)]
[TestCase(10, 0, 1)]
[TestCase(10, 2, 55)]
[TestCase(10, 4, 715)]
[TestCase(10, 6, 5005)]
[TestCase(10, 9, 48620)]
[TestCase(10, 10, 92378)]
[TestCase(10, 11, 167960)]
public void CanCountCombinationsWithRepetition(int n, int k, long expected)
{
Assert.AreEqual(
expected,
Combinatorics.CombinationsWithRepetition(n, k),
expected,
Combinatorics.CombinationsWithRepetition(n, k),
"Count the number of combinations with repetition");
}
@ -141,12 +185,16 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests
/// </summary>
/// <param name="n">N parameter.</param>
/// <param name="k">K parameter.</param>
[Test, Sequential]
public void OutOfRangeCombinationsWithRepetitionCountToZero([Values(0, 0, 1, -1, -1)] int n, [Values(1, -1, -1, 0, 1)] int k)
[TestCase(0, 1)]
[TestCase(0, -1)]
[TestCase(1, -1)]
[TestCase(-1, 0)]
[TestCase(-1, 1)]
public void OutOfRangeCombinationsWithRepetitionCountToZero(int n, int k)
{
Assert.AreEqual(
0,
Combinatorics.CombinationsWithRepetition(n, k),
0,
Combinatorics.CombinationsWithRepetition(n, k),
"The number of combinations with repetition but out of the range must be 0.");
}
@ -155,12 +203,16 @@ namespace MathNet.Numerics.UnitTests.CombinatoricsTests
/// </summary>
/// <param name="n">N parameter.</param>
/// <param name="expected">Expected value.</param>
[Test, Sequential]
public void CanCountPermutations([Values(0, 1, 2, 8, 15)] int n, [Values(1, 1, 2, 40320, 1307674368000)] long expected)
[TestCase(0, 1)]
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(8, 40320)]
[TestCase(15, 1307674368000)]
public void CanCountPermutations(int n, long expected)
{
Assert.AreEqual(
expected,
Combinatorics.Permutations(n),
expected,
Combinatorics.Permutations(n),
"Count the number of permutations");
}
}

128
src/UnitTests/ComplexTests/Complex32Test.TextHandling.cs

@ -1,4 +1,4 @@
// <copyright file="Complex32Test.TextHandling.cs" company="Math.NET">
// <copyright file="Complex32Test.TextHandling.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -42,23 +42,35 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
/// <param name="real">Real part.</param>
/// <param name="imag">Imaginary part.</param>
/// <param name="expected">Expected value.</param>
[Test, Sequential]
public void CanFormatComplexToString(
[Values(1, 1, 1, 0, 0, 0, Single.NaN, Single.NaN, 0, Single.PositiveInfinity, 1.1f, -1.1f, 0, 0, 1.1f)] float real,
[Values(-2, 2, 0, -2, 2, 0, Single.NaN, 0, Single.NaN, Single.PositiveInfinity, 0, 0, 1.1f, -1.1f, 1.1f)] float imag,
[Values("(1, -2)", "(1, 2)", "(1, 0)", "(0, -2)", "(0, 2)", "(0, 0)", "({1}, {1})", "({1}, 0)", "(0, {1})", "({2}, {2})", "(1{0}1, 0)", "(-1{0}1, 0)", "(0, 1{0}1)", "(0, -1{0}1)", "(1{0}1, 1{0}1)")] string expected)
[TestCase(1, -2, "(1, -2)")]
[TestCase(1, 2, "(1, 2)")]
[TestCase(1, 0, "(1, 0)")]
[TestCase(0, -2, "(0, -2)")]
[TestCase(0, 2, "(0, 2)")]
[TestCase(0, 0, "(0, 0)")]
[TestCase(Single.NaN, Single.NaN, "({1}, {1})")]
[TestCase(Single.NaN, 0, "({1}, 0)")]
[TestCase(0, Single.NaN, "(0, {1})")]
[TestCase(Single.PositiveInfinity, Single.PositiveInfinity, "({2}, {2})")]
[TestCase(1.1f, 0, "(1{0}1, 0)")]
[TestCase(-1.1f, 0, "(-1{0}1, 0)")]
[TestCase(0, 1.1f, "(0, 1{0}1)")]
[TestCase(0, -1.1f, "(0, -1{0}1)")]
[TestCase(1.1f, 1.1f, "(1{0}1, 1{0}1)")]
public void CanFormatComplexToString(float real, float imag, string expected)
{
var numberFormat = NumberFormatInfo.CurrentInfo;
var a = new Complex32(real, imag);
Assert.AreEqual(
String.Format(
expected,
numberFormat.NumberDecimalSeparator,
numberFormat.NaNSymbol,
numberFormat.PositiveInfinitySymbol),
expected,
numberFormat.NumberDecimalSeparator,
numberFormat.NaNSymbol,
numberFormat.PositiveInfinitySymbol),
a.ToString());
}
#if !SILVERLIGHT
/// <summary>
/// Can format complex to string with culture.
/// </summary>
@ -66,14 +78,14 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
/// <param name="nan">Not a number name.</param>
/// <param name="infinity">Infinity name.</param>
/// <param name="number">Complex Number.</param>
[Test, Sequential]
public void CanFormatComplexToStringWithCulture(
[Values("en-US", "tr-TR", "de-DE", "de-CH", "he-IL")] string cultureName,
[Values("NaN", "NaN", "n. def.", "n. def.", "לא מספר")] string nan,
[Values("Infinity", "Infinity", "+unendlich", "+unendlich", "אינסוף חיובי")] string infinity,
[Values("1.1", "1,1", "1,1", "1.1", "1.1")] string number)
[TestCase("en-US", "NaN", "Infinity", "1.1")]
[TestCase("tr-TR", "NaN", "Infinity", "1,1")]
[TestCase("de-DE", "n. def.", "+unendlich", "1,1")]
[TestCase("de-CH", "n. def.", "+unendlich", "1.1")]
[TestCase("he-IL", "לא מספר", "אינסוף חיובי", "1.1")]
public void CanFormatComplexToStringWithCulture(string cultureName, string nan, string infinity, string number)
{
var provider = CultureInfo.GetCultureInfo(cultureName);
var provider = new CultureInfo(cultureName);
Assert.AreEqual("(" + nan + ", " + nan + ")", Complex32.NaN.ToString(provider));
Assert.AreEqual("(" + infinity + ", " + infinity + ")", Complex32.Infinity.ToString(provider));
Assert.AreEqual("(0, 0)", Complex32.Zero.ToString(provider));
@ -83,6 +95,7 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
Assert.AreEqual("(0, " + String.Format("{0}", number) + ")", new Complex32(0.0f, 1.1f).ToString(provider));
Assert.AreEqual("(" + String.Format("{0}", number) + ", " + String.Format("{0}", number) + ")", new Complex32(1.1f, 1.1f).ToString(provider));
}
#endif
/// <summary>
/// Can format complex to string with format.
@ -132,14 +145,11 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
/// <param name="expectedReal">Expected real part.</param>
/// <param name="expectedImaginary">Expected imaginary part.</param>
/// <param name="cultureName">Culture ID.</param>
[Test, Sequential]
public void CanParseStringToComplexWithCulture(
[Values("-1 -2i", "-1 - 2i ")] string text,
[Values(-1, -1)] float expectedReal,
[Values(-2, -2)] float expectedImaginary,
[Values("en-US", "de-CH")] string cultureName)
[TestCase("-1 -2i", -1, -2, "en-US")]
[TestCase("-1 - 2i ", -1, -2, "de-CH")]
public void CanParseStringToComplexWithCulture(string text, float expectedReal, float expectedImaginary, string cultureName)
{
var parsed = Complex32.Parse(text, CultureInfo.GetCultureInfo(cultureName));
var parsed = Complex32.Parse(text, new CultureInfo(cultureName));
Assert.AreEqual(expectedReal, parsed.Real);
Assert.AreEqual(expectedImaginary, parsed.Imaginary);
}
@ -150,11 +160,35 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
/// <param name="str">String to parse.</param>
/// <param name="expectedReal">Expected real part.</param>
/// <param name="expectedImaginary">Expected imaginary part.</param>
[Test, Sequential]
public void CanTryParseStringToComplexWithInvariant(
[Values("1", "-1", "-i", "i", "2i", "1 + 2i", "1+2i", "1 - 2i", "1-2i", "1,2 ", "1 , 2", "1,2i", "-1, -2i", " - 1 , - 2 i ", "(+1,2i)", "(-1 , -2)", "(-1 , -2i)", "(+1e1 , -2e-2i)", "(-1E1 -2e2i)", "(-1e+1 -2e2i)", "(-1e1 -2e+2i)", "(-1e-1 -2E2i)", "(-1e1 -2e-2i)", "(-1E+1 -2e+2i)", "(-1e-1,-2e-2i)", "(+1 +2i)", "(-1E+1 -2e+2i)", "(-1e-1,-2e-2i)")] string str,
[Values(1, -1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 10, -10, -10, -10, -0.1f, -10, -10, -0.1f, 1, -10, -0.1f)] float expectedReal,
[Values(0, 0, -1, 1, 2, 2, 2, -2, -2, 2, 2, 2, -2, -2, 2, -2, -2, -0.02f, -200, -200, -200, -200, -0.02f, -200, -0.02f, 2, -200, -0.02f)] float expectedImaginary)
[TestCase("1", 1, 0)]
[TestCase("-1", -1, 0)]
[TestCase("-i", 0, -1)]
[TestCase("i", 0, 1)]
[TestCase("2i", 0, 2)]
[TestCase("1 + 2i", 1, 2)]
[TestCase("1+2i", 1, 2)]
[TestCase("1 - 2i", 1, -2)]
[TestCase("1-2i", 1, -2)]
[TestCase("1,2 ", 1, 2)]
[TestCase("1 , 2", 1, 2)]
[TestCase("1,2i", 1, 2)]
[TestCase("-1, -2i", -1, -2)]
[TestCase(" - 1 , - 2 i ", -1, -2)]
[TestCase("(+1,2i)", 1, 2)]
[TestCase("(-1 , -2)", -1, -2)]
[TestCase("(-1 , -2i)", -1, -2)]
[TestCase("(+1e1 , -2e-2i)", 10, -0.02f)]
[TestCase("(-1E1 -2e2i)", -10, -200)]
[TestCase("(-1e+1 -2e2i)", -10, -200)]
[TestCase("(-1e1 -2e+2i)", -10, -200)]
[TestCase("(-1e-1 -2E2i)", -0.1f, -200)]
[TestCase("(-1e1 -2e-2i)", -10, -0.02f)]
[TestCase("(-1E+1 -2e+2i)", -10, -200)]
[TestCase("(-1e-1,-2e-2i)", -0.1f, -0.02f)]
[TestCase("(+1 +2i)", 1, 2)]
[TestCase("(-1E+1 -2e+2i)", -10, -200)]
[TestCase("(-1e-1,-2e-2i)", -0.1f, -0.02f)]
public void CanTryParseStringToComplexWithInvariant(string str, float expectedReal, float expectedImaginary)
{
var invariantCulture = CultureInfo.InvariantCulture;
Complex32 z;
@ -204,22 +238,27 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
Assert.AreEqual(float.NaN, z.Imaginary, "D3");
ret = Complex32.TryParse(
float.MaxValue.ToString("R") + " " + float.MinValue.ToString("R") + "i",
float.MaxValue.ToString("R") + " " + float.MinValue.ToString("R") + "i",
out z);
Assert.IsTrue(ret, "E1");
Assert.AreEqual(float.MaxValue, z.Real, "E2");
Assert.AreEqual(float.MinValue, z.Imaginary, "E3");
}
#if !SILVERLIGHT
/// <summary>
/// Try parse can handle symbols with a culture.
/// </summary>
/// <param name="cultureName">Culture ID.</param>
[Test]
public void TryParseCanHandleSymbolsWithCulture([Values("en-US", "tr-TR", "de-DE", "de-CH", "he-IL")] string cultureName)
[TestCase("en-US")]
[TestCase("tr-TR")]
[TestCase("de-DE")]
[TestCase("de-CH")]
[TestCase("he-IL")]
public void TryParseCanHandleSymbolsWithCulture(string cultureName)
{
Complex32 z;
var culture = CultureInfo.GetCultureInfo(cultureName);
var culture = new CultureInfo(cultureName);
var ni = culture.NumberFormat;
var separator = culture.TextInfo.ListSeparator;
var ret = Complex32.TryParse(
@ -244,20 +283,35 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
Assert.AreEqual(float.NaN, z.Imaginary, "D3");
ret = Complex32.TryParse(
float.MaxValue.ToString("R", culture) + " " + float.MinValue.ToString("R", culture) + "i",
culture,
float.MaxValue.ToString("R", culture) + " " + float.MinValue.ToString("R", culture) + "i",
culture,
out z);
Assert.IsTrue(ret, "E1");
Assert.AreEqual(float.MaxValue, z.Real, "E2");
Assert.AreEqual(float.MinValue, z.Imaginary, "E3");
}
#endif
/// <summary>
/// Try parse returns false when given bad value with invariant.
/// </summary>
/// <param name="str">String to parse.</param>
[Test]
public void TryParseReturnsFalseWhenGivenBadValueWithInvariant([Values("", "+", "1-", "i+", "1/2i", "1i+2i", "i1i", "(1i,2)", "1e+", "1e", "1,", ",1", null, "()", "( )")] string str)
[TestCase("")]
[TestCase("+")]
[TestCase("1-")]
[TestCase("i+")]
[TestCase("1/2i")]
[TestCase("1i+2i")]
[TestCase("i1i")]
[TestCase("(1i,2)")]
[TestCase("1e+")]
[TestCase("1e")]
[TestCase("1,")]
[TestCase(",1")]
[TestCase(null)]
[TestCase("()")]
[TestCase("( )")]
public void TryParseReturnsFalseWhenGivenBadValueWithInvariant(string str)
{
Complex32 z;
var ret = Complex32.TryParse(str, CultureInfo.InvariantCulture, out z);

27
src/UnitTests/ComplexTests/Complex32Test.cs

@ -1,4 +1,4 @@
// <copyright file="Complex32Test.cs" company="Math.NET">
// <copyright file="Complex32Test.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -127,8 +127,12 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
/// <param name="imag">Imaginary part.</param>
/// <param name="expectedReal">Expected real part.</param>
/// <param name="expectedImag">Expected imaginary part.</param>
[Test, Sequential]
public void CanComputeNaturalLogarithm([Values(0.0f, 0.0f, -1.0f, -111.1f, 111.1f)] float real, [Values(0.0f, 1.0f, 1.0f, 111.1f, -111.1f)] float imag, [Values(float.NegativeInfinity, 0.0f, 0.34657359027997264f, 5.0570042869255571f, 5.0570042869255571f)] float expectedReal, [Values(0.0f, 1.5707963267948966f, 2.3561944901923448f, 2.3561944901923448f, -0.78539816339744828f)] float expectedImag)
[TestCase(0.0f, 0.0f, float.NegativeInfinity, 0.0f)]
[TestCase(0.0f, 1.0f, 0.0f, 1.5707963267948966f)]
[TestCase(-1.0f, 1.0f, 0.34657359027997264f, 2.3561944901923448f)]
[TestCase(-111.1f, 111.1f, 5.0570042869255571f, 2.3561944901923448f)]
[TestCase(111.1f, -111.1f, 5.0570042869255571f, -0.78539816339744828f)]
public void CanComputeNaturalLogarithm(float real, float imag, float expectedReal, float expectedImag)
{
var value = new Complex32(real, imag);
var expected = new Complex32(expectedReal, expectedImag);
@ -548,8 +552,11 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
/// <param name="real">Real part.</param>
/// <param name="imag">Imaginary part.</param>
/// <param name="expected">Expected value.</param>
[Test, Sequential]
public void CanComputeMagnitude([Values(0.0f, 0.0f, -1.0f, -111.1f)] float real, [Values(0.0f, 1.0f, 1.0f, 111.1f)] float imag, [Values(0.0f, 1.0f, 1.4142135623730951f, 157.11912677965086f)] float expected)
[TestCase(0.0f, 0.0f, 0.0f)]
[TestCase(0.0f, 1.0f, 1.0f)]
[TestCase(-1.0f, 1.0f, 1.4142135623730951f)]
[TestCase(-111.1f, 111.1f, 157.11912677965086f)]
public void CanComputeMagnitude(float real, float imag, float expected)
{
Assert.AreEqual(expected, new Complex32(real, imag).Magnitude);
}
@ -561,8 +568,14 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
/// <param name="imag">Imaginary part.</param>
/// <param name="expectedReal">Expected real value.</param>
/// <param name="expectedImag">Expected imaginary value.</param>
[Test, Sequential]
public void CanComputeSign([Values(float.PositiveInfinity, float.PositiveInfinity, float.NegativeInfinity, float.NegativeInfinity, 0.0f, -1.0f, -111.1f)] float real, [Values(float.PositiveInfinity, float.NegativeInfinity, float.PositiveInfinity, float.NegativeInfinity, 0.0f, 1.0f, 111.1f)] float imag, [Values((float)Constants.Sqrt1Over2, (float)Constants.Sqrt1Over2, (float)-Constants.Sqrt1Over2, (float)-Constants.Sqrt1Over2, 0.0f, -0.70710678118654746f, -0.70710678118654746f)] float expectedReal, [Values((float)Constants.Sqrt1Over2, (float)-Constants.Sqrt1Over2, (float)-Constants.Sqrt1Over2, (float)Constants.Sqrt1Over2, 0.0f, 0.70710678118654746f, 0.70710678118654746f)] float expectedImag)
[TestCase(float.PositiveInfinity, float.PositiveInfinity, (float)Constants.Sqrt1Over2, (float)Constants.Sqrt1Over2)]
[TestCase(float.PositiveInfinity, float.NegativeInfinity, (float)Constants.Sqrt1Over2, (float)-Constants.Sqrt1Over2)]
[TestCase(float.NegativeInfinity, float.PositiveInfinity, (float)-Constants.Sqrt1Over2, (float)-Constants.Sqrt1Over2)]
[TestCase(float.NegativeInfinity, float.NegativeInfinity, (float)-Constants.Sqrt1Over2, (float)Constants.Sqrt1Over2)]
[TestCase(0.0f, 0.0f, 0.0f, 0.0f)]
[TestCase(-1.0f, 1.0f, -0.70710678118654746f, 0.70710678118654746f)]
[TestCase(-111.1f, 111.1f, -0.70710678118654746f, 0.70710678118654746f)]
public void CanComputeSign(float real, float imag, float expectedReal, float expectedImag)
{
Assert.AreEqual(new Complex32(expectedReal, expectedImag), new Complex32(real, imag).Sign);
}

77
src/UnitTests/ComplexTests/ComplexTest.TextHandling.cs

@ -1,4 +1,4 @@
// <copyright file="ComplexTest.TextHandling.cs" company="Math.NET">
// <copyright file="ComplexTest.TextHandling.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -44,14 +44,11 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
/// <param name="expectedReal">Expected real part.</param>
/// <param name="expectedImaginary">Expected imaginary part.</param>
/// <param name="cultureName">Culture ID.</param>
[Test, Sequential]
public void CanParseStringToComplexWithCulture(
[Values("-1 -2i", "-1 - 2i ")] string text,
[Values(-1, -1)] double expectedReal,
[Values(-2, -2)] double expectedImaginary,
[Values("en-US", "de-CH")] string cultureName)
[TestCase("-1 -2i", -1, -2, "en-US")]
[TestCase("-1 - 2i ", -1, -2, "de-CH")]
public void CanParseStringToComplexWithCulture(string text, double expectedReal, double expectedImaginary, string cultureName)
{
var parsed = text.ToComplex(CultureInfo.GetCultureInfo(cultureName));
var parsed = text.ToComplex(new CultureInfo(cultureName));
Assert.AreEqual(expectedReal, parsed.Real);
Assert.AreEqual(expectedImaginary, parsed.Imaginary);
}
@ -62,11 +59,35 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
/// <param name="str">String to parse.</param>
/// <param name="expectedReal">Expected real part.</param>
/// <param name="expectedImaginary">Expected imaginary part.</param>
[Test, Sequential]
public void CanTryParseStringToComplexWithInvariant(
[Values("1", "-1", "-i", "i", "2i", "1 + 2i", "1+2i", "1 - 2i", "1-2i", "1,2 ", "1 , 2", "1,2i", "-1, -2i", " - 1 , - 2 i ", "(+1,2i)", "(-1 , -2)", "(-1 , -2i)", "(+1e1 , -2e-2i)", "(-1E1 -2e2i)", "(-1e+1 -2e2i)", "(-1e1 -2e+2i)", "(-1e-1 -2E2i)", "(-1e1 -2e-2i)", "(-1E+1 -2e+2i)", "(-1e-1,-2e-2i)", "(+1 +2i)", "(-1E+1 -2e+2i)", "(-1e-1,-2e-2i)")] string str,
[Values(1, -1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, -1, -1, 1, -1, -1, 10, -10, -10, -10, -0.1, -10, -10, -0.1, 1, -10, -0.1)] double expectedReal,
[Values(0, 0, -1, 1, 2, 2, 2, -2, -2, 2, 2, 2, -2, -2, 2, -2, -2, -0.02, -200, -200, -200, -200, -0.02, -200, -0.02, 2, -200, -0.02)] double expectedImaginary)
[TestCase("1", 1, 0)]
[TestCase("-1", -1, 0)]
[TestCase("-i", 0, -1)]
[TestCase("i", 0, 1)]
[TestCase("2i", 0, 2)]
[TestCase("1 + 2i", 1, 2)]
[TestCase("1+2i", 1, 2)]
[TestCase("1 - 2i", 1, -2)]
[TestCase("1-2i", 1, -2)]
[TestCase("1,2 ", 1, 2)]
[TestCase("1 , 2", 1, 2)]
[TestCase("1,2i", 1, 2)]
[TestCase("-1, -2i", -1, -2)]
[TestCase(" - 1 , - 2 i ", -1, -2)]
[TestCase("(+1,2i)", 1, 2)]
[TestCase("(-1 , -2)", -1, -2)]
[TestCase("(-1 , -2i)", -1, -2)]
[TestCase("(+1e1 , -2e-2i)", 10, -0.02)]
[TestCase("(-1E1 -2e2i)", -10, -200)]
[TestCase("(-1e+1 -2e2i)", -10, -200)]
[TestCase("(-1e1 -2e+2i)", -10, -200)]
[TestCase("(-1e-1 -2E2i)", -0.1, -200)]
[TestCase("(-1e1 -2e-2i)", -10, -0.02)]
[TestCase("(-1E+1 -2e+2i)", -10, -200)]
[TestCase("(-1e-1,-2e-2i)", -0.1, -0.02)]
[TestCase("(+1 +2i)", 1, 2)]
[TestCase("(-1E+1 -2e+2i)", -10, -200)]
[TestCase("(-1e-1,-2e-2i)", -0.1, -0.02)]
public void CanTryParseStringToComplexWithInvariant(string str, double expectedReal, double expectedImaginary)
{
var invariantCulture = CultureInfo.InvariantCulture;
Complex z;
@ -126,15 +147,20 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
Assert.AreEqual(double.MinValue, z.Imaginary, "E3");
}
#if !SILVERLIGHT
/// <summary>
/// Try parse can handle symbols with a culture.
/// </summary>
/// <param name="cultureName">Culture ID.</param>
[Test]
public void TryParseCanHandleSymbolsWithCulture([Values("en-US", "tr-TR", "de-DE", "de-CH", "he-IL")] string cultureName)
[TestCase("en-US")]
[TestCase("tr-TR")]
[TestCase("de-DE")]
[TestCase("de-CH")]
[TestCase("he-IL")]
public void TryParseCanHandleSymbolsWithCulture(string cultureName)
{
Complex z;
var culture = CultureInfo.GetCultureInfo(cultureName);
var culture = new CultureInfo(cultureName);
var ni = culture.NumberFormat;
var separator = culture.TextInfo.ListSeparator;
@ -168,13 +194,28 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
Assert.AreEqual(double.MaxValue, z.Real, "E2");
Assert.AreEqual(double.MinValue, z.Imaginary, "E3");
}
#endif
/// <summary>
/// Try parse returns <c>false</c> when given bad value with invariant.
/// </summary>
/// <param name="str">String to parse.</param>
[Test]
public void TryParseReturnsFalseWhenGivenBadValueWithInvariant([Values("", "+", "1-", "i+", "1/2i", "1i+2i", "i1i", "(1i,2)", "1e+", "1e", "1,", ",1", null, "()", "( )")] string str)
[TestCase("")]
[TestCase("+")]
[TestCase("1-")]
[TestCase("i+")]
[TestCase("1/2i")]
[TestCase("1i+2i")]
[TestCase("i1i")]
[TestCase("(1i,2)")]
[TestCase("1e+")]
[TestCase("1e")]
[TestCase("1,")]
[TestCase(",1")]
[TestCase(null)]
[TestCase("()")]
[TestCase("( )")]
public void TryParseReturnsFalseWhenGivenBadValueWithInvariant(string str)
{
Complex z;
var ret = str.TryToComplex(CultureInfo.InvariantCulture, out z);

17
src/UnitTests/ComplexTests/ComplexTest.cs

@ -1,4 +1,4 @@
// <copyright file="ComplexTest.cs" company="Math.NET">
// <copyright file="ComplexTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -42,8 +42,11 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
/// <param name="imag">Imaginary part.</param>
/// <param name="expectedReal">Expected real part.</param>
/// <param name="expectedImag">Expected imaginary part.</param>
[Test, Sequential]
public void CanComputeExponential([Values(0.0, 0.0, -1.0, -111.1)] double real, [Values(0.0, 1.0, 1.0, 111.1)] double imag, [Values(1.0, 0.54030230586813977, 0.19876611034641295, -2.3259065941590448e-49)] double expectedReal, [Values(0.0, 0.8414709848078965, 0.30955987565311222, -5.1181940185795617e-49)] double expectedImag)
[TestCase(0.0, 0.0, 1.0, 0.0)]
[TestCase(0.0, 1.0, 0.54030230586813977, 0.8414709848078965)]
[TestCase(-1.0, 1.0, 0.19876611034641295, 0.30955987565311222)]
[TestCase(-111.1, 111.1, -2.3259065941590448e-49, -5.1181940185795617e-49)]
public void CanComputeExponential(double real, double imag, double expectedReal, double expectedImag)
{
var value = new Complex(real, imag);
var expected = new Complex(expectedReal, expectedImag);
@ -57,8 +60,12 @@ namespace MathNet.Numerics.UnitTests.ComplexTests
/// <param name="imag">Imaginary part.</param>
/// <param name="expectedReal">Expected real part.</param>
/// <param name="expectedImag">Expected imaginary part.</param>
[Test, Sequential]
public void CanComputeNaturalLogarithm([Values(0.0, 0.0, -1.0, -111.1, 111.1)] double real, [Values(0.0, 1.0, 1.0, 111.1, -111.1)] double imag, [Values(double.NegativeInfinity, 0.0, 0.34657359027997264, 5.0570042869255571, 5.0570042869255571)] double expectedReal, [Values(0.0, 1.5707963267948966, 2.3561944901923448, 2.3561944901923448, -0.78539816339744828)] double expectedImag)
[TestCase(0.0, 0.0, double.NegativeInfinity, 0.0)]
[TestCase(0.0, 1.0, 0.0, 1.5707963267948966)]
[TestCase(-1.0, 1.0, 0.34657359027997264, 2.3561944901923448)]
[TestCase(-111.1, 111.1, 5.0570042869255571, 2.3561944901923448)]
[TestCase(111.1, -111.1, 5.0570042869255571, -0.78539816339744828)]
public void CanComputeNaturalLogarithm(double real, double imag, double expectedReal, double expectedImag)
{
var value = new Complex(real, imag);
var expected = new Complex(expectedReal, expectedImag);

20
src/UnitTests/DistributionTests/CommonDistributionTests.cs

@ -1,4 +1,4 @@
// <copyright file="CommonDistributionTests.cs" company="Math.NET">
// <copyright file="CommonDistributionTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -106,20 +106,20 @@ namespace MathNet.Numerics.UnitTests.DistributionTests
{
_discreteDistributions = new List<IDiscreteDistribution>
{
new Bernoulli(0.6),
new Binomial(0.7, 10),
new Categorical(new[] { 0.7, 0.3 }),
new Bernoulli(0.6),
new Binomial(0.7, 10),
new Categorical(new[] { 0.7, 0.3 }),
new DiscreteUniform(1, 10)
};
_continuousDistributions = new List<IContinuousDistribution>
{
new Beta(1.0, 1.0),
new ContinuousUniform(0.0, 1.0),
new Gamma(1.0, 1.0),
new Normal(0.0, 1.0),
new Weibull(1.0, 1.0),
new LogNormal(1.0, 1.0),
new Beta(1.0, 1.0),
new ContinuousUniform(0.0, 1.0),
new Gamma(1.0, 1.0),
new Normal(0.0, 1.0),
new Weibull(1.0, 1.0),
new LogNormal(1.0, 1.0),
new StudentT(0.0, 1.0, 5.0)
};
}

202
src/UnitTests/DistributionTests/Continuous/BetaTests.cs

@ -1,4 +1,4 @@
// <copyright file="BetaTests.cs" company="Math.NET">
// <copyright file="BetaTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,17 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="a">Parameter A.</param>
/// <param name="b">Parameter B.</param>
[Test, Sequential]
public void CanCreateBeta([Values(0.0, 0.0, 1.0, 1.0, 9.0, 5.0, 1.0, Double.PositiveInfinity, 0.0, Double.PositiveInfinity)] double a, [Values(0.0, 0.1, 0.0, 1.0, 1.0, 100.0, Double.PositiveInfinity, 1.0, Double.PositiveInfinity, 0.0)] double b)
[TestCase(0.0, 0.0)]
[TestCase(0.0, 0.1)]
[TestCase(1.0, 0.0)]
[TestCase(1.0, 1.0)]
[TestCase(9.0, 1.0)]
[TestCase(5.0, 100.0)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(0.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, 0.0)]
public void CanCreateBeta(double a, double b)
{
var n = new Beta(a, b);
Assert.AreEqual(a, n.A);
@ -87,8 +96,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can Set Shape A
/// </summary>
/// <param name="a">New A value.</param>
[Test]
public void CanSetShapeA([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double a)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetShapeA(double a)
{
new Beta(1.0, 1.0)
{
@ -110,8 +124,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set shape B.
/// </summary>
/// <param name="b">New B value.</param>
[Test]
public void CanSetShapeB([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double b)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetShapeB(double b)
{
new Beta(1.0, 1.0)
{
@ -122,7 +141,7 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <summary>
/// Set shape B fails with negative B.
/// </summary>
[Test, Sequential]
[Test]
public void SetShapeBFailsWithNegativeB()
{
var n = new Beta(1.0, 1.0);
@ -135,8 +154,17 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="a">Parameter A.</param>
/// <param name="b">Parameter B.</param>
/// <param name="mean">Mean value.</param>
[Test, Sequential]
public void ValidateMean([Values(0.0, 0.0, 1.0, 1.0, 9.0, 5.0, 1.0, Double.PositiveInfinity, 0.0, Double.PositiveInfinity)] double a, [Values(0.0, 0.1, 0.0, 1.0, 1.0, 100.0, Double.PositiveInfinity, 1.0, Double.PositiveInfinity, 0.0)] double b, [Values(0.5, 0.0, 1.0, 0.5, 0.9, 0.047619047619047619047616, 0.0, 1.0, 0.0, 1.0)] double mean)
[TestCase(0.0, 0.0, 0.5)]
[TestCase(0.0, 0.1, 0.0)]
[TestCase(1.0, 0.0, 1.0)]
[TestCase(1.0, 1.0, 0.5)]
[TestCase(9.0, 1.0, 0.9)]
[TestCase(5.0, 100.0, 0.047619047619047619047616)]
[TestCase(1.0, Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 1.0, 1.0)]
[TestCase(0.0, Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 0.0, 1.0)]
public void ValidateMean(double a, double b, double mean)
{
var n = new Beta(a, b);
Assert.AreEqual(mean, n.Mean);
@ -148,8 +176,17 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="a">Parameter A.</param>
/// <param name="b">Parameter B.</param>
/// <param name="entropy">Entropy value.</param>
[Test, Sequential]
public void ValidateEntropy([Values(0.0, 0.0, 1.0, 1.0, 9.0, 5.0, 1.0, Double.PositiveInfinity, 0.0, Double.PositiveInfinity)] double a, [Values(0.0, 0.1, 0.0, 1.0, 1.0, 100.0, Double.PositiveInfinity, 1.0, Double.PositiveInfinity, 0.0)] double b, [Values(0.693147180559945309417232121458176568075500134360255, 0.0, 0.0, 0.0, -1.3083356884473304939016015849561625204060922267565917, -2.5201623187602743679459255108827601222133603091753153, 0.0, 0.0, 0.0, 0.0)] double entropy)
[TestCase(0.0, 0.0, 0.693147180559945309417232121458176568075500134360255)]
[TestCase(0.0, 0.1, 0.0)]
[TestCase(1.0, 0.0, 0.0)]
[TestCase(1.0, 1.0, 0.0)]
[TestCase(9.0, 1.0, -1.3083356884473304939016015849561625204060922267565917)]
[TestCase(5.0, 100.0, -2.5201623187602743679459255108827601222133603091753153)]
[TestCase(1.0, Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 1.0, 0.0)]
[TestCase(0.0, Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 0.0, 0.0)]
public void ValidateEntropy(double a, double b, double entropy)
{
var n = new Beta(a, b);
AssertHelpers.AlmostEqual(entropy, n.Entropy, 14);
@ -161,8 +198,17 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="a">Parameter A.</param>
/// <param name="b">Parameter B.</param>
/// <param name="skewness">Skewness value.</param>
[Test, Sequential]
public void ValidateSkewness([Values(0.0, 0.0, 1.0, 1.0, 9.0, 5.0, 1.0, Double.PositiveInfinity, 0.0, Double.PositiveInfinity)] double a, [Values(0.0, 0.1, 0.0, 1.0, 1.0, 100.0, Double.PositiveInfinity, 1.0, Double.PositiveInfinity, 0.0)] double b, [Values(0.0, 2.0, -2.0, 0.0, -1.4740554623801777107177478829647496373009282424841579, 0.81759410927553430354583159143895018978562196953345572, 2.0, -2.0, 2.0, -2.0)] double skewness)
[TestCase(0.0, 0.0, 0.0)]
[TestCase(0.0, 0.1, 2.0)]
[TestCase(1.0, 0.0, -2.0)]
[TestCase(1.0, 1.0, 0.0)]
[TestCase(9.0, 1.0, -1.4740554623801777107177478829647496373009282424841579)]
[TestCase(5.0, 100.0, 0.81759410927553430354583159143895018978562196953345572)]
[TestCase(1.0, Double.PositiveInfinity, 2.0)]
[TestCase(Double.PositiveInfinity, 1.0, -2.0)]
[TestCase(0.0, Double.PositiveInfinity, 2.0)]
[TestCase(Double.PositiveInfinity, 0.0, -2.0)]
public void ValidateSkewness(double a, double b, double skewness)
{
var n = new Beta(a, b);
AssertHelpers.AlmostEqual(skewness, n.Skewness, 15);
@ -174,8 +220,17 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="a">Parameter A.</param>
/// <param name="b">Parameter B.</param>
/// <param name="mode">Mode value.</param>
[Test, Sequential]
public void ValidateMode([Values(0.0, 0.0, 1.0, 1.0, 9.0, 5.0, 1.0, Double.PositiveInfinity, 0.0, Double.PositiveInfinity)] double a, [Values(0.0, 0.1, 0.0, 1.0, 1.0, 100.0, Double.PositiveInfinity, 1.0, Double.PositiveInfinity, 0.0)] double b, [Values(0.5, 0.0, 1.0, 0.5, 1.0, 0.038834951456310676243255386452801758423447608947753906, 0.0, 1.0, 0.0, 1.0)] double mode)
[TestCase(0.0, 0.0, 0.5)]
[TestCase(0.0, 0.1, 0.0)]
[TestCase(1.0, 0.0, 1.0)]
[TestCase(1.0, 1.0, 0.5)]
[TestCase(9.0, 1.0, 1.0)]
[TestCase(5.0, 100.0, 0.038834951456310676243255386452801758423447608947753906)]
[TestCase(1.0, Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 1.0, 1.0)]
[TestCase(0.0, Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 0.0, 1.0)]
public void ValidateMode(double a, double b, double mode)
{
var n = new Beta(a, b);
Assert.AreEqual(mode, n.Mode);
@ -276,12 +331,39 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="b">Parameter B.</param>
/// <param name="x">Input value X.</param>
/// <param name="pdf">Density value.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 9.0, 9.0, 9.0, 9.0, 9.0, 5.0, 5.0, 5.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, 0.0, 0.0, 0.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double a,
[Values(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 100, 100, 100, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, 0.0, 0.0, 0.0)] double b,
[Values(0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, -1.0, 2.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0)] double x,
[Values(Double.PositiveInfinity, 0.0, Double.PositiveInfinity, Double.PositiveInfinity, 0.0, 0.0, 0.0, 0.0, Double.PositiveInfinity, 1.0, 1.0, 1.0, 0.0, 0.03515625, 9.0, 0.0, 0.0, 0.0, 1.0881845516040810386311829462908430145307026037926335e-21, 0.0, Double.PositiveInfinity, 0.0, 0.0, 0.0, 0.0, Double.PositiveInfinity, Double.PositiveInfinity, 0.0, 0.0, 0.0, 0.0, Double.PositiveInfinity)] double pdf)
[TestCase(0.0, 0.0, 0.0, Double.PositiveInfinity)]
[TestCase(0.0, 0.0, 0.5, 0.0)]
[TestCase(0.0, 0.0, 1.0, Double.PositiveInfinity)]
[TestCase(0.0, 0.1, 0.0, Double.PositiveInfinity)]
[TestCase(0.0, 0.1, 0.5, 0.0)]
[TestCase(0.0, 0.1, 1.0, 0.0)]
[TestCase(1.0, 0.0, 0.0, 0.0)]
[TestCase(1.0, 0.0, 0.5, 0.0)]
[TestCase(1.0, 0.0, 1.0, Double.PositiveInfinity)]
[TestCase(1.0, 1.0, 0.0, 1.0)]
[TestCase(1.0, 1.0, 0.5, 1.0)]
[TestCase(1.0, 1.0, 1.0, 1.0)]
[TestCase(9.0, 1.0, 0.0, 0.0)]
[TestCase(9.0, 1.0, 0.5, 0.03515625)]
[TestCase(9.0, 1.0, 1.0, 9.0)]
[TestCase(9.0, 1.0, -1.0, 0.0)]
[TestCase(9.0, 1.0, 2.0, 0.0)]
[TestCase(5.0, 100, 0.0, 0.0)]
[TestCase(5.0, 100, 0.5, 1.0881845516040810386311829462908430145307026037926335e-21)]
[TestCase(5.0, 100, 1.0, 0.0)]
[TestCase(1.0, Double.PositiveInfinity, 0.0, Double.PositiveInfinity)]
[TestCase(1.0, Double.PositiveInfinity, 0.5, 0.0)]
[TestCase(1.0, Double.PositiveInfinity, 1.0, 0.0)]
[TestCase(Double.PositiveInfinity, 1.0, 0.0, 0.0)]
[TestCase(Double.PositiveInfinity, 1.0, 0.5, 0.0)]
[TestCase(Double.PositiveInfinity, 1.0, 1.0, Double.PositiveInfinity)]
[TestCase(0.0, Double.PositiveInfinity, 0.0, Double.PositiveInfinity)]
[TestCase(0.0, Double.PositiveInfinity, 0.5, 0.0)]
[TestCase(0.0, Double.PositiveInfinity, 1.0, 0.0)]
[TestCase(Double.PositiveInfinity, 0.0, 0.0, 0.0)]
[TestCase(Double.PositiveInfinity, 0.0, 0.5, 0.0)]
[TestCase(Double.PositiveInfinity, 0.0, 1.0, Double.PositiveInfinity)]
public void ValidateDensity(double a, double b, double x, double pdf)
{
var n = new Beta(a, b);
AssertHelpers.AlmostEqual(pdf, n.Density(x), 13);
@ -294,12 +376,39 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="b">Parameter B.</param>
/// <param name="x">Input value X.</param>
/// <param name="pdfln">Density log value.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 9.0, 9.0, 9.0, 9.0, 9.0, 5.0, 5.0, 5.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, 0.0, 0.0, 0.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double a,
[Values(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 100, 100, 100, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, 0.0, 0.0, 0.0)] double b,
[Values(0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, -1.0, 2.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0)] double x,
[Values(Double.PositiveInfinity, Double.NegativeInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, Double.PositiveInfinity, 0.0, 0.0, 0.0, Double.NegativeInfinity, -3.3479528671433430925473664978203611353090199592365458, 2.1972245773362193827904904738450514092949811156454996, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, -51.447830024537682154565870837960406410586196074573801, Double.NegativeInfinity, Double.PositiveInfinity, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, Double.PositiveInfinity)] double pdfln)
[TestCase(0.0, 0.0, 0.0, Double.PositiveInfinity)]
[TestCase(0.0, 0.0, 0.5, Double.NegativeInfinity)]
[TestCase(0.0, 0.0, 1.0, Double.PositiveInfinity)]
[TestCase(0.0, 0.1, 0.0, Double.PositiveInfinity)]
[TestCase(0.0, 0.1, 0.5, Double.NegativeInfinity)]
[TestCase(0.0, 0.1, 1.0, Double.NegativeInfinity)]
[TestCase(1.0, 0.0, 0.0, Double.NegativeInfinity)]
[TestCase(1.0, 0.0, 0.5, Double.NegativeInfinity)]
[TestCase(1.0, 0.0, 1.0, Double.PositiveInfinity)]
[TestCase(1.0, 1.0, 0.0, 0.0)]
[TestCase(1.0, 1.0, 0.5, 0.0)]
[TestCase(1.0, 1.0, 1.0, 0.0)]
[TestCase(9.0, 1.0, 0.0, Double.NegativeInfinity)]
[TestCase(9.0, 1.0, 0.5, -3.3479528671433430925473664978203611353090199592365458)]
[TestCase(9.0, 1.0, 1.0, 2.1972245773362193827904904738450514092949811156454996)]
[TestCase(9.0, 1.0, -1.0, Double.NegativeInfinity)]
[TestCase(9.0, 1.0, 2.0, Double.NegativeInfinity)]
[TestCase(5.0, 100, 0.0, Double.NegativeInfinity)]
[TestCase(5.0, 100, 0.5, -51.447830024537682154565870837960406410586196074573801)]
[TestCase(5.0, 100, 1.0, Double.NegativeInfinity)]
[TestCase(1.0, Double.PositiveInfinity, 0.0, Double.PositiveInfinity)]
[TestCase(1.0, Double.PositiveInfinity, 0.5, Double.NegativeInfinity)]
[TestCase(1.0, Double.PositiveInfinity, 1.0, Double.NegativeInfinity)]
[TestCase(Double.PositiveInfinity, 1.0, 0.0, Double.NegativeInfinity)]
[TestCase(Double.PositiveInfinity, 1.0, 0.5, Double.NegativeInfinity)]
[TestCase(Double.PositiveInfinity, 1.0, 1.0, Double.PositiveInfinity)]
[TestCase(0.0, Double.PositiveInfinity, 0.0, Double.PositiveInfinity)]
[TestCase(0.0, Double.PositiveInfinity, 0.5, Double.NegativeInfinity)]
[TestCase(0.0, Double.PositiveInfinity, 1.0, Double.NegativeInfinity)]
[TestCase(Double.PositiveInfinity, 0.0, 0.0, Double.NegativeInfinity)]
[TestCase(Double.PositiveInfinity, 0.0, 0.5, Double.NegativeInfinity)]
[TestCase(Double.PositiveInfinity, 0.0, 1.0, Double.PositiveInfinity)]
public void ValidateDensityLn(double a, double b, double x, double pdfln)
{
var n = new Beta(a, b);
AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
@ -312,12 +421,37 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="b">Parameter B.</param>
/// <param name="x">Input value X.</param>
/// <param name="cdf">Cumulative distribution value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 9.0, 9.0, 9.0, 5.0, 5.0, 5.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, 0.0, 0.0, 0.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double a,
[Values(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 100, 100, 100, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, 0.0, 0.0, 0.0)] double b,
[Values(0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0, 0.0, 0.5, 1.0)] double x,
[Values(0.5, 0.5, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.5, 1.0, 0.0, 0.001953125, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0)] double cdf)
[TestCase(0.0, 0.0, 0.0, 0.5)]
[TestCase(0.0, 0.0, 0.5, 0.5)]
[TestCase(0.0, 0.0, 1.0, 1.0)]
[TestCase(0.0, 0.1, 0.0, 1.0)]
[TestCase(0.0, 0.1, 0.5, 1.0)]
[TestCase(0.0, 0.1, 1.0, 1.0)]
[TestCase(1.0, 0.0, 0.0, 0.0)]
[TestCase(1.0, 0.0, 0.5, 0.0)]
[TestCase(1.0, 0.0, 1.0, 1.0)]
[TestCase(1.0, 1.0, 0.0, 0.0)]
[TestCase(1.0, 1.0, 0.5, 0.5)]
[TestCase(1.0, 1.0, 1.0, 1.0)]
[TestCase(9.0, 1.0, 0.0, 0.0)]
[TestCase(9.0, 1.0, 0.5, 0.001953125)]
[TestCase(9.0, 1.0, 1.0, 1.0)]
[TestCase(5.0, 100, 0.0, 0.0)]
[TestCase(5.0, 100, 0.5, 1.0)]
[TestCase(5.0, 100, 1.0, 1.0)]
[TestCase(1.0, Double.PositiveInfinity, 0.0, 1.0)]
[TestCase(1.0, Double.PositiveInfinity, 0.5, 1.0)]
[TestCase(1.0, Double.PositiveInfinity, 1.0, 1.0)]
[TestCase(Double.PositiveInfinity, 1.0, 0.0, 0.0)]
[TestCase(Double.PositiveInfinity, 1.0, 0.5, 0.0)]
[TestCase(Double.PositiveInfinity, 1.0, 1.0, 1.0)]
[TestCase(0.0, Double.PositiveInfinity, 0.0, 1.0)]
[TestCase(0.0, Double.PositiveInfinity, 0.5, 1.0)]
[TestCase(0.0, Double.PositiveInfinity, 1.0, 1.0)]
[TestCase(Double.PositiveInfinity, 0.0, 0.0, 0.0)]
[TestCase(Double.PositiveInfinity, 0.0, 0.5, 0.0)]
[TestCase(Double.PositiveInfinity, 0.0, 1.0, 1.0)]
public void ValidateCumulativeDistribution(double a, double b, double x, double cdf)
{
var n = new Beta(a, b);
AssertHelpers.AlmostEqual(cdf, n.CumulativeDistribution(x), 13);

102
src/UnitTests/DistributionTests/Continuous/CauchyTests.cs

@ -1,4 +1,4 @@
// <copyright file="CauchyTests.cs" company="Math.NET">
// <copyright file="CauchyTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -62,8 +62,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void CanCreateCauchy([Values(0.0, 0.0, 0.0, 10.0, -5.0, 0.0)] double location, [Values(0.1, 1.0, 10.0, 11.0, 100.0, Double.PositiveInfinity)] double scale)
[TestCase(0.0, 0.1)]
[TestCase(0.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(10.0, 11.0)]
[TestCase(-5.0, 100.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void CanCreateCauchy(double location, double scale)
{
var n = new Cauchy(location, scale);
Assert.AreEqual(location, n.Location);
@ -75,8 +80,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void CauchyCreateFailsWithBadParameters([Values(Double.NaN, 1.0, Double.NaN, 1.0)] double location, [Values(1.0, Double.NaN, Double.NaN, 0.0)] double scale)
[TestCase(Double.NaN, 1.0)]
[TestCase(1.0, Double.NaN)]
[TestCase(Double.NaN, Double.NaN)]
[TestCase(1.0, 0.0)]
public void CauchyCreateFailsWithBadParameters(double location, double scale)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Cauchy(location, scale));
}
@ -95,8 +103,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set location.
/// </summary>
/// <param name="location">Location value.</param>
[Test]
public void CanSetLocation([Values(-10.0, -0.0, 0.0, 0.1, 1.0)] double location)
[TestCase(-10.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
public void CanSetLocation(double location)
{
new Cauchy
{
@ -118,8 +130,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set scale.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void CanSetScale([Values(1.0, 2.0, 12.0)] double scale)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(12.0)]
public void CanSetScale(double scale)
{
new Cauchy
{
@ -142,8 +156,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void ValidateEntropy([Values(-0.0, 0.0, 0.1, 1.0, 10.0)] double location, [Values(2.0, 2.0, 4.0, 10.0, 11.0)] double scale)
[TestCase(-0.0, 2.0)]
[TestCase(0.0, 2.0)]
[TestCase(0.1, 4.0)]
[TestCase(1.0, 10.0)]
[TestCase(10.0, 11.0)]
public void ValidateEntropy(double location, double scale)
{
var n = new Cauchy(location, scale);
Assert.AreEqual(Math.Log(4.0 * Constants.Pi * scale), n.Entropy);
@ -164,8 +182,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void ValidateMode([Values(-0.0, 0.0, 0.1, 1.0, 10.0, 0.0)] double location, [Values(2.0, 2.0, 4.0, 10.0, 11.0, Double.PositiveInfinity)] double scale)
[TestCase(-0.0, 2.0)]
[TestCase(0.0, 2.0)]
[TestCase(0.1, 4.0)]
[TestCase(1.0, 10.0)]
[TestCase(10.0, 11.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateMode(double location, double scale)
{
var n = new Cauchy(location, scale);
Assert.AreEqual(location, n.Mode);
@ -176,8 +199,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void ValidateMedian([Values(-0.0, 0.0, 0.1, 1.0, 10.0, 0.0)] double location, [Values(2.0, 2.0, 4.0, 10.0, 11.0, Double.PositiveInfinity)] double scale)
[TestCase(-0.0, 2.0)]
[TestCase(0.0, 2.0)]
[TestCase(0.1, 4.0)]
[TestCase(1.0, 10.0)]
[TestCase(10.0, 11.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateMedian(double location, double scale)
{
var n = new Cauchy(location, scale);
Assert.AreEqual(location, n.Median);
@ -188,8 +216,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void ValidateMinimum([Values(-0.0, 0.0, 0.1, 1.0, 10.0, 0.0)] double location, [Values(2.0, 2.0, 4.0, 10.0, 11.0, Double.PositiveInfinity)] double scale)
[TestCase(-0.0, 2.0)]
[TestCase(0.0, 2.0)]
[TestCase(0.1, 4.0)]
[TestCase(1.0, 10.0)]
[TestCase(10.0, 11.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateMinimum(double location, double scale)
{
var n = new Cauchy(location, scale);
Assert.AreEqual(Double.NegativeInfinity, n.Minimum);
@ -200,8 +233,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void ValidateMaximum([Values(-0.0, 0.0, 0.1, 1.0, 10.0, 0.0)] double location, [Values(2.0, 2.0, 4.0, 10.0, 11.0, Double.PositiveInfinity)] double scale)
[TestCase(-0.0, 2.0)]
[TestCase(0.0, 2.0)]
[TestCase(0.1, 4.0)]
[TestCase(1.0, 10.0)]
[TestCase(10.0, 11.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateMaximum(double location, double scale)
{
var n = new Cauchy(location, scale);
Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
@ -212,8 +250,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void ValidateDensity([Values(0.0, 0.0, 0.0, -5.0, 0.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity, 1.0)] double scale)
[TestCase(0.0, 0.1)]
[TestCase(0.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(-5.0, 100.0)]
[TestCase(0.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, 1.0)]
public void ValidateDensity(double location, double scale)
{
var n = new Cauchy(location, scale);
for (var i = 0; i < 11; i++)
@ -228,8 +271,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void ValidateDensityLn([Values(0.0, 0.0, 0.0, -5.0, 0.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity, 1.0)] double scale)
[TestCase(0.0, 0.1)]
[TestCase(0.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(-5.0, 100.0)]
[TestCase(0.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, 1.0)]
public void ValidateDensityLn(double location, double scale)
{
var n = new Cauchy(location, scale);
for (var i = 0; i < 11; i++)
@ -265,8 +313,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution([Values(0.0, 0.0, 0.0, -5.0, 0.0)] double location, [Values(0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double scale)
[TestCase(0.0, 0.1)]
[TestCase(0.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(-5.0, 100.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateCumulativeDistribution(double location, double scale)
{
var n = new Cauchy(location, scale);
for (var i = 0; i < 11; i++)

156
src/UnitTests/DistributionTests/Continuous/ChiSquareTests.cs

@ -1,4 +1,4 @@
// <copyright file="ChiSquareTests.cs" company="Math.NET">
// <copyright file="ChiSquareTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -50,8 +50,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can create chi square.
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
[Test]
public void CanCreateChiSquare([Values(1.0, 3.0, Double.PositiveInfinity)] double dof)
[TestCase(1.0)]
[TestCase(3.0)]
[TestCase(Double.PositiveInfinity)]
public void CanCreateChiSquare(double dof)
{
var n = new ChiSquare(dof);
Assert.AreEqual(dof, n.DegreesOfFreedom);
@ -61,8 +63,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Chi square create fails with bad parameters.
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
[Test]
public void ChiSquareCreateFailsWithBadParameters([Values(0.0, -1.0, -100.0, Double.NegativeInfinity, Double.NaN)] double dof)
[TestCase(0.0)]
[TestCase(-1.0)]
[TestCase(-100.0)]
[TestCase(Double.NegativeInfinity)]
[TestCase(Double.NaN)]
public void ChiSquareCreateFailsWithBadParameters(double dof)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new ChiSquare(dof));
}
@ -81,8 +87,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set degrees of freedom.
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
[Test]
public void CanSetDoF([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double dof)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetDoF(double dof)
{
new ChiSquare(1.0)
{
@ -94,8 +103,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set Degrees of freedom fails with non-positive value.
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
[Test]
public void SetDofFailsWithNonPositiveDoF([Values(-1.0, -0.0, 0.0)] double dof)
[TestCase(-1.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
public void SetDofFailsWithNonPositiveDoF(double dof)
{
var n = new ChiSquare(1.0);
Assert.Throws<ArgumentOutOfRangeException>(() => n.DegreesOfFreedom = dof);
@ -105,8 +116,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate mean.
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
[Test]
public void ValidateMean([Values(1.0, 2.0, 2.5, 5.0, Double.PositiveInfinity)] double dof)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(2.5)]
[TestCase(5.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMean(double dof)
{
var n = new ChiSquare(dof);
Assert.AreEqual(dof, n.Mean);
@ -116,8 +131,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate variance.
/// </summary>
/// <param name="dof">Degrees of freedom</param>
[Test]
public void ValidateVariance([Values(1.0, 2.0, 2.5, 3.0, Double.PositiveInfinity)] double dof)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(2.5)]
[TestCase(3.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateVariance(double dof)
{
var n = new ChiSquare(dof);
Assert.AreEqual(2 * dof, n.Variance);
@ -127,8 +146,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate standard deviation
/// </summary>
/// <param name="dof">Degrees of freedom</param>
[Test]
public void ValidateStdDev([Values(1.0, 2.0, 2.5, 3.0, Double.PositiveInfinity)] double dof)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(2.5)]
[TestCase(3.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateStdDev(double dof)
{
var n = new ChiSquare(dof);
Assert.AreEqual(Math.Sqrt(n.Variance), n.StdDev);
@ -138,8 +161,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate mode.
/// </summary>
/// <param name="dof">Degrees of freedom</param>
[Test]
public void ValidateMode([Values(1.0, 2.0, 2.5, 3.0, Double.PositiveInfinity)] double dof)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(2.5)]
[TestCase(3.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMode(double dof)
{
var n = new ChiSquare(dof);
Assert.AreEqual(dof - 2, n.Mode);
@ -149,8 +176,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate median.
/// </summary>
/// <param name="dof">Degrees of freedom</param>
[Test]
public void ValidateMedian([Values(1.0, 2.0, 2.5, 3.0, Double.PositiveInfinity)] double dof)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(2.5)]
[TestCase(3.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMedian(double dof)
{
var n = new ChiSquare(dof);
Assert.AreEqual(dof - (2.0 / 3.0), n.Median);
@ -181,10 +212,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
[Values(0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity)] double x)
[TestCase(1.0, 0.0)]
[TestCase(1.0, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(1.0, 5.5)]
[TestCase(1.0, 110.1)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(2.0, 0.0)]
[TestCase(2.0, 0.1)]
[TestCase(2.0, 1.0)]
[TestCase(2.0, 5.5)]
[TestCase(2.0, 110.1)]
[TestCase(2.0, Double.PositiveInfinity)]
[TestCase(2.5, 0.0)]
[TestCase(2.5, 0.1)]
[TestCase(2.5, 1.0)]
[TestCase(2.5, 5.5)]
[TestCase(2.5, 110.1)]
[TestCase(2.5, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(Double.PositiveInfinity, 5.5)]
[TestCase(Double.PositiveInfinity, 110.1)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateDensity(double dof, double x)
{
var n = new ChiSquare(dof);
Assert.AreEqual((Math.Pow(x, (dof / 2.0) - 1.0) * Math.Exp(-x / 2.0)) / (Math.Pow(2.0, dof / 2.0) * SpecialFunctions.Gamma(dof / 2.0)), n.Density(x));
@ -195,10 +247,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
[Values(0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity)] double x)
[TestCase(1.0, 0.0)]
[TestCase(1.0, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(1.0, 5.5)]
[TestCase(1.0, 110.1)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(2.0, 0.0)]
[TestCase(2.0, 0.1)]
[TestCase(2.0, 1.0)]
[TestCase(2.0, 5.5)]
[TestCase(2.0, 110.1)]
[TestCase(2.0, Double.PositiveInfinity)]
[TestCase(2.5, 0.0)]
[TestCase(2.5, 0.1)]
[TestCase(2.5, 1.0)]
[TestCase(2.5, 5.5)]
[TestCase(2.5, 110.1)]
[TestCase(2.5, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(Double.PositiveInfinity, 5.5)]
[TestCase(Double.PositiveInfinity, 110.1)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateDensityLn(double dof, double x)
{
var n = new ChiSquare(dof);
Assert.AreEqual((-x / 2.0) + (((dof / 2.0) - 1.0) * Math.Log(x)) - ((dof / 2.0) * Math.Log(2)) - SpecialFunctions.GammaLn(dof / 2.0), n.DensityLn(x));
@ -248,10 +321,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
[Values(0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity)] double x)
[TestCase(1.0, 0.0)]
[TestCase(1.0, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(1.0, 5.5)]
[TestCase(1.0, 110.1)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(2.0, 0.0)]
[TestCase(2.0, 0.1)]
[TestCase(2.0, 1.0)]
[TestCase(2.0, 5.5)]
[TestCase(2.0, 110.1)]
[TestCase(2.0, Double.PositiveInfinity)]
[TestCase(2.5, 0.0)]
[TestCase(2.5, 0.1)]
[TestCase(2.5, 1.0)]
[TestCase(2.5, 5.5)]
[TestCase(2.5, 110.1)]
[TestCase(2.5, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(Double.PositiveInfinity, 5.5)]
[TestCase(Double.PositiveInfinity, 110.1)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateCumulativeDistribution(double dof, double x)
{
var n = new ChiSquare(dof);
Assert.AreEqual(SpecialFunctions.GammaLowerIncomplete(dof / 2.0, x / 2.0) / SpecialFunctions.Gamma(dof / 2.0), n.CumulativeDistribution(x));

148
src/UnitTests/DistributionTests/Continuous/ChiTests.cs

@ -1,4 +1,4 @@
// <copyright file="ChiTests.cs" company="Math.NET">
// <copyright file="ChiTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -50,8 +50,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can create chi.
/// </summary>
/// <param name="dof">Degrees of freedom</param>
[Test]
public void CanCreateChi([Values(1.0, 3.0, Double.PositiveInfinity)] double dof)
[TestCase(1.0)]
[TestCase(3.0)]
[TestCase(Double.PositiveInfinity)]
public void CanCreateChi(double dof)
{
var n = new Chi(dof);
Assert.AreEqual(dof, n.DegreesOfFreedom);
@ -61,8 +63,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Chi create fails with bad parameters.
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
[Test]
public void ChiCreateFailsWithBadParameters([Values(0.0, -1.0, -100.0, Double.NegativeInfinity, Double.NaN)] double dof)
[TestCase(0.0)]
[TestCase(-1.0)]
[TestCase(-100.0)]
[TestCase(Double.NegativeInfinity)]
[TestCase(Double.NaN)]
public void ChiCreateFailsWithBadParameters(double dof)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Chi(dof));
}
@ -81,8 +87,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set degrees of freedom.
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
[Test]
public void CanSetDoF([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double dof)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetDoF(double dof)
{
new Chi(1.0)
{
@ -94,8 +103,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set Degrees of freedom fails with non-positive value.
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
[Test]
public void SetDofFailsWithNonPositiveDoF([Values(-1.0, -0.0, 0.0)] double dof)
[TestCase(-1.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
public void SetDofFailsWithNonPositiveDoF(double dof)
{
var n = new Chi(1.0);
Assert.Throws<ArgumentOutOfRangeException>(() => n.DegreesOfFreedom = dof);
@ -105,8 +116,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate mean.
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
[Test]
public void ValidateMean([Values(1.0, 2.0, 2.5, 5.0, Double.PositiveInfinity)] double dof)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(2.5)]
[TestCase(5.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMean(double dof)
{
var n = new Chi(dof);
Assert.AreEqual(Math.Sqrt(2) * (SpecialFunctions.Gamma((dof + 1.0) / 2.0) / SpecialFunctions.Gamma(dof / 2.0)), n.Mean);
@ -116,8 +131,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate variance.
/// </summary>
/// <param name="dof">Degrees of freedom</param>
[Test]
public void ValidateVariance([Values(1.0, 2.0, 2.5, 3.0, Double.PositiveInfinity)] double dof)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(2.5)]
[TestCase(3.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateVariance(double dof)
{
var n = new Chi(dof);
Assert.AreEqual(dof - (n.Mean * n.Mean), n.Variance);
@ -127,8 +146,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate standard deviation
/// </summary>
/// <param name="dof">Degrees of freedom</param>
[Test]
public void ValidateStdDev([Values(1.0, 2.0, 2.5, 3.0, Double.PositiveInfinity)] double dof)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(2.5)]
[TestCase(3.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateStdDev(double dof)
{
var n = new Chi(dof);
Assert.AreEqual(Math.Sqrt(n.Variance), n.StdDev);
@ -138,8 +161,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate mode.
/// </summary>
/// <param name="dof">Degrees of freedom</param>
[Test]
public void ValidateMode([Values(1.0, 2.0, 2.5, 3.0, Double.PositiveInfinity)] double dof)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(2.5)]
[TestCase(3.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMode(double dof)
{
var n = new Chi(dof);
if (dof >= 1)
@ -183,10 +210,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
[Values(0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity)] double x)
[TestCase(1.0, 0.0)]
[TestCase(1.0, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(1.0, 5.5)]
[TestCase(1.0, 110.1)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(2.0, 0.0)]
[TestCase(2.0, 0.1)]
[TestCase(2.0, 1.0)]
[TestCase(2.0, 5.5)]
[TestCase(2.0, 110.1)]
[TestCase(2.0, Double.PositiveInfinity)]
[TestCase(2.5, 0.0)]
[TestCase(2.5, 0.1)]
[TestCase(2.5, 1.0)]
[TestCase(2.5, 5.5)]
[TestCase(2.5, 110.1)]
[TestCase(2.5, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(Double.PositiveInfinity, 5.5)]
[TestCase(Double.PositiveInfinity, 110.1)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateDensity(double dof, double x)
{
var n = new Chi(dof);
Assert.AreEqual((Math.Pow(2.0, 1.0 - (dof / 2.0)) * Math.Pow(x, dof - 1.0) * Math.Exp(-x * (x / 2.0))) / SpecialFunctions.Gamma(dof / 2.0), n.Density(x));
@ -197,10 +245,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
[Values(0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity)] double x)
[TestCase(1.0, 0.0)]
[TestCase(1.0, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(1.0, 5.5)]
[TestCase(1.0, 110.1)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(2.0, 0.0)]
[TestCase(2.0, 0.1)]
[TestCase(2.0, 1.0)]
[TestCase(2.0, 5.5)]
[TestCase(2.0, 110.1)]
[TestCase(2.0, Double.PositiveInfinity)]
[TestCase(2.5, 0.0)]
[TestCase(2.5, 0.1)]
[TestCase(2.5, 1.0)]
[TestCase(2.5, 5.5)]
[TestCase(2.5, 110.1)]
[TestCase(2.5, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(Double.PositiveInfinity, 5.5)]
[TestCase(Double.PositiveInfinity, 110.1)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateDensityLn(double dof, double x)
{
var n = new Chi(dof);
Assert.AreEqual(((1.0 - (dof / 2.0)) * Math.Log(2.0)) + ((dof - 1.0) * Math.Log(x)) - (x * (x / 2.0)) - SpecialFunctions.GammaLn(dof / 2.0), n.DensityLn(x));
@ -232,10 +301,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
[Values(0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity, 0.0, 0.1, 1.0, 5.5, 110.1, Double.PositiveInfinity)] double x)
[TestCase(1.0, 0.0)]
[TestCase(1.0, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(1.0, 5.5)]
[TestCase(1.0, 110.1)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(2.0, 0.0)]
[TestCase(2.0, 0.1)]
[TestCase(2.0, 1.0)]
[TestCase(2.0, 5.5)]
[TestCase(2.0, 110.1)]
[TestCase(2.0, Double.PositiveInfinity)]
[TestCase(2.5, 0.0)]
[TestCase(2.5, 0.1)]
[TestCase(2.5, 1.0)]
[TestCase(2.5, 5.5)]
[TestCase(2.5, 110.1)]
[TestCase(2.5, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, 0.0)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(Double.PositiveInfinity, 5.5)]
[TestCase(Double.PositiveInfinity, 110.1)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateCumulativeDistribution(double dof, double x)
{
var n = new Chi(dof);
Assert.AreEqual(SpecialFunctions.GammaLowerIncomplete(dof / 2.0, x * x / 2.0) / SpecialFunctions.Gamma(dof / 2.0), n.CumulativeDistribution(x));

112
src/UnitTests/DistributionTests/Continuous/ContinuousUniformTests.cs

@ -62,8 +62,14 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound.</param>
[Test, Sequential]
public void CanCreateContinuousUniform([Values(0.0, 0.0, 0.0, 10.0, -5.0)] double lower, [Values(0.0, 0.1, 1.0, 10.0, 11.0, 100.0, Double.PositiveInfinity)] double upper)
[TestCase(0.0, 0.0)]
[TestCase(0.0, 0.1)]
[TestCase(0.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(-5.0, 11.0)]
[TestCase(-5.0, 100.0)]
[TestCase(Double.NegativeInfinity, Double.PositiveInfinity)]
public void CanCreateContinuousUniform(double lower, double upper)
{
var n = new ContinuousUniform(lower, upper);
Assert.AreEqual(lower, n.Lower);
@ -75,8 +81,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound.</param>
[Test, Sequential]
public void ContinuousUniformCreateFailsWithBadParameters([Values(Double.NaN, 1.0, Double.NaN, 1.0)] double lower, [Values(1.0, Double.NaN, Double.NaN, 0.0)] double upper)
[TestCase(Double.NaN, 1.0)]
[TestCase(1.0, Double.NaN)]
[TestCase(Double.NaN, Double.NaN)]
[TestCase(1.0, 0.0)]
public void ContinuousUniformCreateFailsWithBadParameters(double lower, double upper)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new ContinuousUniform(lower, upper));
}
@ -95,8 +104,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set lower bound.
/// </summary>
/// <param name="lower">Lower bound.</param>
[Test]
public void CanSetLower([Values(-10.0, -0.0, 0.0, 0.1, 1.0)] double lower)
[TestCase(-10.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
public void CanSetLower(double lower)
{
new ContinuousUniform
{
@ -118,8 +131,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set upper bound.
/// </summary>
/// <param name="upper">Upper bound.</param>
[Test]
public void CanSetUpper([Values(1.0, 2.0, 12.0)] double upper)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(12.0)]
public void CanSetUpper(double upper)
{
new ContinuousUniform
{
@ -142,8 +157,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound.</param>
[Test, Sequential]
public void ValidateEntropy([Values(-0.0, 0.0, 0.1, 1.0, 10.0, 0.0)] double lower, [Values(2.0, 2.0, 4.0, 10.0, 11.0, Double.PositiveInfinity)] double upper)
[TestCase(-0.0, 2.0)]
[TestCase(0.0, 2.0)]
[TestCase(0.1, 4.0)]
[TestCase(1.0, 10.0)]
[TestCase(10.0, 11.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateEntropy(double lower, double upper)
{
var n = new ContinuousUniform(lower, upper);
Assert.AreEqual(Math.Log(upper - lower), n.Entropy);
@ -154,8 +174,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound.</param>
[Test, Sequential]
public void ValidateSkewness([Values(-0.0, 0.0, 0.1, 1.0, 10.0, 0.0)] double lower, [Values(2.0, 2.0, 4.0, 10.0, 11.0, Double.PositiveInfinity)] double upper)
[TestCase(-0.0, 2.0)]
[TestCase(0.0, 2.0)]
[TestCase(0.1, 4.0)]
[TestCase(1.0, 10.0)]
[TestCase(10.0, 11.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateSkewness(double lower, double upper)
{
var n = new ContinuousUniform(lower, upper);
Assert.AreEqual(0.0, n.Skewness);
@ -166,8 +191,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound.</param>
[Test, Sequential]
public void ValidateMode([Values(-0.0, 0.0, 0.1, 1.0, 10.0, 0.0)] double lower, [Values(2.0, 2.0, 4.0, 10.0, 11.0, Double.PositiveInfinity)] double upper)
[TestCase(-0.0, 2.0)]
[TestCase(0.0, 2.0)]
[TestCase(0.1, 4.0)]
[TestCase(1.0, 10.0)]
[TestCase(10.0, 11.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateMode(double lower, double upper)
{
var n = new ContinuousUniform(lower, upper);
Assert.AreEqual((lower + upper) / 2.0, n.Mode);
@ -178,8 +208,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound.</param>
[Test, Sequential]
public void ValidateMedian([Values(-0.0, 0.0, 0.1, 1.0, 10.0, 0.0)] double lower, [Values(2.0, 2.0, 4.0, 10.0, 11.0, Double.PositiveInfinity)] double upper)
[TestCase(-0.0, 2.0)]
[TestCase(0.0, 2.0)]
[TestCase(0.1, 4.0)]
[TestCase(1.0, 10.0)]
[TestCase(10.0, 11.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateMedian(double lower, double upper)
{
var n = new ContinuousUniform(lower, upper);
Assert.AreEqual((lower + upper) / 2.0, n.Median);
@ -190,8 +225,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound.</param>
[Test, Sequential]
public void ValidateMinimum([Values(-0.0, 0.0, 0.1, 1.0, 10.0, 0.0)] double lower, [Values(2.0, 2.0, 4.0, 10.0, 11.0, Double.PositiveInfinity)] double upper)
[TestCase(-0.0, 2.0)]
[TestCase(0.0, 2.0)]
[TestCase(0.1, 4.0)]
[TestCase(1.0, 10.0)]
[TestCase(10.0, 11.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateMinimum(double lower, double upper)
{
var n = new ContinuousUniform(lower, upper);
Assert.AreEqual(lower, n.Minimum);
@ -202,8 +242,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound.</param>
[Test, Sequential]
public void ValidateMaximum([Values(-0.0, 0.0, 0.1, 1.0, 10.0, 0.0)] double lower, [Values(2.0, 2.0, 4.0, 10.0, 11.0, Double.PositiveInfinity)] double upper)
[TestCase(-0.0, 2.0)]
[TestCase(0.0, 2.0)]
[TestCase(0.1, 4.0)]
[TestCase(1.0, 10.0)]
[TestCase(10.0, 11.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateMaximum(double lower, double upper)
{
var n = new ContinuousUniform(lower, upper);
Assert.AreEqual(upper, n.Maximum);
@ -214,8 +259,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound.</param>
[Test, Sequential]
public void ValidateDensity([Values(0.0, 0.0, 0.0, 0.0, -5.0, 0.0)] double lower, [Values(0.0, 0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double upper)
[TestCase(0.0, 0.0)]
[TestCase(0.0, 0.1)]
[TestCase(0.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(-5.0, 100.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateDensity(double lower, double upper)
{
var n = new ContinuousUniform(lower, upper);
for (var i = 0; i < 11; i++)
@ -237,8 +287,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound.</param>
[Test, Sequential]
public void ValidateDensityLn([Values(0.0, 0.0, 0.0, 0.0, -5.0, 0.0)] double lower, [Values(0.0, 0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double upper)
[TestCase(0.0, 0.0)]
[TestCase(0.0, 0.1)]
[TestCase(0.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(-5.0, 100.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateDensityLn(double lower, double upper)
{
var n = new ContinuousUniform(lower, upper);
for (var i = 0; i < 11; i++)
@ -318,8 +373,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lower">Lower bound.</param>
/// <param name="upper">Upper bound.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution([Values(0.0, 0.0, 0.0, 0.0, -5.0, 0.0)] double lower, [Values(0.0, 0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double upper)
[TestCase(0.0, 0.0)]
[TestCase(0.0, 0.1)]
[TestCase(0.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(-5.0, 100.0)]
[TestCase(0.0, Double.PositiveInfinity)]
public void ValidateCumulativeDistribution(double lower, double upper)
{
var n = new ContinuousUniform(lower, upper);
for (var i = 0; i < 11; i++)

190
src/UnitTests/DistributionTests/Continuous/ErlangTests.cs

@ -1,4 +1,4 @@
// <copyright file="ErlangTests.cs" company="Math.NET">
// <copyright file="ErlangTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
[Test, Sequential]
public void CanCreateErlang([Values(0, 1, 1, 10, 10, 10)] int shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale)
[TestCase(0, 0.0)]
[TestCase(1, 0.1)]
[TestCase(1, 1.0)]
[TestCase(10, 10.0)]
[TestCase(10, 1.0)]
[TestCase(10, Double.PositiveInfinity)]
public void CanCreateErlang(int shape, double invScale)
{
var n = new Erlang(shape, invScale);
Assert.AreEqual(shape, n.Shape);
@ -64,8 +69,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
[Test, Sequential]
public void ErlangCreateFailsWithBadParameters([Values(1, 1, -1, -1, -1)] int shape, [Values(Double.NaN, -1.0, 1.0, -1.0, Double.NaN)] double invScale)
[TestCase(1, Double.NaN)]
[TestCase(1, -1.0)]
[TestCase(-1, 1.0)]
[TestCase(-1, -1.0)]
[TestCase(-1, Double.NaN)]
public void ErlangCreateFailsWithBadParameters(int shape, double invScale)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Erlang(shape, invScale));
}
@ -75,8 +84,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
[Test, Sequential]
public void CanCreateErlangWithShapeInvScale([Values(0, 1, 1, 10, 10, 10)] int shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale)
[TestCase(0, 0.0)]
[TestCase(1, 0.1)]
[TestCase(1, 1.0)]
[TestCase(10, 10.0)]
[TestCase(10, 1.0)]
[TestCase(10, Double.PositiveInfinity)]
public void CanCreateErlangWithShapeInvScale(int shape, double invScale)
{
var n = Erlang.WithShapeInvScale(shape, invScale);
Assert.AreEqual(shape, n.Shape);
@ -88,8 +102,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="shape">Shape value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void CanCreateErlangWithShapeScale([Values(0, 1, 1, 10, 10, 10)] int shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double scale)
[TestCase(0, 0.0)]
[TestCase(1, 0.1)]
[TestCase(1, 1.0)]
[TestCase(10, 10.0)]
[TestCase(10, 1.0)]
[TestCase(10, Double.PositiveInfinity)]
public void CanCreateErlangWithShapeScale(int shape, double scale)
{
var n = Erlang.WithShapeScale(shape, scale);
Assert.AreEqual(shape, n.Shape);
@ -110,8 +129,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set shape.
/// </summary>
/// <param name="shape">New shape value.</param>
[Test]
public void CanSetShape([Values(-0, 0, 1, 10)] int shape)
[TestCase(-0)]
[TestCase(0)]
[TestCase(1)]
[TestCase(10)]
public void CanSetShape(int shape)
{
new Erlang(1, 1.0)
{
@ -133,8 +155,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set scale
/// </summary>
/// <param name="scale">New scale value.</param>
[Test]
public void CanSetScale([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetScale(double scale)
{
new Erlang(1, 1.0)
{
@ -156,8 +183,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set inverse scale.
/// </summary>
/// <param name="invScale">Inverse scale value.</param>
[Test]
public void CanSetInvScale([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double invScale)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetInvScale(double invScale)
{
new Erlang(1, 1.0)
{
@ -181,8 +213,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="mean">Expected mean.</param>
[Test, Sequential]
public void ValidateMean([Values(0, 1, 1, 10, 10, 10)] int shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(Double.NaN, 10.0, 1.0, 1.0, 10.0, 10.0)] double mean)
[TestCase(0, 0.0, Double.NaN)]
[TestCase(1, 0.1, 10.0)]
[TestCase(1, 1.0, 1.0)]
[TestCase(10, 10.0, 1.0)]
[TestCase(10, 1.0, 10.0)]
[TestCase(10, Double.PositiveInfinity, 10.0)]
public void ValidateMean(int shape, double invScale, double mean)
{
var n = new Erlang(shape, invScale);
Assert.AreEqual(mean, n.Mean);
@ -194,8 +231,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="var">Expected variance.</param>
[Test, Sequential]
public void ValidateVariance([Values(0, 1, 1, 10, 10, 10)] int shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(Double.NaN, 100.0, 1.0, 0.1, 10.0, 0.0)] double var)
[TestCase(0, 0.0, Double.NaN)]
[TestCase(1, 0.1, 100.0)]
[TestCase(1, 1.0, 1.0)]
[TestCase(10, 10.0, 0.1)]
[TestCase(10, 1.0, 10.0)]
[TestCase(10, Double.PositiveInfinity, 0.0)]
public void ValidateVariance(int shape, double invScale, double var)
{
var n = new Erlang(shape, invScale);
AssertHelpers.AlmostEqual(var, n.Variance, 15);
@ -207,8 +249,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="sdev">Expected value.</param>
[Test, Sequential]
public void ValidateStdDev([Values(0, 1, 1, 10, 10, 10)] int shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(Double.NaN, 10.0, 1.0, 0.31622776601683794197697302588502426416723164097476643, 3.1622776601683793319988935444327185337195551393252168, 0.0)] double sdev)
[TestCase(0, 0.0, Double.NaN)]
[TestCase(1, 0.1, 10.0)]
[TestCase(1, 1.0, 1.0)]
[TestCase(10, 10.0, 0.31622776601683794197697302588502426416723164097476643)]
[TestCase(10, 1.0, 3.1622776601683793319988935444327185337195551393252168)]
[TestCase(10, Double.PositiveInfinity, 0.0)]
public void ValidateStdDev(int shape, double invScale, double sdev)
{
var n = new Erlang(shape, invScale);
AssertHelpers.AlmostEqual(sdev, n.StdDev, 15);
@ -220,8 +267,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="entropy">Expected value.</param>
[Test, Sequential]
public void ValidateEntropy([Values(0, 1, 1, 10, 10, 10)] int shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(Double.NaN, 3.3025850929940456285068402234265387271634735938763824, 1.0, 0.23346908548693395836262094490967812177376750477943892, 2.5360541784809796423806123995940423293748689934081866, 0.0)] double entropy)
[TestCase(0, 0.0, Double.NaN)]
[TestCase(1, 0.1, 3.3025850929940456285068402234265387271634735938763824)]
[TestCase(1, 1.0, 1.0)]
[TestCase(10, 10.0, 0.23346908548693395836262094490967812177376750477943892)]
[TestCase(10, 1.0, 2.5360541784809796423806123995940423293748689934081866)]
[TestCase(10, Double.PositiveInfinity, 0.0)]
public void ValidateEntropy(int shape, double invScale, double entropy)
{
var n = new Erlang(shape, invScale);
AssertHelpers.AlmostEqual(entropy, n.Entropy, 13);
@ -233,8 +285,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="skewness">Expected value.</param>
[Test, Sequential]
public void ValidateSkewness([Values(0, 1, 1, 10, 10, 10)] int shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(Double.NaN, 2.0, 2.0, 0.63245553203367586639977870888654370674391102786504337, 0.63245553203367586639977870888654370674391102786504337, 0.0)] double skewness)
[TestCase(0, 0.0, Double.NaN)]
[TestCase(1, 0.1, 2.0)]
[TestCase(1, 1.0, 2.0)]
[TestCase(10, 10.0, 0.63245553203367586639977870888654370674391102786504337)]
[TestCase(10, 1.0, 0.63245553203367586639977870888654370674391102786504337)]
[TestCase(10, Double.PositiveInfinity, 0.0)]
public void ValidateSkewness(int shape, double invScale, double skewness)
{
var n = new Erlang(shape, invScale);
AssertHelpers.AlmostEqual(skewness, n.Skewness, 15);
@ -246,8 +303,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="mode">Expected value.</param>
[Test, Sequential]
public void ValidateMode([Values(1, 1, 10, 10, 10)] int shape, [Values(0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(0.0, 0.0, 0.9, 9.0, 10.0)] double mode)
[TestCase(1, 0.1, 0.0)]
[TestCase(1, 1.0, 0.0)]
[TestCase(10, 10.0, 0.9)]
[TestCase(10, 1.0, 9.0)]
[TestCase(10, Double.PositiveInfinity, 10.0)]
public void ValidateMode(int shape, double invScale, double mode)
{
var n = new Erlang(shape, invScale);
Assert.AreEqual(mode, n.Mode);
@ -290,12 +351,25 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="invScale">Inverse scale value.</param>
/// <param name="x">Input X value.</param>
/// <param name="pdf">Expected value.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(0, 0, 0, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10)] int shape,
[Values(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double invScale,
[Values(0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0)] double x,
[Values(0.0, 0.0, 0.0, 0.10000000000000000555111512312578270211815834045410156, 0.090483741803595961836995913651194571475319347018875963, 0.036787944117144234201693506390001264039984687455876246, 1.0, 0.36787944117144232159552377016146086744581113103176804, 0.000045399929762484851535591515560550610237918088866564953, 0.0, 1.2511003572113329898476497894772544708420990097708588, 1.0251532120868705806216092933926141802686541811003037e-30, 0.0, 0.0000010137771196302974029859010421116095333052555418644397, 0.12511003572113329898476497894772544708420990097708601, 0.0, 0.0, Double.PositiveInfinity)] double pdf)
[TestCase(0, 0.0, 0.0, 0.0)]
[TestCase(0, 0.0, 1.0, 0.0)]
[TestCase(0, 0.0, 10.0, 0.0)]
[TestCase(1, 0.1, 0.0, 0.10000000000000000555111512312578270211815834045410156)]
[TestCase(1, 0.1, 1.0, 0.090483741803595961836995913651194571475319347018875963)]
[TestCase(1, 0.1, 10.0, 0.036787944117144234201693506390001264039984687455876246)]
[TestCase(1, 1.0, 0.0, 1.0)]
[TestCase(1, 1.0, 1.0, 0.36787944117144232159552377016146086744581113103176804)]
[TestCase(1, 1.0, 10.0, 0.000045399929762484851535591515560550610237918088866564953)]
[TestCase(10, 10.0, 0.0, 0.0)]
[TestCase(10, 10.0, 1.0, 1.2511003572113329898476497894772544708420990097708588)]
[TestCase(10, 10.0, 10.0, 1.0251532120868705806216092933926141802686541811003037e-30)]
[TestCase(10, 1.0, 0.0, 0.0)]
[TestCase(10, 1.0, 1.0, 0.0000010137771196302974029859010421116095333052555418644397)]
[TestCase(10, 1.0, 10.0, 0.12511003572113329898476497894772544708420990097708601)]
[TestCase(10, Double.PositiveInfinity, 0.0, 0.0)]
[TestCase(10, Double.PositiveInfinity, 1.0, 0.0)]
[TestCase(10, Double.PositiveInfinity, 10.0, Double.PositiveInfinity)]
public void ValidateDensity(int shape, double invScale, double x, double pdf)
{
var n = new Erlang(shape, invScale);
AssertHelpers.AlmostEqual(pdf, n.Density(x), 14);
@ -308,12 +382,25 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="invScale">Inverse scale value.</param>
/// <param name="x">Input X value.</param>
/// <param name="pdfln">Expected value.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(0, 0, 0, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10)] int shape,
[Values(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double invScale,
[Values(0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0)] double x,
[Values(Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, -2.3025850929940456285068402234265387271634735938763824, -2.402585092994045634057955346552321429281631934330484, -3.3025850929940456285068402234265387271634735938763824, 0.0, -1.0, -10.0, Double.NegativeInfinity, 0.22402344985898722897219667227693591172986563062456522, -69.052710713194601614865880235563786219860220971716511, Double.NegativeInfinity, -13.801827480081469611207717874566706164281149255663166, -2.0785616431350584550457947824074282958712358580042068, Double.NegativeInfinity, Double.NegativeInfinity, Double.PositiveInfinity)] double pdfln)
[TestCase(0, 0.0, 0.0, Double.NegativeInfinity)]
[TestCase(0, 0.0, 1.0, Double.NegativeInfinity)]
[TestCase(0, 0.0, 10.0, Double.NegativeInfinity)]
[TestCase(1, 0.1, 0.0, -2.3025850929940456285068402234265387271634735938763824)]
[TestCase(1, 0.1, 1.0, -2.402585092994045634057955346552321429281631934330484)]
[TestCase(1, 0.1, 10.0, -3.3025850929940456285068402234265387271634735938763824)]
[TestCase(1, 1.0, 0.0, 0.0)]
[TestCase(1, 1.0, 1.0, -1.0)]
[TestCase(1, 1.0, 10.0, -10.0)]
[TestCase(10, 10.0, 0.0, Double.NegativeInfinity)]
[TestCase(10, 10.0, 1.0, 0.22402344985898722897219667227693591172986563062456522)]
[TestCase(10, 10.0, 10.0, -69.052710713194601614865880235563786219860220971716511)]
[TestCase(10, 1.0, 0.0, Double.NegativeInfinity)]
[TestCase(10, 1.0, 1.0, -13.801827480081469611207717874566706164281149255663166)]
[TestCase(10, 1.0, 10.0, -2.0785616431350584550457947824074282958712358580042068)]
[TestCase(10, Double.PositiveInfinity, 0.0, Double.NegativeInfinity)]
[TestCase(10, Double.PositiveInfinity, 1.0, Double.NegativeInfinity)]
[TestCase(10, Double.PositiveInfinity, 10.0, Double.PositiveInfinity)]
public void ValidateDensityLn(int shape, double invScale, double x, double pdfln)
{
var n = new Erlang(shape, invScale);
AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
@ -347,12 +434,25 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="invScale">Inverse scale value.</param>
/// <param name="x">Input X value.</param>
/// <param name="cdf">Expected value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(0, 0, 0, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10)] int shape,
[Values(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double invScale,
[Values(0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0)] double x,
[Values(0.0, 0.0, 0.0, 0.0, 0.095162581964040431858607615783064404690935346242622848, 0.63212055882855767840447622983853913255418886896823196, 0.0, 0.63212055882855767840447622983853913255418886896823196, 0.99995460007023751514846440848443944938976208191113396, 0.0, 0.54207028552814779168583514294066541824736464003242184, 0.99999999999999999999999999999988746526039157266114706, 0.0, 0.00000011142547833872067735305068724025236288094949815466035, 0.54207028552814779168583514294066541824736464003242184, 0.0, 0.0, 1.0)] double cdf)
[TestCase(0, 0.0, 0.0, 0.0)]
[TestCase(0, 0.0, 1.0, 0.0)]
[TestCase(0, 0.0, 10.0, 0.0)]
[TestCase(1, 0.1, 0.0, 0.0)]
[TestCase(1, 0.1, 1.0, 0.095162581964040431858607615783064404690935346242622848)]
[TestCase(1, 0.1, 10.0, 0.63212055882855767840447622983853913255418886896823196)]
[TestCase(1, 1.0, 0.0, 0.0)]
[TestCase(1, 1.0, 1.0, 0.63212055882855767840447622983853913255418886896823196)]
[TestCase(1, 1.0, 10.0, 0.99995460007023751514846440848443944938976208191113396)]
[TestCase(10, 10.0, 0.0, 0.0)]
[TestCase(10, 10.0, 1.0, 0.54207028552814779168583514294066541824736464003242184)]
[TestCase(10, 10.0, 10.0, 0.99999999999999999999999999999988746526039157266114706)]
[TestCase(10, 1.0, 0.0, 0.0)]
[TestCase(10, 1.0, 1.0, 0.00000011142547833872067735305068724025236288094949815466035)]
[TestCase(10, 1.0, 10.0, 0.54207028552814779168583514294066541824736464003242184)]
[TestCase(10, Double.PositiveInfinity, 0.0, 0.0)]
[TestCase(10, Double.PositiveInfinity, 1.0, 0.0)]
[TestCase(10, Double.PositiveInfinity, 10.0, 1.0)]
public void ValidateCumulativeDistribution(int shape, double invScale, double x, double cdf)
{
var n = new Erlang(shape, invScale);
AssertHelpers.AlmostEqual(cdf, n.CumulativeDistribution(x), 14);

156
src/UnitTests/DistributionTests/Continuous/ExponentialTests.cs

@ -1,4 +1,4 @@
// <copyright file="ExponentialTests.cs" company="Math.NET">
// <copyright file="ExponentialTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -50,8 +50,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can create exponential.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void CanCreateExponential([Values(0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda)
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanCreateExponential(double lambda)
{
var n = new Exponential(lambda);
Assert.AreEqual(lambda, n.Lambda);
@ -61,8 +65,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Exponential create fails with bad parameter.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ExponentialCreateFailsWithBadParameters([Values(Double.NaN, -1.0, -10.0)] double lambda)
[TestCase(Double.NaN)]
[TestCase(-1.0)]
[TestCase(-10.0)]
public void ExponentialCreateFailsWithBadParameters(double lambda)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Exponential(lambda));
}
@ -81,8 +87,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set lambda.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void CanSetLambda([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetLambda(double lambda)
{
new Exponential(1.0)
{
@ -104,8 +115,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate mean.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ValidateMean([Values(0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda)
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMean(double lambda)
{
var n = new Exponential(lambda);
Assert.AreEqual(1.0 / lambda, n.Mean);
@ -115,8 +130,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate variance.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ValidateVariance([Values(0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda)
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateVariance(double lambda)
{
var n = new Exponential(lambda);
Assert.AreEqual(1.0 / (lambda * lambda), n.Variance);
@ -126,8 +145,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate standard deviation.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ValidateStdDev([Values(0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda)
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateStdDev(double lambda)
{
var n = new Exponential(lambda);
Assert.AreEqual(1.0 / lambda, n.StdDev);
@ -137,8 +160,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate entropy.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ValidateEntropy([Values(0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda)
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateEntropy(double lambda)
{
var n = new Exponential(lambda);
Assert.AreEqual(1.0 - Math.Log(lambda), n.Entropy);
@ -148,8 +175,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate skewness.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ValidateSkewness([Values(0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda)
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateSkewness(double lambda)
{
var n = new Exponential(lambda);
Assert.AreEqual(2.0, n.Skewness);
@ -159,8 +190,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate mode.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ValidateMode([Values(0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda)
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMode(double lambda)
{
var n = new Exponential(lambda);
Assert.AreEqual(0.0, n.Mode);
@ -170,8 +205,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate median.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ValidateMedian([Values(0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda)
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMedian(double lambda)
{
var n = new Exponential(lambda);
Assert.AreEqual(Math.Log(2.0) / lambda, n.Median);
@ -202,10 +241,27 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lambda">Lambda value.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda,
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double x)
[TestCase(0.0, 0.0)]
[TestCase(0.1, 0.0)]
[TestCase(1.0, 0.0)]
[TestCase(10.0, 0.0)]
[TestCase(Double.PositiveInfinity, 0.0)]
[TestCase(0.0, 0.1)]
[TestCase(0.1, 0.1)]
[TestCase(1.0, 0.1)]
[TestCase(10.0, 0.1)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(0.0, 1.0)]
[TestCase(0.1, 1.0)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 1.0)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(0.0, Double.PositiveInfinity)]
[TestCase(0.1, Double.PositiveInfinity)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(10.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateDensity(double lambda, double x)
{
var n = new Exponential(lambda);
if (x >= 0)
@ -223,10 +279,27 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lambda">Lambda value.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda,
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double x)
[TestCase(0.0, 0.0)]
[TestCase(0.1, 0.0)]
[TestCase(1.0, 0.0)]
[TestCase(10.0, 0.0)]
[TestCase(Double.PositiveInfinity, 0.0)]
[TestCase(0.0, 0.1)]
[TestCase(0.1, 0.1)]
[TestCase(1.0, 0.1)]
[TestCase(10.0, 0.1)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(0.0, 1.0)]
[TestCase(0.1, 1.0)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 1.0)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(0.0, Double.PositiveInfinity)]
[TestCase(0.1, Double.PositiveInfinity)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(10.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateDensityLn(double lambda, double x)
{
var n = new Exponential(lambda);
Assert.AreEqual(Math.Log(lambda) - (lambda * x), n.DensityLn(x));
@ -258,10 +331,27 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="lambda">Lambda value.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double lambda,
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double x)
[TestCase(0.0, 0.0)]
[TestCase(0.1, 0.0)]
[TestCase(1.0, 0.0)]
[TestCase(10.0, 0.0)]
[TestCase(Double.PositiveInfinity, 0.0)]
[TestCase(0.0, 0.1)]
[TestCase(0.1, 0.1)]
[TestCase(1.0, 0.1)]
[TestCase(10.0, 0.1)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(0.0, 1.0)]
[TestCase(0.1, 1.0)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 1.0)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(0.0, Double.PositiveInfinity)]
[TestCase(0.1, Double.PositiveInfinity)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(10.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateCumulativeDistribution(double lambda, double x)
{
var n = new Exponential(lambda);
if (x >= 0.0)

217
src/UnitTests/DistributionTests/Continuous/FisherSnedecorTests.cs

@ -1,4 +1,4 @@
// <copyright file="FisherSnedecorTests.cs" company="Math.NET">
// <copyright file="FisherSnedecorTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,10 +51,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="d1">Degrees of freedom 1</param>
/// <param name="d2">Degrees of freedom 2</param>
[Test]
public void CanCreateFisherSnedecor(
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double d1,
[Values(0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double d2)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 0.1)]
[TestCase(10.0, 0.1)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(0.1, 1.0)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 1.0)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(0.1, Double.PositiveInfinity)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(10.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void CanCreateFisherSnedecor(double d1, double d2)
{
var n = new FisherSnedecor(d1, d2);
Assert.AreEqual(d1, n.DegreeOfFreedom1);
@ -66,10 +75,23 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="d1">Degrees of freedom 1</param>
/// <param name="d2">Degrees of freedom 2</param>
[Test, Sequential]
public void FisherSnedecorCreateFailsWithBadParameters(
[Values(Double.NaN, 0.0, -1.0, -10.0, Double.NaN, 0.0, -1.0, -10.0, Double.NaN, 0.0, -1.0, -10.0, Double.NaN, 0.0, -1.0, -10.0)] double d1,
[Values(Double.NaN, Double.NaN, Double.NaN, Double.NaN, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -10.0, -10.0, -10.0, -10.0)] double d2)
[TestCase(Double.NaN, Double.NaN)]
[TestCase(0.0, Double.NaN)]
[TestCase(-1.0, Double.NaN)]
[TestCase(-10.0, Double.NaN)]
[TestCase(Double.NaN, 0.0)]
[TestCase(0.0, 0.0)]
[TestCase(-1.0, 0.0)]
[TestCase(-10.0, 0.0)]
[TestCase(Double.NaN, -1.0)]
[TestCase(0.0, -1.0)]
[TestCase(-1.0, -1.0)]
[TestCase(-10.0, -1.0)]
[TestCase(Double.NaN, -10.0)]
[TestCase(0.0, -10.0)]
[TestCase(-1.0, -10.0)]
[TestCase(-10.0, -10.0)]
public void FisherSnedecorCreateFailsWithBadParameters(double d1, double d2)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new FisherSnedecor(d1, d2));
}
@ -88,8 +110,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set degree of freedom 1.
/// </summary>
/// <param name="d1">Degrees of freedom 1</param>
[Test]
public void CanSetDegreeOfFreedom1([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double d1)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetDegreeOfFreedom1(double d1)
{
new FisherSnedecor(1.0, 2.0)
{
@ -111,8 +136,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set degree of freedom 2.
/// </summary>
/// <param name="d2">Degrees of freedom 2</param>
[Test]
public void CanSetDegreeOfFreedom2([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double d2)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetDegreeOfFreedom2(double d2)
{
new FisherSnedecor(1.0, 2.0)
{
@ -135,10 +163,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="d1">Degrees of freedom 1</param>
/// <param name="d2">Degrees of freedom 2</param>
[Test, Sequential]
public void ValidateMean(
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double d1,
[Values(0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double d2)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 0.1)]
[TestCase(10.0, 0.1)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(0.1, 1.0)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 1.0)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(0.1, Double.PositiveInfinity)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(10.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateMean(double d1, double d2)
{
var n = new FisherSnedecor(d1, d2);
if (d2 > 2)
@ -152,10 +189,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="d1">Degrees of freedom 1</param>
/// <param name="d2">Degrees of freedom 2</param>
[Test, Sequential]
public void ValidateVariance(
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double d1,
[Values(0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double d2)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 0.1)]
[TestCase(10.0, 0.1)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(0.1, 1.0)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 1.0)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(0.1, Double.PositiveInfinity)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(10.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateVariance(double d1, double d2)
{
var n = new FisherSnedecor(d1, d2);
if (d2 > 4)
@ -169,10 +215,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="d1">Degrees of freedom 1</param>
/// <param name="d2">Degrees of freedom 2</param>
[Test, Sequential]
public void ValidateStdDev(
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double d1,
[Values(0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double d2)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 0.1)]
[TestCase(10.0, 0.1)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(0.1, 1.0)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 1.0)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(0.1, Double.PositiveInfinity)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(10.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateStdDev(double d1, double d2)
{
var n = new FisherSnedecor(d1, d2);
if (d2 > 4)
@ -196,10 +251,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="d1">Degrees of freedom 1</param>
/// <param name="d2">Degrees of freedom 2</param>
[Test, Sequential]
public void ValidateSkewness(
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity, 0.1, 1.0, 10.0, Double.PositiveInfinity, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double d1,
[Values(0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double d2)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 0.1)]
[TestCase(10.0, 0.1)]
[TestCase(Double.PositiveInfinity, 0.1)]
[TestCase(0.1, 1.0)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 1.0)]
[TestCase(Double.PositiveInfinity, 1.0)]
[TestCase(0.1, Double.PositiveInfinity)]
[TestCase(1.0, Double.PositiveInfinity)]
[TestCase(10.0, Double.PositiveInfinity)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateSkewness(double d1, double d2)
{
var n = new FisherSnedecor(d1, d2);
if (d2 > 6)
@ -213,10 +277,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="d1">Degrees of freedom 1</param>
/// <param name="d2">Degrees of freedom 2</param>
[Test, Sequential]
public void ValidateMode(
[Values(0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0)] double d1,
[Values(0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, 100.0, 100.0, 100.0, 100.0)] double d2)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 0.1)]
[TestCase(10.0, 0.1)]
[TestCase(100.0, 0.1)]
[TestCase(0.1, 1.0)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 1.0)]
[TestCase(100.0, 1.0)]
[TestCase(0.1, 100.0)]
[TestCase(1.0, 100.0)]
[TestCase(10.0, 100.0)]
[TestCase(100.0, 100.0)]
public void ValidateMode(double d1, double d2)
{
var n = new FisherSnedecor(d1, d2);
if (d1 > 2)
@ -261,11 +334,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="d1">Degrees of freedom 1</param>
/// <param name="d2">Degrees of freedom 2</param>
/// <param name="x">Input X value</param>
[Test, Sequential]
public void ValidateDensity(
[Values(0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0)] double d1,
[Values(0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, 100.0, 100.0, 100.0, 100.0, 0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, 100.0, 100.0, 100.0, 100.0)] double d2,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0)] double x)
[TestCase(0.1, 0.1, 1.0)]
[TestCase(1.0, 0.1, 1.0)]
[TestCase(10.0, 0.1, 1.0)]
[TestCase(100.0, 0.1, 1.0)]
[TestCase(0.1, 1.0, 1.0)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(10.0, 1.0, 1.0)]
[TestCase(100.0, 1.0, 1.0)]
[TestCase(0.1, 100.0, 1.0)]
[TestCase(1.0, 100.0, 1.0)]
[TestCase(10.0, 100.0, 1.0)]
[TestCase(100.0, 100.0, 1.0)]
[TestCase(0.1, 0.1, 10.0)]
[TestCase(1.0, 0.1, 10.0)]
[TestCase(10.0, 0.1, 10.0)]
[TestCase(100.0, 0.1, 10.0)]
[TestCase(0.1, 1.0, 10.0)]
[TestCase(1.0, 1.0, 10.0)]
[TestCase(10.0, 1.0, 10.0)]
[TestCase(100.0, 1.0, 10.0)]
[TestCase(0.1, 100.0, 10.0)]
[TestCase(1.0, 100.0, 10.0)]
[TestCase(10.0, 100.0, 10.0)]
[TestCase(100.0, 100.0, 10.0)]
public void ValidateDensity(double d1, double d2, double x)
{
var n = new FisherSnedecor(d1, d2);
Assert.AreEqual(Math.Sqrt(Math.Pow(d1 * x, d1) * Math.Pow(d2, d2) / Math.Pow((d1 * x) + d2, d1 + d2)) / (x * SpecialFunctions.Beta(d1 / 2.0, d2 / 2.0)), n.Density(x));
@ -277,11 +370,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="d1">Degrees of freedom 1</param>
/// <param name="d2">Degrees of freedom 2</param>
/// <param name="x">Input X value</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0, 0.1, 1.0, 10.0, 100.0)] double d1,
[Values(0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, 100.0, 100.0, 100.0, 100.0, 0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, 100.0, 100.0, 100.0, 100.0)] double d2,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0)] double x)
[TestCase(0.1, 0.1, 1.0)]
[TestCase(1.0, 0.1, 1.0)]
[TestCase(10.0, 0.1, 1.0)]
[TestCase(100.0, 0.1, 1.0)]
[TestCase(0.1, 1.0, 1.0)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(10.0, 1.0, 1.0)]
[TestCase(100.0, 1.0, 1.0)]
[TestCase(0.1, 100.0, 1.0)]
[TestCase(1.0, 100.0, 1.0)]
[TestCase(10.0, 100.0, 1.0)]
[TestCase(100.0, 100.0, 1.0)]
[TestCase(0.1, 0.1, 10.0)]
[TestCase(1.0, 0.1, 10.0)]
[TestCase(10.0, 0.1, 10.0)]
[TestCase(100.0, 0.1, 10.0)]
[TestCase(0.1, 1.0, 10.0)]
[TestCase(1.0, 1.0, 10.0)]
[TestCase(10.0, 1.0, 10.0)]
[TestCase(100.0, 1.0, 10.0)]
[TestCase(0.1, 100.0, 10.0)]
[TestCase(1.0, 100.0, 10.0)]
[TestCase(10.0, 100.0, 10.0)]
[TestCase(100.0, 100.0, 10.0)]
public void ValidateDensityLn(double d1, double d2, double x)
{
var n = new FisherSnedecor(d1, d2);
Assert.AreEqual(Math.Log(n.Density(x)), n.DensityLn(x));
@ -314,11 +427,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="d1">Degrees of freedom 1</param>
/// <param name="d2">Degrees of freedom 2</param>
/// <param name="x">Input X value</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(0.1, 1.0, 10.0, 0.1, 1.0, 10.0, 0.1, 1.0, 10.0, 0.1, 1.0, 10.0)] double d1,
[Values(0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0)] double d2,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0)] double x)
[TestCase(0.1, 0.1, 1.0)]
[TestCase(1.0, 0.1, 1.0)]
[TestCase(10.0, 0.1, 1.0)]
[TestCase(0.1, 1.0, 1.0)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(10.0, 1.0, 1.0)]
[TestCase(0.1, 0.1, 10.0)]
[TestCase(1.0, 0.1, 10.0)]
[TestCase(10.0, 0.1, 10.0)]
[TestCase(0.1, 1.0, 10.0)]
[TestCase(1.0, 1.0, 10.0)]
[TestCase(10.0, 1.0, 10.0)]
public void ValidateCumulativeDistribution(double d1, double d2, double x)
{
var n = new FisherSnedecor(d1, d2);
Assert.AreEqual(SpecialFunctions.BetaRegularized(d1 / 2.0, d2 / 2.0, d1 * x / (d2 + (x * d1))), n.CumulativeDistribution(x));

193
src/UnitTests/DistributionTests/Continuous/GammaTests.cs

@ -1,4 +1,4 @@
// <copyright file="GammaTests.cs" company="Math.NET">
// <copyright file="GammaTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
[Test, Sequential]
public void CanCreateGamma([Values(0.0, 1.0, 1.0, 10.0, 10.0, 10.0)] double shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale)
[TestCase(0.0, 0.0)]
[TestCase(1.0, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(10.0, 1.0)]
[TestCase(10.0, Double.PositiveInfinity)]
public void CanCreateGamma(double shape, double invScale)
{
var n = new Gamma(shape, invScale);
Assert.AreEqual(shape, n.Shape);
@ -64,8 +69,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
[Test, Sequential]
public void GammaCreateFailsWithBadParameters([Values(1.0, 1.0, -1.0, -1.0, -1.0)] double shape, [Values(Double.NaN, -1.0, 1.0, -1.0, Double.NaN)] double invScale)
[TestCase(1.0, Double.NaN)]
[TestCase(1.0, -1.0)]
[TestCase(-1.0, 1.0)]
[TestCase(-1.0, -1.0)]
[TestCase(-1.0, Double.NaN)]
public void GammaCreateFailsWithBadParameters(double shape, double invScale)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Gamma(shape, invScale));
}
@ -75,8 +84,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
[Test, Sequential]
public void CanCreateGammaWithShapeInvScale([Values(0.0, 1.0, 1.0, 10.0, 10.0, 10.0)] double shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale)
[TestCase(0.0, 0.0)]
[TestCase(1.0, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(10.0, 1.0)]
[TestCase(10.0, Double.PositiveInfinity)]
public void CanCreateGammaWithShapeInvScale(double shape, double invScale)
{
var n = Gamma.WithShapeInvScale(shape, invScale);
Assert.AreEqual(shape, n.Shape);
@ -88,8 +102,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="shape">Shape value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void CanCreateGammaWithShapeScale([Values(0.0, 1.0, 1.0, 10.0, 10.0, 10.0)] double shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double scale)
[TestCase(0.0, 0.0)]
[TestCase(1.0, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(10.0, 1.0)]
[TestCase(10.0, Double.PositiveInfinity)]
public void CanCreateGammaWithShapeScale(double shape, double scale)
{
var n = Gamma.WithShapeScale(shape, scale);
Assert.AreEqual(shape, n.Shape);
@ -110,8 +129,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set shape.
/// </summary>
/// <param name="shape">Shape value.</param>
[Test]
public void CanSetShape([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetShape(double shape)
{
new Gamma(1.0, 1.0)
{
@ -133,8 +157,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set scale.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void CanSetScale([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetScale(double scale)
{
new Gamma(1.0, 1.0)
{
@ -156,8 +185,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set inverse scale.
/// </summary>
/// <param name="invScale">Inverse scale value.</param>
[Test]
public void CanSetInvScale([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double invScale)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetInvScale(double invScale)
{
new Gamma(1.0, 1.0)
{
@ -181,8 +215,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="mean">Expected value.</param>
[Test, Sequential]
public void ValidateMean([Values(0.0, 1.0, 1.0, 10.0, 10.0, 10.0)] double shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(Double.NaN, 10.0, 1.0, 1.0, 10.0, 10.0)] double mean)
[TestCase(0.0, 0.0, Double.NaN)]
[TestCase(1.0, 0.1, 10.0)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(10.0, 10.0, 1.0)]
[TestCase(10.0, 1.0, 10.0)]
[TestCase(10.0, Double.PositiveInfinity, 10.0)]
public void ValidateMean(double shape, double invScale, double mean)
{
var n = new Gamma(shape, invScale);
Assert.AreEqual(mean, n.Mean);
@ -194,8 +233,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="var">Expected value.</param>
[Test, Sequential]
public void ValidateVariance([Values(0.0, 1.0, 1.0, 10.0, 10.0, 10.0)] double shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(Double.NaN, 100.0, 1.0, 0.1, 10.0, 0.0)] double var)
[TestCase(0.0, 0.0, Double.NaN)]
[TestCase(1.0, 0.1, 100.0)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(10.0, 10.0, 0.1)]
[TestCase(10.0, 1.0, 10.0)]
[TestCase(10.0, Double.PositiveInfinity, 0.0)]
public void ValidateVariance(double shape, double invScale, double var)
{
var n = new Gamma(shape, invScale);
AssertHelpers.AlmostEqual(var, n.Variance, 15);
@ -207,8 +251,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="sdev">Expected value.</param>
[Test, Sequential]
public void ValidateStdDev([Values(0.0, 1.0, 1.0, 10.0, 10.0, 10.0)] double shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(Double.NaN, 10.0, 1.0, 0.31622776601683794197697302588502426416723164097476643, 3.1622776601683793319988935444327185337195551393252168, 0.0)] double sdev)
[TestCase(0.0, 0.0, Double.NaN)]
[TestCase(1.0, 0.1, 10.0)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(10.0, 10.0, 0.31622776601683794197697302588502426416723164097476643)]
[TestCase(10.0, 1.0, 3.1622776601683793319988935444327185337195551393252168)]
[TestCase(10.0, Double.PositiveInfinity, 0.0)]
public void ValidateStdDev(double shape, double invScale, double sdev)
{
var n = new Gamma(shape, invScale);
AssertHelpers.AlmostEqual(sdev, n.StdDev, 15);
@ -220,8 +269,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="entropy">Expected value.</param>
[Test, Sequential]
public void ValidateEntropy([Values(0.0, 1.0, 1.0, 10.0, 10.0, 10.0)] double shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(Double.NaN, 3.3025850929940456285068402234265387271634735938763824, 1.0, 0.23346908548693395836262094490967812177376750477943892, 2.5360541784809796423806123995940423293748689934081866, 0.0)] double entropy)
[TestCase(0.0, 0.0, Double.NaN)]
[TestCase(1.0, 0.1, 3.3025850929940456285068402234265387271634735938763824)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(10.0, 10.0, 0.23346908548693395836262094490967812177376750477943892)]
[TestCase(10.0, 1.0, 2.5360541784809796423806123995940423293748689934081866)]
[TestCase(10.0, Double.PositiveInfinity, 0.0)]
public void ValidateEntropy(double shape, double invScale, double entropy)
{
var n = new Gamma(shape, invScale);
AssertHelpers.AlmostEqual(entropy, n.Entropy, 13);
@ -233,8 +287,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="skewness">Expected value.</param>
[Test, Sequential]
public void ValidateSkewness([Values(0.0, 1.0, 1.0, 10.0, 10.0, 10.0)] double shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(Double.NaN, 2.0, 2.0, 0.63245553203367586639977870888654370674391102786504337, 0.63245553203367586639977870888654370674391102786504337, 0.0)] double skewness)
[TestCase(0.0, 0.0, Double.NaN)]
[TestCase(1.0, 0.1, 2.0)]
[TestCase(1.0, 1.0, 2.0)]
[TestCase(10.0, 10.0, 0.63245553203367586639977870888654370674391102786504337)]
[TestCase(10.0, 1.0, 0.63245553203367586639977870888654370674391102786504337)]
[TestCase(10.0, Double.PositiveInfinity, 0.0)]
public void ValidateSkewness(double shape, double invScale, double skewness)
{
var n = new Gamma(shape, invScale);
AssertHelpers.AlmostEqual(skewness, n.Skewness, 15);
@ -246,8 +305,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="invScale">Inverse scale value.</param>
/// <param name="mode">Expected value.</param>
[Test, Sequential]
public void ValidateMode([Values(0.0, 1.0, 1.0, 10.0, 10.0, 10.0)] double shape, [Values(0.0, 0.1, 1.0, 10.0, 1.0, Double.PositiveInfinity)] double invScale, [Values(Double.NaN, 0.0, 0.0, 0.9, 9.0, 10.0)] double mode)
[TestCase(0.0, 0.0, Double.NaN)]
[TestCase(1.0, 0.1, 0.0)]
[TestCase(1.0, 1.0, 0.0)]
[TestCase(10.0, 10.0, 0.9)]
[TestCase(10.0, 1.0, 9.0)]
[TestCase(10.0, Double.PositiveInfinity, 10.0)]
public void ValidateMode(double shape, double invScale, double mode)
{
var n = new Gamma(shape, invScale);
Assert.AreEqual(mode, n.Mode);
@ -290,12 +354,25 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="invScale">Inverse scale value.</param>
/// <param name="x">Input X value.</param>
/// <param name="pdf">Expected value.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(0, 0, 0, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10)] int shape,
[Values(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double invScale,
[Values(0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0)] double x,
[Values(0.0, 0.0, 0.0, 0.10000000000000000555111512312578270211815834045410156, 0.090483741803595961836995913651194571475319347018875963, 0.036787944117144234201693506390001264039984687455876246, 1.0, 0.36787944117144232159552377016146086744581113103176804, 0.000045399929762484851535591515560550610237918088866564953, 0.0, 1.2511003572113329898476497894772544708420990097708588, 1.0251532120868705806216092933926141802686541811003037e-30, 0.0, 0.0000010137771196302974029859010421116095333052555418644397, 0.12511003572113329898476497894772544708420990097708601, 0.0, 0.0, Double.PositiveInfinity)] double pdf)
[TestCase(0, 0.0, 0.0, 0.0)]
[TestCase(0, 0.0, 1.0, 0.0)]
[TestCase(0, 0.0, 10.0, 0.0)]
[TestCase(1, 0.1, 0.0, 0.10000000000000000555111512312578270211815834045410156)]
[TestCase(1, 0.1, 1.0, 0.090483741803595961836995913651194571475319347018875963)]
[TestCase(1, 0.1, 10.0, 0.036787944117144234201693506390001264039984687455876246)]
[TestCase(1, 1.0, 0.0, 1.0)]
[TestCase(1, 1.0, 1.0, 0.36787944117144232159552377016146086744581113103176804)]
[TestCase(1, 1.0, 10.0, 0.000045399929762484851535591515560550610237918088866564953)]
[TestCase(10, 10.0, 0.0, 0.0)]
[TestCase(10, 10.0, 1.0, 1.2511003572113329898476497894772544708420990097708588)]
[TestCase(10, 10.0, 10.0, 1.0251532120868705806216092933926141802686541811003037e-30)]
[TestCase(10, 1.0, 0.0, 0.0)]
[TestCase(10, 1.0, 1.0, 0.0000010137771196302974029859010421116095333052555418644397)]
[TestCase(10, 1.0, 10.0, 0.12511003572113329898476497894772544708420990097708601)]
[TestCase(10, Double.PositiveInfinity, 0.0, 0.0)]
[TestCase(10, Double.PositiveInfinity, 1.0, 0.0)]
[TestCase(10, Double.PositiveInfinity, 10.0, Double.PositiveInfinity)]
public void ValidateDensity(int shape, double invScale, double x, double pdf)
{
var n = new Gamma(shape, invScale);
AssertHelpers.AlmostEqual(pdf, n.Density(x), 14);
@ -308,12 +385,25 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="invScale">Inverse scale value.</param>
/// <param name="x">Input X value.</param>
/// <param name="pdfln">Expected value.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(0, 0, 0, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10)] int shape,
[Values(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double invScale,
[Values(0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0)] double x,
[Values(Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, -2.3025850929940456285068402234265387271634735938763824, -2.402585092994045634057955346552321429281631934330484, -3.3025850929940456285068402234265387271634735938763824, 0.0, -1.0, -10.0, Double.NegativeInfinity, 0.22402344985898722897219667227693591172986563062456522, -69.052710713194601614865880235563786219860220971716511, Double.NegativeInfinity, -13.801827480081469611207717874566706164281149255663166, -2.0785616431350584550457947824074282958712358580042068, Double.NegativeInfinity, Double.NegativeInfinity, Double.PositiveInfinity)] double pdfln)
[TestCase(0, 0.0, 0.0, Double.NegativeInfinity)]
[TestCase(0, 0.0, 1.0, Double.NegativeInfinity)]
[TestCase(0, 0.0, 10.0, Double.NegativeInfinity)]
[TestCase(1, 0.1, 0.0, -2.3025850929940456285068402234265387271634735938763824)]
[TestCase(1, 0.1, 1.0, -2.402585092994045634057955346552321429281631934330484)]
[TestCase(1, 0.1, 10.0, -3.3025850929940456285068402234265387271634735938763824)]
[TestCase(1, 1.0, 0.0, 0.0)]
[TestCase(1, 1.0, 1.0, -1.0)]
[TestCase(1, 1.0, 10.0, -10.0)]
[TestCase(10, 10.0, 0.0, Double.NegativeInfinity)]
[TestCase(10, 10.0, 1.0, 0.22402344985898722897219667227693591172986563062456522)]
[TestCase(10, 10.0, 10.0, -69.052710713194601614865880235563786219860220971716511)]
[TestCase(10, 1.0, 0.0, Double.NegativeInfinity)]
[TestCase(10, 1.0, 1.0, -13.801827480081469611207717874566706164281149255663166)]
[TestCase(10, 1.0, 10.0, -2.0785616431350584550457947824074282958712358580042068)]
[TestCase(10, Double.PositiveInfinity, 0.0, Double.NegativeInfinity)]
[TestCase(10, Double.PositiveInfinity, 1.0, Double.NegativeInfinity)]
[TestCase(10, Double.PositiveInfinity, 10.0, Double.PositiveInfinity)]
public void ValidateDensityLn(int shape, double invScale, double x, double pdfln)
{
var n = new Gamma(shape, invScale);
AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
@ -384,12 +474,25 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="invScale">Inverse scale value.</param>
/// <param name="x">Input X value.</param>
/// <param name="cdf">Expected value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(0, 0, 0, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10)] int shape,
[Values(0.0, 0.0, 0.0, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double invScale,
[Values(0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0)] double x,
[Values(0.0, 0.0, 0.0, 0.0, 0.095162581964040431858607615783064404690935346242622848, 0.63212055882855767840447622983853913255418886896823196, 0.0, 0.63212055882855767840447622983853913255418886896823196, 0.99995460007023751514846440848443944938976208191113396, 0.0, 0.54207028552814779168583514294066541824736464003242184, 0.99999999999999999999999999999988746526039157266114706, 0.0, 0.00000011142547833872067735305068724025236288094949815466035, 0.54207028552814779168583514294066541824736464003242184, 0.0, 0.0, 1.0)] double cdf)
[TestCase(0, 0.0, 0.0, 0.0)]
[TestCase(0, 0.0, 1.0, 0.0)]
[TestCase(0, 0.0, 10.0, 0.0)]
[TestCase(1, 0.1, 0.0, 0.0)]
[TestCase(1, 0.1, 1.0, 0.095162581964040431858607615783064404690935346242622848)]
[TestCase(1, 0.1, 10.0, 0.63212055882855767840447622983853913255418886896823196)]
[TestCase(1, 1.0, 0.0, 0.0)]
[TestCase(1, 1.0, 1.0, 0.63212055882855767840447622983853913255418886896823196)]
[TestCase(1, 1.0, 10.0, 0.99995460007023751514846440848443944938976208191113396)]
[TestCase(10, 10.0, 0.0, 0.0)]
[TestCase(10, 10.0, 1.0, 0.54207028552814779168583514294066541824736464003242184)]
[TestCase(10, 10.0, 10.0, 0.99999999999999999999999999999988746526039157266114706)]
[TestCase(10, 1.0, 0.0, 0.0)]
[TestCase(10, 1.0, 1.0, 0.00000011142547833872067735305068724025236288094949815466035)]
[TestCase(10, 1.0, 10.0, 0.54207028552814779168583514294066541824736464003242184)]
[TestCase(10, Double.PositiveInfinity, 0.0, 0.0)]
[TestCase(10, Double.PositiveInfinity, 1.0, 0.0)]
[TestCase(10, Double.PositiveInfinity, 10.0, 1.0)]
public void ValidateCumulativeDistribution(int shape, double invScale, double x, double cdf)
{
var n = new Gamma(shape, invScale);
AssertHelpers.AlmostEqual(cdf, n.CumulativeDistribution(x), 14);

116
src/UnitTests/DistributionTests/Continuous/InverseGammaTests.cs

@ -1,4 +1,4 @@
// <copyright file="InverseGammaTests.cs" company="Math.NET">
// <copyright file="InverseGammaTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="a">A parameter.</param>
/// <param name="b">B parameter.</param>
[Test, Combinatorial]
public void CanCreateInverseGamma([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void CanCreateInverseGamma(double a, double b)
{
var n = new InverseGamma(a, b);
Assert.AreEqual(a, n.Shape);
@ -64,8 +66,17 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="a">A parameter.</param>
/// <param name="b">B parameter.</param>
[Test, Sequential]
public void InverseGammaCreateFailsWithBadParameters([Values(0.0, -1.0, -100.0, Double.NegativeInfinity, Double.NaN, 1.0, 1.0, 1.0, 1.0, 1.0)] double a, [Values(1.0, 1.0, 1.0, 1.0, 1.0, 0.0, -1.0, -100.0, Double.NegativeInfinity, Double.NaN)] double b)
[TestCase(0.0, 1.0)]
[TestCase(-1.0, 1.0)]
[TestCase(-100.0, 1.0)]
[TestCase(Double.NegativeInfinity, 1.0)]
[TestCase(Double.NaN, 1.0)]
[TestCase(1.0, 0.0)]
[TestCase(1.0, -1.0)]
[TestCase(1.0, -100.0)]
[TestCase(1.0, Double.NegativeInfinity)]
[TestCase(1.0, Double.NaN)]
public void InverseGammaCreateFailsWithBadParameters(double a, double b)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new InverseGamma(a, b));
}
@ -84,8 +95,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set A.
/// </summary>
/// <param name="a">A parameter.</param>
[Test]
public void CanSetA([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double a)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetA(double a)
{
new InverseGamma(1.0, 1.0)
{
@ -97,8 +111,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set A fails with non-positive value.
/// </summary>
/// <param name="a">A parameter.</param>
[Test]
public void SetAFailsWithNonPositiveA([Values(-1.0, -0.0, 0.0)] double a)
[TestCase(-1.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
public void SetAFailsWithNonPositiveA(double a)
{
var n = new InverseGamma(1.0, 1.0);
Assert.Throws<ArgumentOutOfRangeException>(() => n.Shape = a);
@ -108,8 +124,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set B.
/// </summary>
/// <param name="b">B parameter.</param>
[Test]
public void CanSetB([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double b)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetB(double b)
{
new InverseGamma(1.0, 1.0)
{
@ -121,8 +140,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set B fails with non-positive value.
/// </summary>
/// <param name="b">B parameter.</param>
[Test]
public void SetBFailsWithNonPositiveB([Values(-1.0, -0.0, 0.0)] double b)
[TestCase(-1.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
public void SetBFailsWithNonPositiveB(double b)
{
var n = new InverseGamma(1.0, 1.0);
Assert.Throws<ArgumentOutOfRangeException>(() => n.Scale = b);
@ -133,8 +154,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="a">A parameter.</param>
/// <param name="b">B parameter.</param>
[Test, Combinatorial]
public void ValidateMean([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateMean(double a, double b)
{
var n = new InverseGamma(a, b);
if (a > 1)
@ -148,8 +171,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="a">A parameter.</param>
/// <param name="b">B parameter.</param>
[Test, Combinatorial]
public void ValidateVariance([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateVariance(double a, double b)
{
var n = new InverseGamma(a, b);
if (a > 2)
@ -163,8 +188,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="a">A parameter.</param>
/// <param name="b">B parameter.</param>
[Test, Combinatorial]
public void ValidateStdDev([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateStdDev(double a, double b)
{
var n = new InverseGamma(a, b);
if (a > 2)
@ -178,8 +205,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="a">A parameter.</param>
/// <param name="b">B parameter.</param>
[Test, Combinatorial]
public void ValidateMode([Values(0.1, 1.0, Double.PositiveInfinity)] double a, [Values(0.1, 1.0, Double.PositiveInfinity)] double b)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateMode(double a, double b)
{
var n = new InverseGamma(a, b);
Assert.AreEqual(b / (a + 1.0), n.Mode);
@ -221,11 +250,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="a">A parameter.</param>
/// <param name="b">B parameter.</param>
/// <param name="x">Input X valuer.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(0.1, 0.1, 0.1, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double a,
[Values(0.1, 1.0, Double.PositiveInfinity, 0.1, 1.0, Double.PositiveInfinity, 0.1, 1.0, Double.PositiveInfinity)] double b,
[Values(1.2, 2.0, 1.1, 1.5, 1.2, 1.5, 5.0, 2.5, 1.0)] double x)
[TestCase(0.1, 0.1, 1.2)]
[TestCase(0.1, 1.0, 2.0)]
[TestCase(0.1, Double.PositiveInfinity, 1.1)]
[TestCase(1.0, 0.1, 1.5)]
[TestCase(1.0, 1.0, 1.2)]
[TestCase(1.0, Double.PositiveInfinity, 1.5)]
[TestCase(Double.PositiveInfinity, 0.1, 5.0)]
[TestCase(Double.PositiveInfinity, 1.0, 2.5)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity, 1.0)]
public void ValidateDensity(double a, double b, double x)
{
var n = new InverseGamma(a, b);
if (x >= 0)
@ -244,11 +278,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="a">A parameter.</param>
/// <param name="b">B parameter.</param>
/// <param name="x">Input X valuer.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(0.1, 0.1, 0.1, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double a,
[Values(0.1, 1.0, Double.PositiveInfinity, 0.1, 1.0, Double.PositiveInfinity, 0.1, 1.0, Double.PositiveInfinity)] double b,
[Values(1.2, 2.0, 1.1, 1.5, 1.2, 1.5, 5.0, 2.5, 1.0)] double x)
[TestCase(0.1, 0.1, 1.2)]
[TestCase(0.1, 1.0, 2.0)]
[TestCase(0.1, Double.PositiveInfinity, 1.1)]
[TestCase(1.0, 0.1, 1.5)]
[TestCase(1.0, 1.0, 1.2)]
[TestCase(1.0, Double.PositiveInfinity, 1.5)]
[TestCase(Double.PositiveInfinity, 0.1, 5.0)]
[TestCase(Double.PositiveInfinity, 1.0, 2.5)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity, 1.0)]
public void ValidateDensityLn(double a, double b, double x)
{
var n = new InverseGamma(a, b);
Assert.AreEqual(Math.Log(n.Density(x)), n.DensityLn(x));
@ -281,11 +320,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="a">A parameter.</param>
/// <param name="b">B parameter.</param>
/// <param name="x">Input X valuer.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(0.1, 0.1, 0.1, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double a,
[Values(0.1, 1.0, Double.PositiveInfinity, 0.1, 1.0, Double.PositiveInfinity, 0.1, 1.0, Double.PositiveInfinity)] double b,
[Values(1.2, 2.0, 1.1, 1.5, 1.2, 1.5, 5.0, 2.5, 1.0)] double x)
[TestCase(0.1, 0.1, 1.2)]
[TestCase(0.1, 1.0, 2.0)]
[TestCase(0.1, Double.PositiveInfinity, 1.1)]
[TestCase(1.0, 0.1, 1.5)]
[TestCase(1.0, 1.0, 1.2)]
[TestCase(1.0, Double.PositiveInfinity, 1.5)]
[TestCase(Double.PositiveInfinity, 0.1, 5.0)]
[TestCase(Double.PositiveInfinity, 1.0, 2.5)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity, 1.0)]
public void ValidateCumulativeDistribution(double a, double b, double x)
{
var n = new InverseGamma(a, b);
Assert.AreEqual(SpecialFunctions.GammaUpperRegularized(a, b / x), n.CumulativeDistribution(x));

179
src/UnitTests/DistributionTests/Continuous/LaplaceTests.cs

@ -1,4 +1,4 @@
// <copyright file="LaplaceTests.cs" company="Math.NET">
// <copyright file="LaplaceTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -62,8 +62,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Combinatorial]
public void CanCreateLaplace([Values(Double.NegativeInfinity, -5.0 - 1.0, 0.0, 1.0, 5.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(Double.NegativeInfinity, 0.1)]
[TestCase(-5.0 - 1.0, 1.0)]
[TestCase(0.0, 5.0)]
[TestCase(1.0, 7.0)]
[TestCase(5.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void CanCreateLaplace(double location, double scale)
{
var n = new Laplace(location, scale);
Assert.AreEqual(location, n.Location);
@ -84,8 +89,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set location.
/// </summary>
/// <param name="location">Location value.</param>
[Test]
public void CanSetLocation([Values(Double.NegativeInfinity, -5.0 - 1.0, 0.0, 1.0, 5.0, Double.PositiveInfinity)] double location)
[TestCase(Double.NegativeInfinity)]
[TestCase(-5.0 - 1.0)]
[TestCase(0.0)]
[TestCase(1.0)]
[TestCase(5.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetLocation(double location)
{
new Laplace
{
@ -107,8 +117,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set scale.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void CanSetScale([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetScale(double scale)
{
new Laplace
{
@ -120,8 +133,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set scale fails with negative value.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void SetScaleFailsWithNegativeScale([Values(0.0, -1.0, -5.0, Double.NegativeInfinity, Double.NaN)] double scale)
[TestCase(0.0)]
[TestCase(-1.0)]
[TestCase(-5.0)]
[TestCase(Double.NegativeInfinity)]
[TestCase(Double.NaN)]
public void SetScaleFailsWithNegativeScale(double scale)
{
var n = new Laplace();
Assert.Throws<ArgumentOutOfRangeException>(() => n.Scale = scale);
@ -132,8 +149,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Combinatorial]
public void ValidateMean([Values(Double.NegativeInfinity, -5.0 - 1.0, 0.0, 1.0, 5.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(Double.NegativeInfinity, 0.1)]
[TestCase(-5.0 - 1.0, 1.0)]
[TestCase(0.0, 5.0)]
[TestCase(1.0, 7.0)]
[TestCase(5.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateMean(double location, double scale)
{
var n = new Laplace(location, scale);
Assert.AreEqual(location, n.Mean);
@ -144,8 +166,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Combinatorial]
public void ValidateVariance([Values(Double.NegativeInfinity, -5.0 - 1.0, 0.0, 1.0, 5.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(Double.NegativeInfinity, 0.1)]
[TestCase(-5.0 - 1.0, 1.0)]
[TestCase(0.0, 5.0)]
[TestCase(1.0, 7.0)]
[TestCase(5.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateVariance(double location, double scale)
{
var n = new Laplace(location, scale);
Assert.AreEqual(2.0 * scale * scale, n.Variance);
@ -156,8 +183,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Combinatorial]
public void ValidateStdDev([Values(Double.NegativeInfinity, -5.0 - 1.0, 0.0, 1.0, 5.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(Double.NegativeInfinity, 0.1)]
[TestCase(-5.0 - 1.0, 1.0)]
[TestCase(0.0, 5.0)]
[TestCase(1.0, 7.0)]
[TestCase(5.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateStdDev(double location, double scale)
{
var n = new Laplace(location, scale);
Assert.AreEqual(Math.Sqrt(2.0) * scale, n.StdDev);
@ -168,8 +200,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Combinatorial]
public void ValidateEntropy([Values(Double.NegativeInfinity, -5.0 - 1.0, 0.0, 1.0, 5.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(Double.NegativeInfinity, 0.1)]
[TestCase(-5.0 - 1.0, 1.0)]
[TestCase(0.0, 5.0)]
[TestCase(1.0, 7.0)]
[TestCase(5.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateEntropy(double location, double scale)
{
var n = new Laplace(location, scale);
Assert.AreEqual(Math.Log(2.0 * Constants.E * scale), n.Entropy);
@ -180,8 +217,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Combinatorial]
public void ValidateSkewness([Values(Double.NegativeInfinity, -5.0 - 1.0, 0.0, 1.0, 5.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(Double.NegativeInfinity, 0.1)]
[TestCase(-5.0 - 1.0, 1.0)]
[TestCase(0.0, 5.0)]
[TestCase(1.0, 7.0)]
[TestCase(5.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateSkewness(double location, double scale)
{
var n = new Laplace(location, scale);
Assert.AreEqual(0.0, n.Skewness);
@ -192,8 +234,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Combinatorial]
public void ValidateMode([Values(Double.NegativeInfinity, -5.0 - 1.0, 0.0, 1.0, 5.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(Double.NegativeInfinity, 0.1)]
[TestCase(-5.0 - 1.0, 1.0)]
[TestCase(0.0, 5.0)]
[TestCase(1.0, 7.0)]
[TestCase(5.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateMode(double location, double scale)
{
var n = new Laplace(location, scale);
Assert.AreEqual(location, n.Mode);
@ -204,8 +251,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Combinatorial]
public void ValidateMedian([Values(Double.NegativeInfinity, -5.0 - 1.0, 0.0, 1.0, 5.0, Double.PositiveInfinity)] double location, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(Double.NegativeInfinity, 0.1)]
[TestCase(-5.0 - 1.0, 1.0)]
[TestCase(0.0, 5.0)]
[TestCase(1.0, 7.0)]
[TestCase(5.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateMedian(double location, double scale)
{
var n = new Laplace(location, scale);
Assert.AreEqual(location, n.Median);
@ -237,11 +289,28 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(0.0, 1.0, -1.0, 5.0, -5.0, Double.PositiveInfinity, Double.NegativeInfinity, 0.0, 1.0, -1.0, 5.0, -5.0, Double.PositiveInfinity, Double.NegativeInfinity, 0.0, 1.0, -1.0, 5.0, -5.0, Double.PositiveInfinity, Double.NegativeInfinity)] double location,
[Values(0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double scale,
[Values(1.5, 2.8, -5.4, -4.9, 2.0, 5.5, -0.0, Double.PositiveInfinity, 5.0, -1.0, -1.0, 2.5, 2.0, 15.0, 89.3, -0.1, 0.1, -6.1, -10.0, 2.0, -5.1)] double x)
[TestCase(0.0, 0.1, 1.5)]
[TestCase(1.0, 0.1, 2.8)]
[TestCase(-1.0, 0.1, -5.4)]
[TestCase(5.0, 0.1, -4.9)]
[TestCase(-5.0, 0.1, 2.0)]
[TestCase(Double.PositiveInfinity, 0.1, 5.5)]
[TestCase(Double.NegativeInfinity, 0.1, -0.0)]
[TestCase(0.0, 1.0, Double.PositiveInfinity)]
[TestCase(1.0, 1.0, 5.0)]
[TestCase(-1.0, 1.0, -1.0)]
[TestCase(5.0, 1.0, -1.0)]
[TestCase(-5.0, 1.0, 2.5)]
[TestCase(Double.PositiveInfinity, 1.0, 2.0)]
[TestCase(Double.NegativeInfinity, 1.0, 15.0)]
[TestCase(0.0, Double.PositiveInfinity, 89.3)]
[TestCase(1.0, Double.PositiveInfinity, -0.1)]
[TestCase(-1.0, Double.PositiveInfinity, 0.1)]
[TestCase(5.0, Double.PositiveInfinity, -6.1)]
[TestCase(-5.0, Double.PositiveInfinity, -10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity, 2.0)]
[TestCase(Double.NegativeInfinity, Double.PositiveInfinity, -5.1)]
public void ValidateDensity(double location, double scale, double x)
{
var n = new Laplace(location, scale);
Assert.AreEqual(Math.Exp(-Math.Abs(x - location) / scale) / (2.0 * scale), n.Density(x));
@ -253,11 +322,28 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(0.0, 1.0, -1.0, 5.0, -5.0, Double.PositiveInfinity, Double.NegativeInfinity, 0.0, 1.0, -1.0, 5.0, -5.0, Double.PositiveInfinity, Double.NegativeInfinity, 0.0, 1.0, -1.0, 5.0, -5.0, Double.PositiveInfinity, Double.NegativeInfinity)] double location,
[Values(0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double scale,
[Values(1.5, 2.8, -5.4, -4.9, 2.0, 5.5, -0.0, Double.PositiveInfinity, 5.0, -1.0, -1.0, 2.5, 2.0, 15.0, 89.3, -0.1, 0.1, -6.1, -10.0, 2.0, -5.1)] double x)
[TestCase(0.0, 0.1, 1.5)]
[TestCase(1.0, 0.1, 2.8)]
[TestCase(-1.0, 0.1, -5.4)]
[TestCase(5.0, 0.1, -4.9)]
[TestCase(-5.0, 0.1, 2.0)]
[TestCase(Double.PositiveInfinity, 0.1, 5.5)]
[TestCase(Double.NegativeInfinity, 0.1, -0.0)]
[TestCase(0.0, 1.0, Double.PositiveInfinity)]
[TestCase(1.0, 1.0, 5.0)]
[TestCase(-1.0, 1.0, -1.0)]
[TestCase(5.0, 1.0, -1.0)]
[TestCase(-5.0, 1.0, 2.5)]
[TestCase(Double.PositiveInfinity, 1.0, 2.0)]
[TestCase(Double.NegativeInfinity, 1.0, 15.0)]
[TestCase(0.0, Double.PositiveInfinity, 89.3)]
[TestCase(1.0, Double.PositiveInfinity, -0.1)]
[TestCase(-1.0, Double.PositiveInfinity, 0.1)]
[TestCase(5.0, Double.PositiveInfinity, -6.1)]
[TestCase(-5.0, Double.PositiveInfinity, -10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity, 2.0)]
[TestCase(Double.NegativeInfinity, Double.PositiveInfinity, -5.1)]
public void ValidateDensityLn(double location, double scale, double x)
{
var n = new Laplace(location, scale);
Assert.AreEqual(-Math.Log(2.0 * scale) - (Math.Abs(x - location) / scale), n.DensityLn(x));
@ -290,11 +376,28 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(0.0, 1.0, -1.0, 5.0, -5.0, Double.PositiveInfinity, Double.NegativeInfinity, 0.0, 1.0, -1.0, 5.0, -5.0, Double.PositiveInfinity, Double.NegativeInfinity, 0.0, 1.0, -1.0, 5.0, -5.0, Double.PositiveInfinity, Double.NegativeInfinity)] double location,
[Values(0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double scale,
[Values(1.5, 2.8, -5.4, -4.9, 2.0, 5.5, -0.0, Double.PositiveInfinity, 5.0, -1.0, -1.0, 2.5, 2.0, 15.0, 89.3, -0.1, 0.1, -6.1, -10.0, 2.0, -5.1)] double x)
[TestCase(0.0, 0.1, 1.5)]
[TestCase(1.0, 0.1, 2.8)]
[TestCase(-1.0, 0.1, -5.4)]
[TestCase(5.0, 0.1, -4.9)]
[TestCase(-5.0, 0.1, 2.0)]
[TestCase(Double.PositiveInfinity, 0.1, 5.5)]
[TestCase(Double.NegativeInfinity, 0.1, -0.0)]
[TestCase(0.0, 1.0, Double.PositiveInfinity)]
[TestCase(1.0, 1.0, 5.0)]
[TestCase(-1.0, 1.0, -1.0)]
[TestCase(5.0, 1.0, -1.0)]
[TestCase(-5.0, 1.0, 2.5)]
[TestCase(Double.PositiveInfinity, 1.0, 2.0)]
[TestCase(Double.NegativeInfinity, 1.0, 15.0)]
[TestCase(0.0, Double.PositiveInfinity, 89.3)]
[TestCase(1.0, Double.PositiveInfinity, -0.1)]
[TestCase(-1.0, Double.PositiveInfinity, 0.1)]
[TestCase(5.0, Double.PositiveInfinity, -6.1)]
[TestCase(-5.0, Double.PositiveInfinity, -10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity, 2.0)]
[TestCase(Double.NegativeInfinity, Double.PositiveInfinity, -5.1)]
public void ValidateCumulativeDistribution(double location, double scale, double x)
{
var n = new Laplace(location, scale);
Assert.AreEqual(0.5 * (1.0 + (Math.Sign(x - location) * (1.0 - Math.Exp(-Math.Abs(x - location) / scale)))), n.CumulativeDistribution(x));

294
src/UnitTests/DistributionTests/Continuous/LogNormalTests.cs

@ -1,4 +1,4 @@
// <copyright file="LogNormalTests.cs" company="Math.NET">
// <copyright file="LogNormalTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="mu">Mu parameter.</param>
/// <param name="sigma">Sigma value.</param>
[Test, Combinatorial]
public void CanCreateLogNormal([Values(0.0, 10.0, -5.0)] double mu, [Values(0.0, 0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double sigma)
[TestCase(0.0, 0.0)]
[TestCase(10.0, 0.1)]
[TestCase(-5.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(10.0, 100.0)]
[TestCase(-5.0, Double.PositiveInfinity)]
public void CanCreateLogNormal(double mu, double sigma)
{
var n = new LogNormal(mu, sigma);
Assert.AreEqual(mu, n.Mu);
@ -64,8 +69,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="mu">Mu parameter.</param>
/// <param name="sigma">Sigma value.</param>
[Test, Sequential]
public void LogNormalCreateFailsWithBadParameters([Values(Double.NaN, 1.0, Double.NaN, 1.0)] double mu, [Values(1.0, Double.NaN, Double.NaN, -1.0)] double sigma)
[TestCase(Double.NaN, 1.0)]
[TestCase(1.0, Double.NaN)]
[TestCase(Double.NaN, Double.NaN)]
[TestCase(1.0, -1.0)]
public void LogNormalCreateFailsWithBadParameters(double mu, double sigma)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new LogNormal(mu, sigma));
}
@ -84,8 +92,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set sigma.
/// </summary>
/// <param name="sigma">Sigma value.</param>
[Test]
public void CanSetSigma([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double sigma)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetSigma(double sigma)
{
new LogNormal(1.0, 2.0)
{
@ -107,8 +120,15 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set mu.
/// </summary>
/// <param name="mu">Mu parameter.</param>
[Test]
public void CanSetMu([Values(Double.NegativeInfinity, -1.0, -0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double mu)
[TestCase(Double.NegativeInfinity)]
[TestCase(-1.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetMu(double mu)
{
new LogNormal(1.0, 2.0)
{
@ -122,11 +142,32 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="mu">Mu parameter.</param>
/// <param name="sigma">Sigma value.</param>
/// <param name="entropy">Expected value.</param>
[Test, Sequential]
public void ValidateEntropy(
[Values(-1.000000, -1.000000, -1.000000, -1.000000, -0.100000, -0.100000, -0.100000, -0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 2.500000, 5.500000, 5.500000, 5.500000, 5.500000, 3.0)] double mu,
[Values(0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.0)] double sigma,
[Values(-1.8836465597893728867265104870209210873020761202386, 0.82440364131283712375834285186996677643338789710028, 1.335229265078827806963856948173628711311498693546, 2.1236866254430979764250411929125703716076041932149, -0.9836465597893728922776256101467037894202344606927, 1.7244036413128371182072277287441840743152295566462, 2.2352292650788278014127418250478460091933403530919, 3.0236866254430979708739260697867876694894458527608, -0.7836465597893728811753953638951383851839177797845, 1.9244036413128371293094579749957494785515462375544, 2.4352292650788278125149720712994114134296570340001, 3.223686625443097981976156316038353073725762533669, 0.6163534402106271132734895129790789126979238797614, 3.3244036413128371237583428518699667764333878971003, 3.835229265078827806963856948173628711311498693546, 4.6236866254430979764250411929125703716076041932149, 1.6163534402106271132734895129790789126979238797614, 4.3244036413128371237583428518699667764333878971003, 4.835229265078827806963856948173628711311498693546, 5.6236866254430979764250411929125703716076041932149, 4.6163534402106271132734895129790789126979238797614, 7.3244036413128371237583428518699667764333878971003, 7.835229265078827806963856948173628711311498693546, 8.6236866254430979764250411929125703716076041932149, Double.NegativeInfinity)] double entropy)
[TestCase(-1.000000, 0.100000, -1.8836465597893728867265104870209210873020761202386)]
[TestCase(-1.000000, 1.500000, 0.82440364131283712375834285186996677643338789710028)]
[TestCase(-1.000000, 2.500000, 1.335229265078827806963856948173628711311498693546)]
[TestCase(-1.000000, 5.500000, 2.1236866254430979764250411929125703716076041932149)]
[TestCase(-0.100000, 0.100000, -0.9836465597893728922776256101467037894202344606927)]
[TestCase(-0.100000, 1.500000, 1.7244036413128371182072277287441840743152295566462)]
[TestCase(-0.100000, 2.500000, 2.2352292650788278014127418250478460091933403530919)]
[TestCase(-0.100000, 5.500000, 3.0236866254430979708739260697867876694894458527608)]
[TestCase(0.100000, 0.100000, -0.7836465597893728811753953638951383851839177797845)]
[TestCase(0.100000, 1.500000, 1.9244036413128371293094579749957494785515462375544)]
[TestCase(0.100000, 2.500000, 2.4352292650788278125149720712994114134296570340001)]
[TestCase(0.100000, 5.500000, 3.223686625443097981976156316038353073725762533669)]
[TestCase(1.500000, 0.100000, 0.6163534402106271132734895129790789126979238797614)]
[TestCase(1.500000, 1.500000, 3.3244036413128371237583428518699667764333878971003)]
[TestCase(1.500000, 2.500000, 3.835229265078827806963856948173628711311498693546)]
[TestCase(1.500000, 5.500000, 4.6236866254430979764250411929125703716076041932149)]
[TestCase(2.500000, 0.100000, 1.6163534402106271132734895129790789126979238797614)]
[TestCase(2.500000, 1.500000, 4.3244036413128371237583428518699667764333878971003)]
[TestCase(2.500000, 2.500000, 4.835229265078827806963856948173628711311498693546)]
[TestCase(2.500000, 5.500000, 5.6236866254430979764250411929125703716076041932149)]
[TestCase(5.500000, 0.100000, 4.6163534402106271132734895129790789126979238797614)]
[TestCase(5.500000, 1.500000, 7.3244036413128371237583428518699667764333878971003)]
[TestCase(5.500000, 2.500000, 7.835229265078827806963856948173628711311498693546)]
[TestCase(5.500000, 5.500000, 8.6236866254430979764250411929125703716076041932149)]
[TestCase(3.0, 0.0, Double.NegativeInfinity)]
public void ValidateEntropy(double mu, double sigma, double entropy)
{
var n = new LogNormal(mu, sigma);
AssertHelpers.AlmostEqual(entropy, n.Entropy, 14);
@ -138,11 +179,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="mu">Mu parameter.</param>
/// <param name="sigma">Sigma value.</param>
/// <param name="skewness">Expected value.</param>
[Test, Sequential]
public void ValidateSkewness(
[Values(-1.000000, -1.000000, -1.000000, -1.000000, -0.100000, -0.100000, -0.100000, -0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 2.500000, 5.500000, 5.500000, 5.500000, 5.500000)] double mu,
[Values(0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000)] double sigma,
[Values(0.30175909933883402945387113824982918009810212213629, 33.46804679732172529147579024311650645764144530123, 11824.007933610287521341659465200553739278936344799, 50829064464591483629.132631635472412625371367420496, 0.30175909933883402945387113824982918009810212213629, 33.46804679732172529147579024311650645764144530123, 11824.007933610287521341659465200553739278936344799, 50829064464591483629.132631635472412625371367420496, 0.30175909933883402945387113824982918009810212213629, 33.46804679732172529147579024311650645764144530123, 11824.007933610287521341659465200553739278936344799, 50829064464591483629.132631635472412625371367420496, 0.30175909933883402945387113824982918009810212213629, 33.46804679732172529147579024311650645764144530123, 11824.007933610287521341659465200553739278936344799, 50829064464591483629.132631635472412625371367420496, 0.30175909933883402945387113824982918009810212213629, 33.46804679732172529147579024311650645764144530123, 11824.007933610287521341659465200553739278936344799, 50829064464591483629.132631635472412625371367420496, 0.30175909933883402945387113824982918009810212213629, 33.46804679732172529147579024311650645764144530123, 11824.007933610287521341659465200553739278936344799, 50829064464591483629.132631635472412625371367420496)] double skewness)
[TestCase(-1.000000, 0.100000, 0.30175909933883402945387113824982918009810212213629)]
[TestCase(-1.000000, 1.500000, 33.46804679732172529147579024311650645764144530123)]
[TestCase(-1.000000, 2.500000, 11824.007933610287521341659465200553739278936344799)]
[TestCase(-1.000000, 5.500000, 50829064464591483629.132631635472412625371367420496)]
[TestCase(-0.100000, 0.100000, 0.30175909933883402945387113824982918009810212213629)]
[TestCase(-0.100000, 1.500000, 33.46804679732172529147579024311650645764144530123)]
[TestCase(-0.100000, 2.500000, 11824.007933610287521341659465200553739278936344799)]
[TestCase(-0.100000, 5.500000, 50829064464591483629.132631635472412625371367420496)]
[TestCase(0.100000, 0.100000, 0.30175909933883402945387113824982918009810212213629)]
[TestCase(0.100000, 1.500000, 33.46804679732172529147579024311650645764144530123)]
[TestCase(0.100000, 2.500000, 11824.007933610287521341659465200553739278936344799)]
[TestCase(0.100000, 5.500000, 50829064464591483629.132631635472412625371367420496)]
[TestCase(1.500000, 0.100000, 0.30175909933883402945387113824982918009810212213629)]
[TestCase(1.500000, 1.500000, 33.46804679732172529147579024311650645764144530123)]
[TestCase(1.500000, 2.500000, 11824.007933610287521341659465200553739278936344799)]
[TestCase(1.500000, 5.500000, 50829064464591483629.132631635472412625371367420496)]
[TestCase(2.500000, 0.100000, 0.30175909933883402945387113824982918009810212213629)]
[TestCase(2.500000, 1.500000, 33.46804679732172529147579024311650645764144530123)]
[TestCase(2.500000, 2.500000, 11824.007933610287521341659465200553739278936344799)]
[TestCase(2.500000, 5.500000, 50829064464591483629.132631635472412625371367420496)]
[TestCase(5.500000, 0.100000, 0.30175909933883402945387113824982918009810212213629)]
[TestCase(5.500000, 1.500000, 33.46804679732172529147579024311650645764144530123)]
[TestCase(5.500000, 2.500000, 11824.007933610287521341659465200553739278936344799)]
[TestCase(5.500000, 5.500000, 50829064464591483629.132631635472412625371367420496)]
public void ValidateSkewness(double mu, double sigma, double skewness)
{
var n = new LogNormal(mu, sigma);
AssertHelpers.AlmostEqual(skewness, n.Skewness, 14);
@ -154,11 +215,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="mu">Mu parameter.</param>
/// <param name="sigma">Sigma value.</param>
/// <param name="mode">Expected value.</param>
[Test, Sequential]
public void ValidateMode(
[Values(-1.000000, -1.000000, -1.000000, -1.000000, -0.100000, -0.100000, -0.100000, -0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 2.500000, 5.500000, 5.500000, 5.500000, 5.500000)] double mu,
[Values(0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000)] double sigma,
[Values(0.36421897957152331652213191863106773137983085909534, 0.03877420783172200988689983526759614326014406193602, 0.0007101743888425490635846003705775444086763023873619, 0.000000000000026810038677818032221548731163905979029274677187036, 0.89583413529652823774737070060865897390995185639633, 0.095369162215549610417813418326627245539514227574881, 0.0017467471362611196181003627521060283221112106850165, 0.00000000000006594205454219929159167575814655534255162059017114, 1.0941742837052103542285651753780976842292770841345, 0.11648415777349696821514223131929465848700730137808, 0.0021334817700377079925027678518795817076296484352472, 0.000000000000080541807296590798973741710866097756565304960216803, 4.4370955190036645692996309927420381428715912422597, 0.47236655274101470713804655094326791297020357913648, 0.008651695203120634177071503957250390848166331197708, 0.00000000000032661313427874471360158184468030186601222739665225, 12.061276120444720299113038763305617245808510584994, 1.2840254166877414840734205680624364583362808652815, 0.023517745856009108236151185100432939470067655273072, 0.00000000000088782654784596584473099190326928541185172970391855, 242.2572068579541371904816252345031593584721473492, 25.790339917193062089080107669377221876655268848954, 0.47236655274101470713804655094326791297020357913648, 0.000000000017832472908146389493511850431527026413424899198327)] double mode)
[TestCase(-1.000000, 0.100000, 0.36421897957152331652213191863106773137983085909534)]
[TestCase(-1.000000, 1.500000, 0.03877420783172200988689983526759614326014406193602)]
[TestCase(-1.000000, 2.500000, 0.0007101743888425490635846003705775444086763023873619)]
[TestCase(-1.000000, 5.500000, 0.000000000000026810038677818032221548731163905979029274677187036)]
[TestCase(-0.100000, 0.100000, 0.89583413529652823774737070060865897390995185639633)]
[TestCase(-0.100000, 1.500000, 0.095369162215549610417813418326627245539514227574881)]
[TestCase(-0.100000, 2.500000, 0.0017467471362611196181003627521060283221112106850165)]
[TestCase(-0.100000, 5.500000, 0.00000000000006594205454219929159167575814655534255162059017114)]
[TestCase(0.100000, 0.100000, 1.0941742837052103542285651753780976842292770841345)]
[TestCase(0.100000, 1.500000, 0.11648415777349696821514223131929465848700730137808)]
[TestCase(0.100000, 2.500000, 0.0021334817700377079925027678518795817076296484352472)]
[TestCase(0.100000, 5.500000, 0.000000000000080541807296590798973741710866097756565304960216803)]
[TestCase(1.500000, 0.100000, 4.4370955190036645692996309927420381428715912422597)]
[TestCase(1.500000, 1.500000, 0.47236655274101470713804655094326791297020357913648)]
[TestCase(1.500000, 2.500000, 0.008651695203120634177071503957250390848166331197708)]
[TestCase(1.500000, 5.500000, 0.00000000000032661313427874471360158184468030186601222739665225)]
[TestCase(2.500000, 0.100000, 12.061276120444720299113038763305617245808510584994)]
[TestCase(2.500000, 1.500000, 1.2840254166877414840734205680624364583362808652815)]
[TestCase(2.500000, 2.500000, 0.023517745856009108236151185100432939470067655273072)]
[TestCase(2.500000, 5.500000, 0.00000000000088782654784596584473099190326928541185172970391855)]
[TestCase(5.500000, 0.100000, 242.2572068579541371904816252345031593584721473492)]
[TestCase(5.500000, 1.500000, 25.790339917193062089080107669377221876655268848954)]
[TestCase(5.500000, 2.500000, 0.47236655274101470713804655094326791297020357913648)]
[TestCase(5.500000, 5.500000, 0.000000000017832472908146389493511850431527026413424899198327)]
public void ValidateMode(double mu, double sigma, double mode)
{
var n = new LogNormal(mu, sigma);
Assert.AreEqual(mode, n.Mode);
@ -170,11 +251,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="mu">Mu parameter.</param>
/// <param name="sigma">Sigma value.</param>
/// <param name="median">Expected value.</param>
[Test, Sequential]
public void ValidateMedian(
[Values(-1.000000, -1.000000, -1.000000, -1.000000, -0.100000, -0.100000, -0.100000, -0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 2.500000, 5.500000, 5.500000, 5.500000, 5.500000)] double mu,
[Values(0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000)] double sigma,
[Values(0.36787944117144232159552377016146086744581113103177, 0.36787944117144232159552377016146086744581113103177, 0.36787944117144232159552377016146086744581113103177, 0.36787944117144232159552377016146086744581113103177, 0.90483741803595956814139238421693559530906465375738, 0.90483741803595956814139238421693559530906465375738, 0.90483741803595956814139238421693559530906465375738, 0.90483741803595956814139238421693559530906465375738, 1.1051709180756476309466388234587796577416634163742, 1.1051709180756476309466388234587796577416634163742, 1.1051709180756476309466388234587796577416634163742, 1.1051709180756476309466388234587796577416634163742, 4.4816890703380648226020554601192758190057498683697, 4.4816890703380648226020554601192758190057498683697, 4.4816890703380648226020554601192758190057498683697, 4.4816890703380648226020554601192758190057498683697, 12.182493960703473438070175951167966183182767790063, 12.182493960703473438070175951167966183182767790063, 12.182493960703473438070175951167966183182767790063, 12.182493960703473438070175951167966183182767790063, 244.6919322642203879151889495118393501842287101075, 244.6919322642203879151889495118393501842287101075, 244.6919322642203879151889495118393501842287101075, 244.6919322642203879151889495118393501842287101075)] double median)
[TestCase(-1.000000, 0.100000, 0.36787944117144232159552377016146086744581113103177)]
[TestCase(-1.000000, 1.500000, 0.36787944117144232159552377016146086744581113103177)]
[TestCase(-1.000000, 2.500000, 0.36787944117144232159552377016146086744581113103177)]
[TestCase(-1.000000, 5.500000, 0.36787944117144232159552377016146086744581113103177)]
[TestCase(-0.100000, 0.100000, 0.90483741803595956814139238421693559530906465375738)]
[TestCase(-0.100000, 1.500000, 0.90483741803595956814139238421693559530906465375738)]
[TestCase(-0.100000, 2.500000, 0.90483741803595956814139238421693559530906465375738)]
[TestCase(-0.100000, 5.500000, 0.90483741803595956814139238421693559530906465375738)]
[TestCase(0.100000, 0.100000, 1.1051709180756476309466388234587796577416634163742)]
[TestCase(0.100000, 1.500000, 1.1051709180756476309466388234587796577416634163742)]
[TestCase(0.100000, 2.500000, 1.1051709180756476309466388234587796577416634163742)]
[TestCase(0.100000, 5.500000, 1.1051709180756476309466388234587796577416634163742)]
[TestCase(1.500000, 0.100000, 4.4816890703380648226020554601192758190057498683697)]
[TestCase(1.500000, 1.500000, 4.4816890703380648226020554601192758190057498683697)]
[TestCase(1.500000, 2.500000, 4.4816890703380648226020554601192758190057498683697)]
[TestCase(1.500000, 5.500000, 4.4816890703380648226020554601192758190057498683697)]
[TestCase(2.500000, 0.100000, 12.182493960703473438070175951167966183182767790063)]
[TestCase(2.500000, 1.500000, 12.182493960703473438070175951167966183182767790063)]
[TestCase(2.500000, 2.500000, 12.182493960703473438070175951167966183182767790063)]
[TestCase(2.500000, 5.500000, 12.182493960703473438070175951167966183182767790063)]
[TestCase(5.500000, 0.100000, 244.6919322642203879151889495118393501842287101075)]
[TestCase(5.500000, 1.500000, 244.6919322642203879151889495118393501842287101075)]
[TestCase(5.500000, 2.500000, 244.6919322642203879151889495118393501842287101075)]
[TestCase(5.500000, 5.500000, 244.6919322642203879151889495118393501842287101075)]
public void ValidateMedian(double mu, double sigma, double median)
{
var n = new LogNormal(mu, sigma);
Assert.AreEqual(median, n.Median);
@ -186,11 +287,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="mu">Mu parameter.</param>
/// <param name="sigma">Sigma value.</param>
/// <param name="mean">Expected value.</param>
[Test, Sequential]
public void ValidateMean(
[Values(-1.000000, -1.000000, -1.000000, -1.000000, -0.100000, -0.100000, -0.100000, -0.100000, 0.100000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 2.500000, 5.500000, 5.500000, 5.500000, 5.500000)] double mu,
[Values(0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000, 0.100000, 1.500000, 2.500000, 5.500000)] double sigma,
[Values(0.36972344454405898424295931933535060663729727450496, 1.1331484530668263168290072278117938725655031317452, 8.3728974881272646632047051583699874196015291437918, 1362729.1842528548177103892815156762190272224157908, 0.90937293446823141948366366799116134283184493055232, 2.7870954605658505209699655454000403395863724001622, 20.594004711196027346218102453235151379866942184579, 3351772.9412526949983798753257651403306685815830315, 1.1107106103557052433570611860384876269319432656698, 3.4041660827908192886708290528609320712960422205023, 25.153574155818364061848601838108180348672588964125, 4093864.7151726636524297378613262447736728507467499, 4.5041536302884836520306376113128094189800629942172, 13.804574186067094919261248628970575865946258844868, 102.00277308269968445339478193484494686013688925329, 16601440.057234774713918640507932346750889433699096, 12.243558965801025772304627735965552181680541950402, 37.524723159600998914070697772298569304087527691818, 277.27228452313398040814702091277144916631260200421, 45127392.833833379992911980630933945681066040228608, 245.91845567882191847293631456824227914641401674654, 753.70421255456126566058070133948176772966773355511, 5569.16270856600407442234466894967473356247174813, 906407915.01115491334464289369168840924937330105415)] double mean)
[TestCase(-1.000000, 0.100000, 0.36972344454405898424295931933535060663729727450496)]
[TestCase(-1.000000, 1.500000, 1.1331484530668263168290072278117938725655031317452)]
[TestCase(-1.000000, 2.500000, 8.3728974881272646632047051583699874196015291437918)]
[TestCase(-1.000000, 5.500000, 1362729.1842528548177103892815156762190272224157908)]
[TestCase(-0.100000, 0.100000, 0.90937293446823141948366366799116134283184493055232)]
[TestCase(-0.100000, 1.500000, 2.7870954605658505209699655454000403395863724001622)]
[TestCase(-0.100000, 2.500000, 20.594004711196027346218102453235151379866942184579)]
[TestCase(-0.100000, 5.500000, 3351772.9412526949983798753257651403306685815830315)]
[TestCase(0.100000, 0.100000, 1.1107106103557052433570611860384876269319432656698)]
[TestCase(0.100000, 1.500000, 3.4041660827908192886708290528609320712960422205023)]
[TestCase(0.100000, 2.500000, 25.153574155818364061848601838108180348672588964125)]
[TestCase(0.100000, 5.500000, 4093864.7151726636524297378613262447736728507467499)]
[TestCase(1.500000, 0.100000, 4.5041536302884836520306376113128094189800629942172)]
[TestCase(1.500000, 1.500000, 13.804574186067094919261248628970575865946258844868)]
[TestCase(1.500000, 2.500000, 102.00277308269968445339478193484494686013688925329)]
[TestCase(1.500000, 5.500000, 16601440.057234774713918640507932346750889433699096)]
[TestCase(2.500000, 0.100000, 12.243558965801025772304627735965552181680541950402)]
[TestCase(2.500000, 1.500000, 37.524723159600998914070697772298569304087527691818)]
[TestCase(2.500000, 2.500000, 277.27228452313398040814702091277144916631260200421)]
[TestCase(2.500000, 5.500000, 45127392.833833379992911980630933945681066040228608)]
[TestCase(5.500000, 0.100000, 245.91845567882191847293631456824227914641401674654)]
[TestCase(5.500000, 1.500000, 753.70421255456126566058070133948176772966773355511)]
[TestCase(5.500000, 2.500000, 5569.16270856600407442234466894967473356247174813)]
[TestCase(5.500000, 5.500000, 906407915.01115491334464289369168840924937330105415)]
public void ValidateMean(double mu, double sigma, double mean)
{
var n = new LogNormal(mu, sigma);
AssertHelpers.AlmostEqual(mean, n.Mean, 14);
@ -223,12 +344,35 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="sigma">Sigma value.</param>
/// <param name="x">Input X value.</param>
/// <param name="p">Expected value.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(-0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000)] double mu,
[Values(0.100000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000)] double sigma,
[Values(-0.100000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000)] double x,
[Values(0.0, 1.7968349035073582236359415565799753846986440127816e-104, 0.00000018288923328441197822391757965928083462391836798722, 2.3363114904470413709866234247494393485647978367885, 0.90492497850024368541682348133921492204585092983646, 0.49191985207660942803818797602364034466489243416574, 0.33133347214343229148978298237579567194870525187207, 1.0824698632626565182080576574958317806389057196768, 0.31029619474753883558901295436486123689563749784867, 0.19922929916156673799861939824205622734205083805245, 4.1070141770545881694056265342787422035256248474059e-313, 2.8602688726477103843476657332784045661507239533567e-104, 1.6670425710002183246335601541889400558525870482613e-64, 0.10698412103361841220076392503406214751353235895732, 0.18266125308224685664142384493330155315630876975024, 0.17185785323404088913982425377565512294017306418953, 0.50186885259059181992025035649158160252576845315332, 0.21721369314437986034957451699565540205404697589349, 0.15729636000661278918949298391170443742675565300598, 5.6836826548848916385760779034504046896805825555997e-500, 3.1225608678589488061206338085285607881363155340377e-221, 4.6994713794671660918554320071312374073172560048297e-161, 0.015806486291412916772431170442330946677601577502353, 0.055184331257528847223852028950484131834529030116388, 0.063982134749859504449658286955049840393511776984362, 0.25212505662402617595900822552548977822542300480086, 0.14117186955911792460646517002386088579088567275401, 0.11021452580363707866161369621432656293405065561317)] double p)
[TestCase(-0.100000, 0.100000, -0.100000, 0.0)]
[TestCase(-0.100000, 0.100000, 0.100000, 1.7968349035073582236359415565799753846986440127816e-104)]
[TestCase(-0.100000, 0.100000, 0.500000, 0.00000018288923328441197822391757965928083462391836798722)]
[TestCase(-0.100000, 0.100000, 0.800000, 2.3363114904470413709866234247494393485647978367885)]
[TestCase(-0.100000, 1.500000, 0.100000, 0.90492497850024368541682348133921492204585092983646)]
[TestCase(-0.100000, 1.500000, 0.500000, 0.49191985207660942803818797602364034466489243416574)]
[TestCase(-0.100000, 1.500000, 0.800000, 0.33133347214343229148978298237579567194870525187207)]
[TestCase(-0.100000, 2.500000, 0.100000, 1.0824698632626565182080576574958317806389057196768)]
[TestCase(-0.100000, 2.500000, 0.500000, 0.31029619474753883558901295436486123689563749784867)]
[TestCase(-0.100000, 2.500000, 0.800000, 0.19922929916156673799861939824205622734205083805245)]
[TestCase(1.500000, 0.100000, 0.100000, 4.1070141770545881694056265342787422035256248474059e-313)]
[TestCase(1.500000, 0.100000, 0.500000, 2.8602688726477103843476657332784045661507239533567e-104)]
[TestCase(1.500000, 0.100000, 0.800000, 1.6670425710002183246335601541889400558525870482613e-64)]
[TestCase(1.500000, 1.500000, 0.100000, 0.10698412103361841220076392503406214751353235895732)]
[TestCase(1.500000, 1.500000, 0.500000, 0.18266125308224685664142384493330155315630876975024)]
[TestCase(1.500000, 1.500000, 0.800000, 0.17185785323404088913982425377565512294017306418953)]
[TestCase(1.500000, 2.500000, 0.100000, 0.50186885259059181992025035649158160252576845315332)]
[TestCase(1.500000, 2.500000, 0.500000, 0.21721369314437986034957451699565540205404697589349)]
[TestCase(1.500000, 2.500000, 0.800000, 0.15729636000661278918949298391170443742675565300598)]
[TestCase(2.500000, 0.100000, 0.100000, 5.6836826548848916385760779034504046896805825555997e-500)]
[TestCase(2.500000, 0.100000, 0.500000, 3.1225608678589488061206338085285607881363155340377e-221)]
[TestCase(2.500000, 0.100000, 0.800000, 4.6994713794671660918554320071312374073172560048297e-161)]
[TestCase(2.500000, 1.500000, 0.100000, 0.015806486291412916772431170442330946677601577502353)]
[TestCase(2.500000, 1.500000, 0.500000, 0.055184331257528847223852028950484131834529030116388)]
[TestCase(2.500000, 1.500000, 0.800000, 0.063982134749859504449658286955049840393511776984362)]
[TestCase(2.500000, 2.500000, 0.100000, 0.25212505662402617595900822552548977822542300480086)]
[TestCase(2.500000, 2.500000, 0.500000, 0.14117186955911792460646517002386088579088567275401)]
[TestCase(2.500000, 2.500000, 0.800000, 0.11021452580363707866161369621432656293405065561317)]
public void ValidateDensity(double mu, double sigma, double x, double p)
{
var n = new LogNormal(mu, sigma);
AssertHelpers.AlmostEqual(p, n.Density(x), 14);
@ -241,12 +385,35 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="sigma">Sigma value.</param>
/// <param name="x">Input X value.</param>
/// <param name="p">Expected value.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(-0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000)] double mu,
[Values(0.100000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000)] double sigma,
[Values(-0.100000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000)] double x,
[Values(Double.NegativeInfinity, -238.88282294119596467794686179588610665317241097599, -15.514385149961296196003163062199569075052113039686, 0.84857339958981283964373051826407417105725729082041, -0.099903235403144611051953094864849327288457482212211, -0.70943947804316122682964396008813828577195771418027, -1.1046299420497998262946038709903250420774183529995, 0.07924534056485078867266307735371665927517517183681, -1.1702279707433794860424967893989374511050637417043, -1.6132988605030400828957768752511536087538109996183, -719.29643782024317312262673764204041218720576249741, -238.41793403955250272430898754048547661932857086122, -146.85439481068371057247137024006716189469284256628, -2.2350748570877992856465076624973458117562108140674, -1.7001219175524556705452882616787223585705662860012, -1.7610875785399045023354101841009649273236721172008, -0.68941644324162489418137656699398207513321602763104, -1.5268736489667254857801287379715477173125628275598, -1.8496236096394777662704671479709839674424623547308, -1149.5549471196476523788026360929146688367845019398, -507.73265209554698134113704985174959301922196605736, -369.16874994210463740474549611573497379941224077335, -4.1473348984184862316495477617980296904955324113457, -2.8970762200235424747307247601045786110485663457169, -2.7491513791239977024488074547907467152956602019989, -1.3778300581206721947424710027422282714793718026513, -1.9577771978563167352868858774048559682046428490575, -2.2053265778497513183112901654193054111123780652581)] double p)
[TestCase(-0.100000, 0.100000, -0.100000, Double.NegativeInfinity)]
[TestCase(-0.100000, 0.100000, 0.100000, -238.88282294119596467794686179588610665317241097599)]
[TestCase(-0.100000, 0.100000, 0.500000, -15.514385149961296196003163062199569075052113039686)]
[TestCase(-0.100000, 0.100000, 0.800000, 0.84857339958981283964373051826407417105725729082041)]
[TestCase(-0.100000, 1.500000, 0.100000, -0.099903235403144611051953094864849327288457482212211)]
[TestCase(-0.100000, 1.500000, 0.500000, -0.70943947804316122682964396008813828577195771418027)]
[TestCase(-0.100000, 1.500000, 0.800000, -1.1046299420497998262946038709903250420774183529995)]
[TestCase(-0.100000, 2.500000, 0.100000, 0.07924534056485078867266307735371665927517517183681)]
[TestCase(-0.100000, 2.500000, 0.500000, -1.1702279707433794860424967893989374511050637417043)]
[TestCase(-0.100000, 2.500000, 0.800000, -1.6132988605030400828957768752511536087538109996183)]
[TestCase(1.500000, 0.100000, 0.100000, -719.29643782024317312262673764204041218720576249741)]
[TestCase(1.500000, 0.100000, 0.500000, -238.41793403955250272430898754048547661932857086122)]
[TestCase(1.500000, 0.100000, 0.800000, -146.85439481068371057247137024006716189469284256628)]
[TestCase(1.500000, 1.500000, 0.100000, -2.2350748570877992856465076624973458117562108140674)]
[TestCase(1.500000, 1.500000, 0.500000, -1.7001219175524556705452882616787223585705662860012)]
[TestCase(1.500000, 1.500000, 0.800000, -1.7610875785399045023354101841009649273236721172008)]
[TestCase(1.500000, 2.500000, 0.100000, -0.68941644324162489418137656699398207513321602763104)]
[TestCase(1.500000, 2.500000, 0.500000, -1.5268736489667254857801287379715477173125628275598)]
[TestCase(1.500000, 2.500000, 0.800000, -1.8496236096394777662704671479709839674424623547308)]
[TestCase(2.500000, 0.100000, 0.100000, -1149.5549471196476523788026360929146688367845019398)]
[TestCase(2.500000, 0.100000, 0.500000, -507.73265209554698134113704985174959301922196605736)]
[TestCase(2.500000, 0.100000, 0.800000, -369.16874994210463740474549611573497379941224077335)]
[TestCase(2.500000, 1.500000, 0.100000, -4.1473348984184862316495477617980296904955324113457)]
[TestCase(2.500000, 1.500000, 0.500000, -2.8970762200235424747307247601045786110485663457169)]
[TestCase(2.500000, 1.500000, 0.800000, -2.7491513791239977024488074547907467152956602019989)]
[TestCase(2.500000, 2.500000, 0.100000, -1.3778300581206721947424710027422282714793718026513)]
[TestCase(2.500000, 2.500000, 0.500000, -1.9577771978563167352868858774048559682046428490575)]
[TestCase(2.500000, 2.500000, 0.800000, -2.2053265778497513183112901654193054111123780652581)]
public void ValidateDensityLn(double mu, double sigma, double x, double p)
{
var n = new LogNormal(mu, sigma);
AssertHelpers.AlmostEqual(p, n.DensityLn(x), 14);
@ -317,12 +484,35 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="sigma">Sigma value.</param>
/// <param name="x">Input X value.</param>
/// <param name="f">Expected value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(-0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, -0.100000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000, 2.500000)] double mu,
[Values(0.100000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000, 0.100000, 0.100000, 0.100000, 1.500000, 1.500000, 1.500000, 2.500000, 2.500000, 2.500000)] double sigma,
[Values(-0.100000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000, 0.100000, 0.500000, 0.800000)] double x,
[Values(0.0, 0.0, 0.0000000015011556178148777579869633555518882664666520593658, 0.10908001076375810900224507908874442583171381706127, 0.070999149762464508991968731574953594549291668468349, 0.34626224992888089297789445771047690175505847991946, 0.46728530589487698517090261668589508746353129242404, 0.18914969879695093477606645992572208111152994999076, 0.40622798321378106125020505907901206714868922279347, 0.48035707589956665425068652807400957345208517749893, 0.0, 0.0, 0.0, 0.005621455876973168709588070988239748831823850202953, 0.07185716187918271235246980951571040808235628115265, 0.12532699044614938400496547188720940854423187977236, 0.064125647996943514411570834861724406903677144126117, 0.19017302281590810871719754032332631806011441356498, 0.24533064397555500690927047163085419096928289095201, 0.0, 0.0, 0.0, 0.00068304052220788502001572635016579586444611070077399, 0.016636862816580533038130583128179878924863968664206, 0.034729001282904174941366974418836262996834852343018, 0.027363708266690978870139978537188410215717307180775, 0.10075543423327634536450625420610429181921642201567, 0.13802019192453118732001307556787218421918336849121)] double f)
[TestCase(-0.100000, 0.100000, -0.100000, 0.0)]
[TestCase(-0.100000, 0.100000, 0.100000, 0.0)]
[TestCase(-0.100000, 0.100000, 0.500000, 0.0000000015011556178148777579869633555518882664666520593658)]
[TestCase(-0.100000, 0.100000, 0.800000, 0.10908001076375810900224507908874442583171381706127)]
[TestCase(-0.100000, 1.500000, 0.100000, 0.070999149762464508991968731574953594549291668468349)]
[TestCase(-0.100000, 1.500000, 0.500000, 0.34626224992888089297789445771047690175505847991946)]
[TestCase(-0.100000, 1.500000, 0.800000, 0.46728530589487698517090261668589508746353129242404)]
[TestCase(-0.100000, 2.500000, 0.100000, 0.18914969879695093477606645992572208111152994999076)]
[TestCase(-0.100000, 2.500000, 0.500000, 0.40622798321378106125020505907901206714868922279347)]
[TestCase(-0.100000, 2.500000, 0.800000, 0.48035707589956665425068652807400957345208517749893)]
[TestCase(1.500000, 0.100000, 0.100000, 0.0)]
[TestCase(1.500000, 0.100000, 0.500000, 0.0)]
[TestCase(1.500000, 0.100000, 0.800000, 0.0)]
[TestCase(1.500000, 1.500000, 0.100000, 0.005621455876973168709588070988239748831823850202953)]
[TestCase(1.500000, 1.500000, 0.500000, 0.07185716187918271235246980951571040808235628115265)]
[TestCase(1.500000, 1.500000, 0.800000, 0.12532699044614938400496547188720940854423187977236)]
[TestCase(1.500000, 2.500000, 0.100000, 0.064125647996943514411570834861724406903677144126117)]
[TestCase(1.500000, 2.500000, 0.500000, 0.19017302281590810871719754032332631806011441356498)]
[TestCase(1.500000, 2.500000, 0.800000, 0.24533064397555500690927047163085419096928289095201)]
[TestCase(2.500000, 0.100000, 0.100000, 0.0)]
[TestCase(2.500000, 0.100000, 0.500000, 0.0)]
[TestCase(2.500000, 0.100000, 0.800000, 0.0)]
[TestCase(2.500000, 1.500000, 0.100000, 0.00068304052220788502001572635016579586444611070077399)]
[TestCase(2.500000, 1.500000, 0.500000, 0.016636862816580533038130583128179878924863968664206)]
[TestCase(2.500000, 1.500000, 0.800000, 0.034729001282904174941366974418836262996834852343018)]
[TestCase(2.500000, 2.500000, 0.100000, 0.027363708266690978870139978537188410215717307180775)]
[TestCase(2.500000, 2.500000, 0.500000, 0.10075543423327634536450625420610429181921642201567)]
[TestCase(2.500000, 2.500000, 0.800000, 0.13802019192453118732001307556787218421918336849121)]
public void ValidateCumulativeDistribution(double mu, double sigma, double x, double f)
{
var n = new LogNormal(mu, sigma);
AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 8);

168
src/UnitTests/DistributionTests/Continuous/NormalTests.cs

@ -1,4 +1,4 @@
// <copyright file="NormalTests.cs" company="Math.NET">
// <copyright file="NormalTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -62,8 +62,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="mean">Mean value.</param>
/// <param name="sdev">Standard deviation value.</param>
[Test, Combinatorial]
public void CanCreateNormal([Values(0.0, 10.0, -5.0)] double mean, [Values(0.0, 0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double sdev)
[TestCase(0.0, 0.0)]
[TestCase(10.0, 0.1)]
[TestCase(-5.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(10.0, 100.0)]
[TestCase(-5.0, Double.PositiveInfinity)]
public void CanCreateNormal(double mean, double sdev)
{
var n = new Normal(mean, sdev);
Assert.AreEqual(mean, n.Mean);
@ -75,8 +80,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="mean">Mean value.</param>
/// <param name="sdev">Standard deviation value.</param>
[Test, Sequential]
public void NormalCreateFailsWithBadParameters([Values(Double.NaN, 1.0, Double.NaN, 1.0)] double mean, [Values(1.0, Double.NaN, Double.NaN, -1.0)] double sdev)
[TestCase(Double.NaN, 1.0)]
[TestCase(1.0, Double.NaN)]
[TestCase(Double.NaN, Double.NaN)]
[TestCase(1.0, -1.0)]
public void NormalCreateFailsWithBadParameters(double mean, double sdev)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Normal(mean, sdev));
}
@ -86,8 +94,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="mean">Mean value.</param>
/// <param name="sdev">Standard deviation value.</param>
[Test, Combinatorial]
public void CanCreateNormalFromMeanAndStdDev([Values(0.0, 10.0, -5.0)] double mean, [Values(0.0, 0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double sdev)
[TestCase(0.0, 0.0)]
[TestCase(10.0, 0.1)]
[TestCase(-5.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(10.0, 100.0)]
[TestCase(-5.0, Double.PositiveInfinity)]
public void CanCreateNormalFromMeanAndStdDev(double mean, double sdev)
{
var n = Normal.WithMeanStdDev(mean, sdev);
Assert.AreEqual(mean, n.Mean);
@ -99,8 +112,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="mean">Mean value.</param>
/// <param name="var">Variance value.</param>
[Test, Combinatorial]
public void CanCreateNormalFromMeanAndVariance([Values(0.0, 10.0, -5.0)] double mean, [Values(0.0, 0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double var)
[TestCase(0.0, 0.0)]
[TestCase(10.0, 0.1)]
[TestCase(-5.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(10.0, 100.0)]
[TestCase(-5.0, Double.PositiveInfinity)]
public void CanCreateNormalFromMeanAndVariance(double mean, double var)
{
var n = Normal.WithMeanVariance(mean, var);
AssertHelpers.AlmostEqual(mean, n.Mean, 16);
@ -112,8 +130,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="mean">Mean value.</param>
/// <param name="prec">Precision value.</param>
[Test, Combinatorial]
public void CanCreateNormalFromMeanAndPrecision([Values(0.0, 10.0, -5.0)] double mean, [Values(0.0, 0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double prec)
[TestCase(0.0, 0.0)]
[TestCase(10.0, 0.1)]
[TestCase(-5.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(10.0, 100.0)]
[TestCase(-5.0, Double.PositiveInfinity)]
public void CanCreateNormalFromMeanAndPrecision(double mean, double prec)
{
var n = Normal.WithMeanPrecision(mean, prec);
AssertHelpers.AlmostEqual(mean, n.Mean, 15);
@ -134,8 +157,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set precision.
/// </summary>
/// <param name="prec">Precision value.</param>
[Test]
public void CanSetPrecision([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double prec)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetPrecision(double prec)
{
new Normal
{
@ -157,8 +185,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set variance.
/// </summary>
/// <param name="var">Variance value.</param>
[Test]
public void CanSetVariance([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double var)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetVariance(double var)
{
new Normal
{
@ -180,8 +213,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set standard deviation.
/// </summary>
/// <param name="sdev">Standard deviation value.</param>
[Test]
public void CanSetStdDev([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double sdev)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetStdDev(double sdev)
{
new Normal
{
@ -203,8 +241,14 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set mean.
/// </summary>
/// <param name="mean">Mean value.</param>
[Test]
public void CanSetMean([Values(Double.NegativeInfinity, -0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double mean)
[TestCase(Double.NegativeInfinity)]
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetMean(double mean)
{
new Normal
{
@ -216,8 +260,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate entropy.
/// </summary>
/// <param name="sdev">Standard deviation value.</param>
[Test]
public void ValidateEntropy([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double sdev)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateEntropy(double sdev)
{
var n = new Normal(1.0, sdev);
Assert.AreEqual(Constants.LogSqrt2PiE + Math.Log(n.StdDev), n.Entropy);
@ -227,8 +276,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate skewness.
/// </summary>
/// <param name="sdev">Standard deviation value.</param>
[Test]
public void ValidateSkewness([Values(-0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double sdev)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateSkewness(double sdev)
{
var n = new Normal(1.0, sdev);
Assert.AreEqual(0.0, n.Skewness);
@ -238,8 +292,14 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate mean.
/// </summary>
/// <param name="mean">Mean value.</param>
[Test]
public void ValidateMode([Values(Double.NegativeInfinity, -0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double mean)
[TestCase(Double.NegativeInfinity)]
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMode(double mean)
{
var n = new Normal(mean, 1.0);
Assert.AreEqual(mean, n.Mode);
@ -249,8 +309,14 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate median.
/// </summary>
/// <param name="mean">Mean value.</param>
[Test]
public void ValidateMedian([Values(Double.NegativeInfinity, -0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double mean)
[TestCase(Double.NegativeInfinity)]
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMedian(double mean)
{
var n = new Normal(mean, 1.0);
Assert.AreEqual(mean, n.Median);
@ -281,8 +347,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="mean">Mean value.</param>
/// <param name="sdev">Standard deviation value.</param>
[Test, Combinatorial]
public void ValidateDensity([Values(0.0, 10.0, -5.0)] double mean, [Values(0.0, 0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double sdev)
[TestCase(0.0, 0.0)]
[TestCase(10.0, 0.1)]
[TestCase(-5.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(10.0, 100.0)]
[TestCase(-5.0, Double.PositiveInfinity)]
public void ValidateDensity(double mean, double sdev)
{
var n = Normal.WithMeanStdDev(mean, sdev);
for (var i = 0; i < 11; i++)
@ -299,8 +370,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="mean">Mean value.</param>
/// <param name="sdev">Standard deviation value.</param>
[Test, Combinatorial]
public void ValidateDensityLn([Values(0.0, 10.0, -5.0)] double mean, [Values(0.0, 0.1, 1.0, 10.0, 100.0, Double.PositiveInfinity)] double sdev)
[TestCase(0.0, 0.0)]
[TestCase(10.0, 0.1)]
[TestCase(-5.0, 1.0)]
[TestCase(0.0, 10.0)]
[TestCase(10.0, 100.0)]
[TestCase(-5.0, Double.PositiveInfinity)]
public void ValidateDensityLn(double mean, double sdev)
{
var n = Normal.WithMeanStdDev(mean, sdev);
for (var i = 0; i < 11; i++)
@ -375,10 +451,17 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="x">Input X value.</param>
/// <param name="f">Expected value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(Double.NegativeInfinity, -5.0, -2.0, -0.0, 0.0, 4.0, 5.0, 6.0, 10.0, Double.PositiveInfinity)] double x,
[Values(0.0, 0.00000028665157187919391167375233287464535385442301361187883, 0.0002326290790355250363499258867279847735487493358890356, 0.0062096653257761351669781045741922211278977469230927036, 0.0062096653257761351669781045741922211278977469230927036, 0.30853753872598689636229538939166226011639782444542207, 0.5, 0.69146246127401310363770461060833773988360217555457859, 0.9937903346742238648330218954258077788721022530769078, 1.0)] double f)
[TestCase(Double.NegativeInfinity, 0.0)]
[TestCase(-5.0, 0.00000028665157187919391167375233287464535385442301361187883)]
[TestCase(-2.0, 0.0002326290790355250363499258867279847735487493358890356)]
[TestCase(-0.0, 0.0062096653257761351669781045741922211278977469230927036)]
[TestCase(0.0, 0.0062096653257761351669781045741922211278977469230927036)]
[TestCase(4.0, 0.30853753872598689636229538939166226011639782444542207)]
[TestCase(5.0, 0.5)]
[TestCase(6.0, 0.69146246127401310363770461060833773988360217555457859)]
[TestCase(10.0, 0.9937903346742238648330218954258077788721022530769078)]
[TestCase(Double.PositiveInfinity, 1.0)]
public void ValidateCumulativeDistribution(double x, double f)
{
var n = Normal.WithMeanStdDev(5.0, 2.0);
AssertHelpers.AlmostEqual(f, n.CumulativeDistribution(x), 10);
@ -389,10 +472,17 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="x">Input X value.</param>
/// <param name="f">Expected value.</param>
[Test, Sequential]
public void ValidateInverseCumulativeDistribution(
[Values(Double.NegativeInfinity, -5.0, -2.0, -0.0, 0.0, 4.0, 5.0, 6.0, 10.0, Double.PositiveInfinity)] double x,
[Values(0.0, 0.00000028665157187919391167375233287464535385442301361187883, 0.0002326290790355250363499258867279847735487493358890356, 0.0062096653257761351669781045741922211278977469230927036, .0062096653257761351669781045741922211278977469230927036, .30853753872598689636229538939166226011639782444542207, .5, .69146246127401310363770461060833773988360217555457859, 0.9937903346742238648330218954258077788721022530769078, 1.0)] double f)
[TestCase(Double.NegativeInfinity, 0.0)]
[TestCase(-5.0, 0.00000028665157187919391167375233287464535385442301361187883)]
[TestCase(-2.0, 0.0002326290790355250363499258867279847735487493358890356)]
[TestCase(-0.0, 0.0062096653257761351669781045741922211278977469230927036)]
[TestCase(0.0, .0062096653257761351669781045741922211278977469230927036)]
[TestCase(4.0, .30853753872598689636229538939166226011639782444542207)]
[TestCase(5.0, .5)]
[TestCase(6.0, .69146246127401310363770461060833773988360217555457859)]
[TestCase(10.0, 0.9937903346742238648330218954258077788721022530769078)]
[TestCase(Double.PositiveInfinity, 1.0)]
public void ValidateInverseCumulativeDistribution(double x, double f)
{
var n = Normal.WithMeanStdDev(5.0, 2.0);
AssertHelpers.AlmostEqual(x, n.InverseCumulativeDistribution(f), 15);

131
src/UnitTests/DistributionTests/Continuous/ParetoTests.cs

@ -1,4 +1,4 @@
// <copyright file="ParetoTests.cs" company="Math.NET">
// <copyright file="ParetoTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
[Test, Combinatorial]
public void CanCreatePareto([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void CanCreatePareto(double scale, double shape)
{
var n = new Pareto(scale, shape);
Assert.AreEqual(scale, n.Scale);
@ -64,10 +67,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
[Test, Sequential]
public void ParetoCreateFailsWithBadParameters(
[Values(Double.NaN, 1.0, Double.NaN, 1.0, -1.0, -1.0, 0.0, 0.0, 1.0)] double scale,
[Values(1.0, Double.NaN, Double.NaN, -1.0, 1.0, -1.0, 0.0, 1.0, 0.0)] double shape)
[TestCase(Double.NaN, 1.0)]
[TestCase(1.0, Double.NaN)]
[TestCase(Double.NaN, Double.NaN)]
[TestCase(1.0, -1.0)]
[TestCase(-1.0, 1.0)]
[TestCase(-1.0, -1.0)]
[TestCase(0.0, 0.0)]
[TestCase(0.0, 1.0)]
[TestCase(1.0, 0.0)]
public void ParetoCreateFailsWithBadParameters(double scale, double shape)
{
Assert.Throws<ArgumentOutOfRangeException>(() => { var n = new Pareto(scale, shape); });
}
@ -86,8 +95,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set scale.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void CanSetScale([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetScale(double scale)
{
new Pareto(1.0, 1.0)
{
@ -109,8 +121,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set shape.
/// </summary>
/// <param name="shape">Shape value.</param>
[Test]
public void CanSetShape([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetShape(double shape)
{
new Pareto(1.0, 1.0)
{
@ -133,8 +148,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
[Test, Combinatorial]
public void ValidateMean([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateMean(double scale, double shape)
{
var n = new Pareto(scale, shape);
if (shape > 1)
@ -148,8 +166,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
[Test, Combinatorial]
public void ValidateVariance([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateVariance(double scale, double shape)
{
var n = new Pareto(scale, shape);
if (shape <= 2.0)
@ -167,8 +188,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
[Test, Combinatorial]
public void ValidateStdDev([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateStdDev(double scale, double shape)
{
var n = new Pareto(scale, shape);
Assert.AreEqual((scale * Math.Sqrt(shape)) / ((shape - 1.0) * Math.Sqrt(shape - 2.0)), n.StdDev);
@ -179,8 +203,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
[Test, Combinatorial]
public void ValidateEntropy([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateEntropy(double scale, double shape)
{
var n = new Pareto(scale, shape);
Assert.AreEqual(Math.Log(shape / scale) - (1.0 / shape) - 1.0, n.Entropy);
@ -191,8 +218,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
[Test, Combinatorial]
public void ValidateSkewness([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateSkewness(double scale, double shape)
{
var n = new Pareto(scale, shape);
Assert.AreEqual((2.0 * (shape + 1.0) / (shape - 3.0)) * Math.Sqrt((shape - 2.0) / shape), n.Skewness);
@ -203,8 +233,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
[Test, Combinatorial]
public void ValidateMode([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateMode(double scale, double shape)
{
var n = new Pareto(scale, shape);
Assert.AreEqual(scale, n.Mode);
@ -215,10 +248,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
[Test, Combinatorial]
public void ValidateMedian(
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale,
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateMedian(double scale, double shape)
{
var n = new Pareto(scale, shape);
Assert.AreEqual(scale * Math.Pow(2.0, 1.0 / shape), n.Median);
@ -228,8 +262,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate minimum.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void ValidateMinimum([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMinimum(double scale)
{
var n = new Pareto(scale, 1.0);
Assert.AreEqual(scale, n.Minimum);
@ -251,11 +288,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateDensity(
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale,
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape,
[Values(0.1, 1.0, 2.0, 2.1, 10.0, 12.0, Double.PositiveInfinity)] double x)
[TestCase(0.1, 0.1, 0.1)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(5.0, 5.0, 2.0)]
[TestCase(7.0, 7.0, 10.0)]
[TestCase(10.0, 10.0, 12.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateDensity(double scale, double shape, double x)
{
var n = new Pareto(scale, shape);
Assert.AreEqual(shape * Math.Pow(scale, shape) / Math.Pow(x, shape + 1.0), n.Density(x));
@ -267,11 +306,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateDensityLn(
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale,
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape,
[Values(0.1, 1.0, 2.0, 2.1, 10.0, 12.0, Double.PositiveInfinity)] double x)
[TestCase(0.1, 0.1, 0.1)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(5.0, 5.0, 2.0)]
[TestCase(7.0, 7.0, 10.0)]
[TestCase(10.0, 10.0, 12.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateDensityLn(double scale, double shape, double x)
{
var n = new Pareto(scale, shape);
Assert.AreEqual(Math.Log(n.Density(x)), n.DensityLn(x));
@ -304,11 +345,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="scale">Scale value.</param>
/// <param name="shape">Shape value.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateCumulativeDistribution(
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale,
[Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape,
[Values(0.1, 1.0, 2.0, 2.1, 10.0, 12.0, Double.PositiveInfinity)] double x)
[TestCase(0.1, 0.1, 0.1)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(5.0, 5.0, 2.0)]
[TestCase(7.0, 7.0, 10.0)]
[TestCase(10.0, 10.0, 12.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateCumulativeDistribution(double scale, double shape, double x)
{
var n = new Pareto(scale, shape);
Assert.AreEqual(1.0 - Math.Pow(scale / x, shape), n.CumulativeDistribution(x));

115
src/UnitTests/DistributionTests/Continuous/RayleighTests.cs

@ -1,4 +1,4 @@
// <copyright file="RayleighTests.cs" company="Math.NET">
// <copyright file="RayleighTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -50,8 +50,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can create Rayleigh
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void CanCreateRayleigh([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanCreateRayleigh(double scale)
{
var n = new Rayleigh(scale);
Assert.AreEqual(scale, n.Scale);
@ -61,8 +64,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Rayleigh create fails with bad parameters.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void RayleighCreateFailsWithBadParameters([Values(Double.NaN, Double.NegativeInfinity, -1.0, 0.0)] double scale)
[TestCase(Double.NaN)]
[TestCase(Double.NegativeInfinity)]
[TestCase(-1.0)]
[TestCase(0.0)]
public void RayleighCreateFailsWithBadParameters(double scale)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Rayleigh(scale));
}
@ -81,8 +87,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set scale.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void CanSetScale([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetScale(double scale)
{
new Rayleigh(1.0)
{
@ -94,8 +103,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set scale fails with negative scale.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void SetScaleFailsWithNegativeScale([Values(-0.0, 0.0, -1.0, Double.NegativeInfinity, Double.NaN)] double scale)
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(-1.0)]
[TestCase(Double.NegativeInfinity)]
[TestCase(Double.NaN)]
public void SetScaleFailsWithNegativeScale(double scale)
{
var n = new Rayleigh(1.0);
Assert.Throws<ArgumentOutOfRangeException>(() => n.Scale = scale);
@ -105,8 +118,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate mean.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void ValidateMean([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMean(double scale)
{
var n = new Rayleigh(scale);
Assert.AreEqual(scale * Math.Sqrt(Constants.PiOver2), n.Mean);
@ -116,8 +132,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate variance.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void ValidateVariance([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateVariance(double scale)
{
var n = new Rayleigh(scale);
Assert.AreEqual((2.0 - Constants.PiOver2) * scale * scale, n.Variance);
@ -127,8 +146,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate standard deviation.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void ValidateStdDev([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateStdDev(double scale)
{
var n = new Rayleigh(scale);
Assert.AreEqual(Math.Sqrt(2.0 - Constants.PiOver2) * scale, n.StdDev);
@ -138,8 +160,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate entropy.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void ValidateEntropy([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateEntropy(double scale)
{
var n = new Rayleigh(scale);
Assert.AreEqual(1.0 + Math.Log(scale / Math.Sqrt(2)) + (Constants.EulerMascheroni / 2.0), n.Entropy);
@ -150,8 +175,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="skn">Expected value.</param>
[Test, Combinatorial]
public void ValidateSkewness([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.63111065781893638)] double skn)
[TestCase(0.1, 0.63111065781893638)]
[TestCase(1.0, 0.63111065781893638)]
[TestCase(10.0, 0.63111065781893638)]
[TestCase(Double.PositiveInfinity, 0.63111065781893638)]
public void ValidateSkewness(double scale, double skn)
{
var n = new Rayleigh(scale);
AssertHelpers.AlmostEqual(skn, n.Skewness, 17);
@ -161,8 +189,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate mode.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void ValidateMode([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMode(double scale)
{
var n = new Rayleigh(scale);
Assert.AreEqual(scale, n.Mode);
@ -172,8 +203,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate median.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void ValidateMedian([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMedian(double scale)
{
var n = new Rayleigh(scale);
Assert.AreEqual(scale * Math.Sqrt(Math.Log(4.0)), n.Median);
@ -183,8 +217,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate minimum.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void ValidateMinimum([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMinimum(double scale)
{
var n = new Rayleigh(scale);
Assert.AreEqual(0.0, n.Minimum);
@ -194,8 +231,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate maximum.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void ValidateMaximum([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMaximum(double scale)
{
var n = new Rayleigh(1.0);
Assert.AreEqual(Double.PositiveInfinity, n.Maximum);
@ -206,8 +246,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateDensity([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double x)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateDensity(double scale, double x)
{
var n = new Rayleigh(scale);
Assert.AreEqual((x / (scale * scale)) * Math.Exp(-x * x / (2.0 * scale * scale)), n.Density(x));
@ -218,8 +261,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateDensityLn([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double x)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateDensityLn(double scale, double x)
{
var n = new Rayleigh(scale);
Assert.AreEqual(Math.Log(x / (scale * scale)) - (x * (x / (2.0 * (scale * scale)))), n.DensityLn(x));
@ -251,8 +297,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="scale">Scale value.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateCumulativeDistribution([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double x)
[TestCase(0.1, 0.1)]
[TestCase(1.0, 1.0)]
[TestCase(10.0, 10.0)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void ValidateCumulativeDistribution(double scale, double x)
{
var n = new Rayleigh(scale);
Assert.AreEqual(1.0 - Math.Exp(-x * x / (2.0 * scale * scale)), n.CumulativeDistribution(x));

175
src/UnitTests/DistributionTests/Continuous/StableTests.cs

@ -1,4 +1,4 @@
// <copyright file="StableTests.cs" company="Math.NET">
// <copyright file="StableTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -53,8 +53,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="beta">Beta value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="location">Location value.</param>
[Test, Combinatorial]
public void CanCreateStable([Values(0.1, 2.0)] double alpha, [Values(-1.0, 1.0)] double beta, [Values(0.1, Double.PositiveInfinity)] double scale, [Values(Double.NegativeInfinity, -1.0, 0.0, 1.0, Double.PositiveInfinity)] double location)
[TestCase(0.1, -1.0, 0.1, Double.NegativeInfinity)]
[TestCase(2.0, 1.0, Double.PositiveInfinity, -1.0)]
[TestCase(0.1, -1.0, 0.1, 0.0)]
[TestCase(2.0, 1.0, Double.PositiveInfinity, 1.0)]
[TestCase(0.1, -1.0, 0.1, Double.PositiveInfinity)]
public void CanCreateStable(double alpha, double beta, double scale, double location)
{
var n = new Stable(alpha, beta, scale, location);
Assert.AreEqual(alpha, n.Alpha);
@ -70,12 +74,25 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="beta">Beta value.</param>
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void StableCreateFailsWithBadParameters(
[Values(Double.NaN, 1.0, Double.NaN, Double.NaN, Double.NaN, 1.0, 1.0, 1.0, Double.NaN, 1.0, 1.0, 1.0, Double.NaN, 1.0, 1.0, 1.0, 0.0, 2.1)] double alpha,
[Values(Double.NaN, Double.NaN, 1.0, Double.NaN, Double.NaN, 1.0, Double.NaN, Double.NaN, 1.0, 1.0, 1.0, Double.NaN, 1.0, 1.0, -1.1, 1.1, 1.0, 1.0)] double beta,
[Values(Double.NaN, Double.NaN, Double.NaN, 1.0, Double.NaN, Double.NaN, 1.0, Double.NaN, 1.0, 1.0, Double.NaN, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0)] double location,
[Values(Double.NaN, Double.NaN, Double.NaN, Double.NaN, 1.0, Double.NaN, Double.NaN, 1.0, Double.NaN, Double.NaN, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale)
[TestCase(Double.NaN, Double.NaN, Double.NaN, Double.NaN)]
[TestCase(1.0, Double.NaN, Double.NaN, Double.NaN)]
[TestCase(Double.NaN, 1.0, Double.NaN, Double.NaN)]
[TestCase(Double.NaN, Double.NaN, 1.0, Double.NaN)]
[TestCase(Double.NaN, Double.NaN, Double.NaN, 1.0)]
[TestCase(1.0, 1.0, Double.NaN, Double.NaN)]
[TestCase(1.0, Double.NaN, 1.0, Double.NaN)]
[TestCase(1.0, Double.NaN, Double.NaN, 1.0)]
[TestCase(Double.NaN, 1.0, 1.0, Double.NaN)]
[TestCase(1.0, 1.0, 1.0, Double.NaN)]
[TestCase(1.0, 1.0, Double.NaN, 1.0)]
[TestCase(1.0, Double.NaN, 1.0, 1.0)]
[TestCase(Double.NaN, 1.0, 1.0, 1.0)]
[TestCase(1.0, 1.0, 0.0, 1.0)]
[TestCase(1.0, -1.1, 1.0, 1.0)]
[TestCase(1.0, 1.1, 1.0, 1.0)]
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(2.1, 1.0, 1.0, 1.0)]
public void StableCreateFailsWithBadParameters(double alpha, double beta, double location, double scale)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Stable(alpha, beta, location, scale));
}
@ -94,8 +111,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set alpha.
/// </summary>
/// <param name="alpha">Alpha value.</param>
[Test]
public void CanSetAlpha([Values(0.1, 1.0, 2.0)] double alpha)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(2.0)]
public void CanSetAlpha(double alpha)
{
new Stable(1.0, 1.0, 1.0, 1.0)
{
@ -107,8 +126,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set alpha fails with bad values.
/// </summary>
/// <param name="alpha">Alpha value.</param>
[Test]
public void SetAlphaFail([Values(Double.NaN, -0.0, 0.0, 2.1, Double.NegativeInfinity, Double.PositiveInfinity)] double alpha)
[TestCase(Double.NaN)]
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(2.1)]
[TestCase(Double.NegativeInfinity)]
[TestCase(Double.PositiveInfinity)]
public void SetAlphaFail(double alpha)
{
var n = new Stable(1.0, 1.0, 1.0, 1.0);
Assert.Throws<ArgumentOutOfRangeException>(() => n.Alpha = alpha);
@ -118,8 +142,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set beta.
/// </summary>
/// <param name="beta">Beta value.</param>
[Test]
public void CanSetBeta([Values(-1.0, -0.1, -0.0, 0.0, 0.1, 1.0)] double beta)
[TestCase(-1.0)]
[TestCase(-0.1)]
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
public void CanSetBeta(double beta)
{
new Stable(1.0, 1.0, 1.0, 1.0)
{
@ -131,8 +160,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set beta fails with bad values.
/// </summary>
/// <param name="beta">Beta value.</param>
[Test]
public void SetBetaFail([Values(Double.NaN, -1.1, 1.1, Double.NegativeInfinity, Double.PositiveInfinity)] double beta)
[TestCase(Double.NaN)]
[TestCase(-1.1)]
[TestCase(1.1)]
[TestCase(Double.NegativeInfinity)]
[TestCase(Double.PositiveInfinity)]
public void SetBetaFail(double beta)
{
var n = new Stable(1.0, 1.0, 1.0, 1.0);
Assert.Throws<ArgumentOutOfRangeException>(() => n.Beta = beta);
@ -142,8 +175,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set scale.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void CanSetScale([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetScale(double scale)
{
new Stable(1.0, 1.0, 1.0, 1.0)
{
@ -155,8 +191,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set scale fails with bad values.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void SetScaleFail([Values(Double.NaN, 0.0)] double scale)
[TestCase(Double.NaN)]
[TestCase(0.0)]
public void SetScaleFail(double scale)
{
var n = new Stable(1.0, 1.0, 1.0, 1.0);
Assert.Throws<ArgumentOutOfRangeException>(() => n.Scale = scale);
@ -166,8 +203,15 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set location.
/// </summary>
/// <param name="location">Location value.</param>
[Test]
public void CanSetLocation([Values(Double.NegativeInfinity, -10.0, -1.0, -0.1, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double location)
[TestCase(Double.NegativeInfinity)]
[TestCase(-10.0)]
[TestCase(-1.0)]
[TestCase(-0.1)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetLocation(double location)
{
new Stable(1.0, 1.0, 1.0, 1.0)
{
@ -212,8 +256,15 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate mode.
/// </summary>
/// <param name="location">Location value.</param>
[Test]
public void ValidateMode([Values(Double.NegativeInfinity, -10.0, -1.0, -0.1, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double location)
[TestCase(Double.NegativeInfinity)]
[TestCase(-10.0)]
[TestCase(-1.0)]
[TestCase(-0.1)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMode(double location)
{
var n = new Stable(1.0, 0.0, 1.0, location);
if (n.Beta == 0)
@ -226,8 +277,15 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate mean.
/// </summary>
/// <param name="location">Location value.</param>
[Test]
public void ValidateMedian([Values(Double.NegativeInfinity, -10.0, -1.0, -0.1, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double location)
[TestCase(Double.NegativeInfinity)]
[TestCase(-10.0)]
[TestCase(-1.0)]
[TestCase(-0.1)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void ValidateMedian(double location)
{
var n = new Stable(1.0, 0.0, 1.0, location);
if (n.Beta == 0)
@ -240,8 +298,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Validate minimum.
/// </summary>
/// <param name="beta">Beta value.</param>
[Test]
public void ValidateMinimum([Values(-1.0, -0.1, -0.0, 0.0, 0.1, 1.0)] double beta)
[TestCase(-1.0)]
[TestCase(-0.1)]
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
public void ValidateMinimum(double beta)
{
var n = new Stable(1.0, beta, 1.0, 1.0);
Assert.AreEqual(Math.Abs(beta) != 1 ? Double.NegativeInfinity : 0.0, n.Minimum);
@ -266,14 +329,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="location">Location value.</param>
/// <param name="x">Input X value.</param>
/// <param name="d">Expected value.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 0.5, 0.5, 0.5)] double alpha,
[Values(-1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0)] double beta,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale,
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location,
[Values(1.5, 3.0, 5.0, 1.5, 3.0, 5.0, 1.5, 3.0, 5.0)] double x,
[Values(0.16073276729880184, 0.029732572305907354, 0.00054457105758817781, 0.097941503441166353, 0.031830988618379068, 0.012242687930145794, 0.15559955475708653, 0.064989885240913717, 0.032286845174307237)] double d)
[TestCase(2.0, -1.0, 1.0, 0.0, 1.5, 0.16073276729880184)]
[TestCase(2.0, -1.0, 1.0, 0.0, 3.0, 0.029732572305907354)]
[TestCase(2.0, -1.0, 1.0, 0.0, 5.0, 0.00054457105758817781)]
[TestCase(1.0, 0.0, 1.0, 0.0, 1.5, 0.097941503441166353)]
[TestCase(1.0, 0.0, 1.0, 0.0, 3.0, 0.031830988618379068)]
[TestCase(1.0, 0.0, 1.0, 0.0, 5.0, 0.012242687930145794)]
[TestCase(0.5, 1.0, 1.0, 0.0, 1.5, 0.15559955475708653)]
[TestCase(0.5, 1.0, 1.0, 0.0, 3.0, 0.064989885240913717)]
[TestCase(0.5, 1.0, 1.0, 0.0, 5.0, 0.032286845174307237)]
public void ValidateDensity(double alpha, double beta, double scale, double location, double x, double d)
{
var n = new Stable(alpha, beta, scale, location);
AssertHelpers.AlmostEqual(d, n.Density(x), 15);
@ -288,14 +353,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="location">Location value.</param>
/// <param name="x">Input X value.</param>
/// <param name="dln">Expected value.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 0.5, 0.5, 0.5)] double alpha,
[Values(-1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0)] double beta,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale,
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location,
[Values(1.5, 3.0, 5.0, 1.5, 3.0, 5.0, 1.5, 3.0, 5.0)] double x,
[Values(-1.8280121234846454, -3.5155121234846449, -7.5155121234846449, -2.3233848821910463, -3.4473149788434458, -4.4028264238708825, -1.8604695287002526, -2.7335236328735038, -3.4330954018558235)] double dln)
[TestCase(2.0, -1.0, 1.0, 0.0, 1.5, -1.8280121234846454)]
[TestCase(2.0, -1.0, 1.0, 0.0, 3.0, -3.5155121234846449)]
[TestCase(2.0, -1.0, 1.0, 0.0, 5.0, -7.5155121234846449)]
[TestCase(1.0, 0.0, 1.0, 0.0, 1.5, -2.3233848821910463)]
[TestCase(1.0, 0.0, 1.0, 0.0, 3.0, -3.4473149788434458)]
[TestCase(1.0, 0.0, 1.0, 0.0, 5.0, -4.4028264238708825)]
[TestCase(0.5, 1.0, 1.0, 0.0, 1.5, -1.8604695287002526)]
[TestCase(0.5, 1.0, 1.0, 0.0, 3.0, -2.7335236328735038)]
[TestCase(0.5, 1.0, 1.0, 0.0, 5.0, -3.4330954018558235)]
public void ValidateDensityLn(double alpha, double beta, double scale, double location, double x, double dln)
{
var n = new Stable(alpha, beta, scale, location);
AssertHelpers.AlmostEqual(dln, n.DensityLn(x), 15);
@ -331,14 +398,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="location">Location value.</param>
/// <param name="x">Input X value.</param>
/// <param name="cdf">Expected value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(2.0, 2.0, 2.0, 1.0, 1.0, 1.0, 0.5, 0.5, 0.5)] double alpha,
[Values(-1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0)] double beta,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale,
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location,
[Values(1.5, 3.0, 5.0, 1.5, 3.0, 5.0, 1.5, 3.0, 5.0)] double x,
[Values(0.8555778168267576, 0.98305257323765538, 0.9997965239912775, 0.81283295818900125, 0.89758361765043326, 0.93716704181099886, 0.41421617824252516, 0.563702861650773, 0.65472084601857694)] double cdf)
[TestCase(2.0, -1.0, 1.0, 0.0, 1.5, 0.8555778168267576)]
[TestCase(2.0, -1.0, 1.0, 0.0, 3.0, 0.98305257323765538)]
[TestCase(2.0, -1.0, 1.0, 0.0, 5.0, 0.9997965239912775)]
[TestCase(1.0, 0.0, 1.0, 0.0, 1.5, 0.81283295818900125)]
[TestCase(1.0, 0.0, 1.0, 0.0, 3.0, 0.89758361765043326)]
[TestCase(1.0, 0.0, 1.0, 0.0, 5.0, 0.93716704181099886)]
[TestCase(0.5, 1.0, 1.0, 0.0, 1.5, 0.41421617824252516)]
[TestCase(0.5, 1.0, 1.0, 0.0, 3.0, 0.563702861650773)]
[TestCase(0.5, 1.0, 1.0, 0.0, 5.0, 0.65472084601857694)]
public void ValidateCumulativeDistribution(double alpha, double beta, double scale, double location, double x, double cdf)
{
var n = new Stable(alpha, beta, scale, location);
AssertHelpers.AlmostEqual(cdf, n.CumulativeDistribution(x), 15);

205
src/UnitTests/DistributionTests/Continuous/StudentTTests.cs

@ -1,4 +1,4 @@
// <copyright file="StudentTTests.cs" company="Math.NET">
// <copyright file="StudentTTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -64,8 +64,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="dof">Degrees of freedom.</param>
[Test, Combinatorial]
public void CanCreateStudentT([Values(0.0, -5.0, 10.0)] double location, [Values(0.1, 1.0, 10.0)] double scale, [Values(1.0, 3.0, Double.PositiveInfinity)] double dof)
[TestCase(0.0, 0.1, 1.0)]
[TestCase(-5.0, 1.0, 3.0)]
[TestCase(10.0, 10.0, Double.PositiveInfinity)]
public void CanCreateStudentT(double location, double scale, double dof)
{
var n = new StudentT(location, scale, dof);
Assert.AreEqual(location, n.Location);
@ -79,11 +81,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="dof">Degrees of freedom.</param>
[Test, Sequential]
public void StudentTCreateFailsWithBadParameters(
[Values(Double.NaN, 0.0, 0.0, 0.0, 0.0)] double location,
[Values(1.0, Double.NaN, 1.0, -10.0, 10.0)] double scale,
[Values(1.0, 1.0, Double.NaN, 1.0, -1.0)] double dof)
[TestCase(Double.NaN, 1.0, 1.0)]
[TestCase(0.0, Double.NaN, 1.0)]
[TestCase(0.0, 1.0, Double.NaN)]
[TestCase(0.0, -10.0, 1.0)]
[TestCase(0.0, 10.0, -1.0)]
public void StudentTCreateFailsWithBadParameters(double location, double scale, double dof)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new StudentT(location, scale, dof));
}
@ -102,8 +105,15 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set location.
/// </summary>
/// <param name="loc">Location value.</param>
[Test]
public void CanSetLocation([Values(Double.NegativeInfinity, -5.0, -0.0, 0.0, 0.1, 1.0, 10.0, Double.PositiveInfinity)] double loc)
[TestCase(Double.NegativeInfinity)]
[TestCase(-5.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetLocation(double loc)
{
new StudentT
{
@ -115,8 +125,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set scale.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void CanSetScale([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetScale(double scale)
{
new StudentT
{
@ -128,8 +141,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set scale fails with non-positive scale.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void SetScaleFailsWithNonPositiveScale([Values(-1.0, -0.0, 0.0)] double scale)
[TestCase(-1.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
public void SetScaleFailsWithNonPositiveScale(double scale)
{
var n = new StudentT();
Assert.Throws<ArgumentOutOfRangeException>(() => n.Scale = scale);
@ -139,8 +154,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set degrees of freedom.
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
[Test]
public void CanSetDoF([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double dof)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetDoF(double dof)
{
new StudentT
{
@ -152,8 +170,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set degrees of freedom fails with non-positive value.
/// </summary>
/// <param name="dof">Degrees of freedom.</param>
[Test]
public void SetDofFailsWithNonPositiveDoF([Values(-1.0, -0.0, 0.0)] double dof)
[TestCase(-1.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
public void SetDofFailsWithNonPositiveDoF(double dof)
{
var n = new StudentT();
Assert.Throws<ArgumentOutOfRangeException>(() => n.DegreesOfFreedom = dof);
@ -166,12 +186,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="scale">Scale value.</param>
/// <param name="dof">Degrees of freedom.</param>
/// <param name="mean">Expected value.</param>
[Test, Sequential]
public void ValidateMean(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, -5.0, 0.0)] double location,
[Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 1.0, 100.0, Double.PositiveInfinity)] double scale,
[Values(1.0, 1.0, 3.0, 1.0, 2.0, Double.PositiveInfinity, 1.0, 1.5, 1.0)] double dof,
[Values(Double.NaN, Double.NaN, 0.0, Double.NaN, 0.0, 0.0, Double.NaN, -5.0, Double.NaN)] double mean)
[TestCase(0.0, 1.0, 1.0, Double.NaN)]
[TestCase(0.0, 0.1, 1.0, Double.NaN)]
[TestCase(0.0, 1.0, 3.0, 0.0)]
[TestCase(0.0, 10.0, 1.0, Double.NaN)]
[TestCase(0.0, 10.0, 2.0, 0.0)]
[TestCase(0.0, 10.0, Double.PositiveInfinity, 0.0)]
[TestCase(10.0, 1.0, 1.0, Double.NaN)]
[TestCase(-5.0, 100.0, 1.5, -5.0)]
[TestCase(0.0, Double.PositiveInfinity, 1.0, Double.NaN)]
public void ValidateMean(double location, double scale, double dof, double mean)
{
var n = new StudentT(location, scale, dof);
Assert.AreEqual(mean, n.Mean);
@ -184,12 +208,18 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="scale">Scale value.</param>
/// <param name="dof">Degrees of freedom.</param>
/// <param name="var">Expected value.</param>
[Test, Sequential]
public void ValidateVariance(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 10.0, -5.0, 0.0)] double location,
[Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 10.0, 1.0, 1.0, 100.0, Double.PositiveInfinity)] double scale,
[Values(1.0, 1.0, 3.0, 1.0, 2.0, 2.5, Double.PositiveInfinity, 1.0, 2.5, 1.5, 1.0)] double dof,
[Values(Double.NaN, Double.NaN, 3.0, Double.NaN, Double.PositiveInfinity, 500.0, 100.0, Double.NaN, 5.0, Double.PositiveInfinity, Double.NaN)] double var)
[TestCase(0.0, 1.0, 1.0, Double.NaN)]
[TestCase(0.0, 0.1, 1.0, Double.NaN)]
[TestCase(0.0, 1.0, 3.0, 3.0)]
[TestCase(0.0, 10.0, 1.0, Double.NaN)]
[TestCase(0.0, 10.0, 2.0, Double.PositiveInfinity)]
[TestCase(0.0, 10.0, 2.5, 500.0)]
[TestCase(0.0, 10.0, Double.PositiveInfinity, 100.0)]
[TestCase(10.0, 1.0, 1.0, Double.NaN)]
[TestCase(10.0, 1.0, 2.5, 5.0)]
[TestCase(-5.0, 100.0, 1.5, Double.PositiveInfinity)]
[TestCase(0.0, Double.PositiveInfinity, 1.0, Double.NaN)]
public void ValidateVariance(double location, double scale, double dof, double var)
{
var n = new StudentT(location, scale, dof);
Assert.AreEqual(var, n.Variance);
@ -202,12 +232,18 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="scale">Scale value.</param>
/// <param name="dof">Degrees of freedom.</param>
/// <param name="sdev">Expected value.</param>
[Test, Sequential]
public void ValidateStdDev(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 10.0, -5.0, 0.0)] double location,
[Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 10.0, 1.0, 1.0, 100.0, Double.PositiveInfinity)] double scale,
[Values(1.0, 1.0, 3.0, 1.0, 2.0, 2.5, Double.PositiveInfinity, 1.0, 2.5, 1.5, 1.0)] double dof,
[Values(Double.NaN, Double.NaN, 1.7320508075688772935274463415059, Double.NaN, Double.PositiveInfinity, 22.360679774997896964091736687313, 10.0, Double.NaN, 2.2360679774997896964091736687313, Double.PositiveInfinity, Double.NaN)] double sdev)
[TestCase(0.0, 1.0, 1.0, Double.NaN)]
[TestCase(0.0, 0.1, 1.0, Double.NaN)]
[TestCase(0.0, 1.0, 3.0, 1.7320508075688772935274463415059)]
[TestCase(0.0, 10.0, 1.0, Double.NaN)]
[TestCase(0.0, 10.0, 2.0, Double.PositiveInfinity)]
[TestCase(0.0, 10.0, 2.5, 22.360679774997896964091736687313)]
[TestCase(0.0, 10.0, Double.PositiveInfinity, 10.0)]
[TestCase(10.0, 1.0, 1.0, Double.NaN)]
[TestCase(10.0, 1.0, 2.5, 2.2360679774997896964091736687313)]
[TestCase(-5.0, 100.0, 1.5, Double.PositiveInfinity)]
[TestCase(0.0, Double.PositiveInfinity, 1.0, Double.NaN)]
public void ValidateStdDev(double location, double scale, double dof, double sdev)
{
var n = new StudentT(location, scale, dof);
Assert.AreEqual(sdev, n.StdDev);
@ -219,11 +255,18 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="dof">Degrees of freedom.</param>
[Test, Sequential]
public void ValidateMode(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 10.0, -5.0, 0.0)] double location,
[Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 10.0, 1.0, 1.0, 100.0, Double.PositiveInfinity)] double scale,
[Values(1.0, 1.0, 3.0, 1.0, 2.0, 2.5, Double.PositiveInfinity, 1.0, 2.5, 1.5, 1.0)] double dof)
[TestCase(0.0, 1.0, 1.0)]
[TestCase(0.0, 0.1, 1.0)]
[TestCase(0.0, 1.0, 3.0)]
[TestCase(0.0, 10.0, 1.0)]
[TestCase(0.0, 10.0, 2.0)]
[TestCase(0.0, 10.0, 2.5)]
[TestCase(0.0, 10.0, Double.PositiveInfinity)]
[TestCase(10.0, 1.0, 1.0)]
[TestCase(10.0, 1.0, 2.5)]
[TestCase(-5.0, 100.0, 1.5)]
[TestCase(0.0, Double.PositiveInfinity, 1.0)]
public void ValidateMode(double location, double scale, double dof)
{
var n = new StudentT(location, scale, dof);
Assert.AreEqual(location, n.Mode);
@ -235,11 +278,18 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="location">Location value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="dof">Degrees of freedom.</param>
[Test, Sequential]
public void ValidateMedian(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 10.0, -5.0, 0.0)] double location,
[Values(1.0, 0.1, 1.0, 10.0, 10.0, 10.0, 10.0, 1.0, 1.0, 100.0, Double.PositiveInfinity)] double scale,
[Values(1.0, 1.0, 3.0, 1.0, 2.0, 2.5, Double.PositiveInfinity, 1.0, 2.5, 1.5, 1.0)] double dof)
[TestCase(0.0, 1.0, 1.0)]
[TestCase(0.0, 0.1, 1.0)]
[TestCase(0.0, 1.0, 3.0)]
[TestCase(0.0, 10.0, 1.0)]
[TestCase(0.0, 10.0, 2.0)]
[TestCase(0.0, 10.0, 2.5)]
[TestCase(0.0, 10.0, Double.PositiveInfinity)]
[TestCase(10.0, 1.0, 1.0)]
[TestCase(10.0, 1.0, 2.5)]
[TestCase(-5.0, 100.0, 1.5)]
[TestCase(0.0, Double.PositiveInfinity, 1.0)]
public void ValidateMedian(double location, double scale, double dof)
{
var n = new StudentT(location, scale, dof);
Assert.AreEqual(location, n.Median);
@ -273,13 +323,20 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="dof">Degrees of freedom.</param>
/// <param name="x">Input X value.</param>
/// <param name="p">Expected value.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
[Values(0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, 2.0)] double x,
[Values(0.318309886183791, 0.159154943091895, 0.159154943091895, 0.063661977236758, 0.063661977236758, 0.353553390593274, 0.192450089729875, 0.192450089729875, 0.068041381743977, 0.068041381743977, 0.398942280401433, 0.241970724519143, 0.053990966513188)] double p)
[TestCase(0.0, 1.0, 1.0, 0.0, 0.318309886183791)]
[TestCase(0.0, 1.0, 1.0, 1.0, 0.159154943091895)]
[TestCase(0.0, 1.0, 1.0, -1.0, 0.159154943091895)]
[TestCase(0.0, 1.0, 1.0, 2.0, 0.063661977236758)]
[TestCase(0.0, 1.0, 1.0, -2.0, 0.063661977236758)]
[TestCase(0.0, 1.0, 2.0, 0.0, 0.353553390593274)]
[TestCase(0.0, 1.0, 2.0, 1.0, 0.192450089729875)]
[TestCase(0.0, 1.0, 2.0, -1.0, 0.192450089729875)]
[TestCase(0.0, 1.0, 2.0, 2.0, 0.068041381743977)]
[TestCase(0.0, 1.0, 2.0, -2.0, 0.068041381743977)]
[TestCase(0.0, 1.0, Double.PositiveInfinity, 0.0, 0.398942280401433)]
[TestCase(0.0, 1.0, Double.PositiveInfinity, 1.0, 0.241970724519143)]
[TestCase(0.0, 1.0, Double.PositiveInfinity, 2.0, 0.053990966513188)]
public void ValidateDensity(double location, double scale, double dof, double x, double p)
{
var n = new StudentT(location, scale, dof);
AssertHelpers.AlmostEqual(p, n.Density(x), 13);
@ -293,13 +350,20 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="dof">Degrees of freedom.</param>
/// <param name="x">Input X value.</param>
/// <param name="p">Expected value.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
[Values(0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, 2.0)] double x,
[Values(-1.144729885849399, -1.837877066409348, -1.837877066409348, -2.754167798283503, -2.754167798283503, -1.039720770839917, -1.647918433002166, -1.647918433002166, -2.687639203842085, -2.687639203842085, -0.918938533204672, -1.418938533204674, -2.918938533204674)] double p)
[TestCase(0.0, 1.0, 1.0, 0.0, -1.144729885849399)]
[TestCase(0.0, 1.0, 1.0, 1.0, -1.837877066409348)]
[TestCase(0.0, 1.0, 1.0, -1.0, -1.837877066409348)]
[TestCase(0.0, 1.0, 1.0, 2.0, -2.754167798283503)]
[TestCase(0.0, 1.0, 1.0, -2.0, -2.754167798283503)]
[TestCase(0.0, 1.0, 2.0, 0.0, -1.039720770839917)]
[TestCase(0.0, 1.0, 2.0, 1.0, -1.647918433002166)]
[TestCase(0.0, 1.0, 2.0, -1.0, -1.647918433002166)]
[TestCase(0.0, 1.0, 2.0, 2.0, -2.687639203842085)]
[TestCase(0.0, 1.0, 2.0, -2.0, -2.687639203842085)]
[TestCase(0.0, 1.0, Double.PositiveInfinity, 0.0, -0.918938533204672)]
[TestCase(0.0, 1.0, Double.PositiveInfinity, 1.0, -1.418938533204674)]
[TestCase(0.0, 1.0, Double.PositiveInfinity, 2.0, -2.918938533204674)]
public void ValidateDensityLn(double location, double scale, double dof, double x, double p)
{
var n = new StudentT(location, scale, dof);
AssertHelpers.AlmostEqual(p, n.DensityLn(x), 13);
@ -372,13 +436,20 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="dof">Degrees of freedom.</param>
/// <param name="x">Input X value.</param>
/// <param name="c">Expected value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)] double location,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)] double scale,
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0, 2.0, Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity)] double dof,
[Values(0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, -1.0, 2.0, -2.0, 0.0, 1.0, 2.0)] double x,
[Values(0.5, 0.75, 0.25, 0.852416382349567, 0.147583617650433, 0.5, 0.788675134594813, 0.211324865405187, 0.908248290463863, 0.091751709536137, 0.5, 0.841344746068543, 0.977249868051821)] double c)
[TestCase(0.0, 1.0, 1.0, 0.0, 0.5)]
[TestCase(0.0, 1.0, 1.0, 1.0, 0.75)]
[TestCase(0.0, 1.0, 1.0, -1.0, 0.25)]
[TestCase(0.0, 1.0, 1.0, 2.0, 0.852416382349567)]
[TestCase(0.0, 1.0, 1.0, -2.0, 0.147583617650433)]
[TestCase(0.0, 1.0, 2.0, 0.0, 0.5)]
[TestCase(0.0, 1.0, 2.0, 1.0, 0.788675134594813)]
[TestCase(0.0, 1.0, 2.0, -1.0, 0.211324865405187)]
[TestCase(0.0, 1.0, 2.0, 2.0, 0.908248290463863)]
[TestCase(0.0, 1.0, 2.0, -2.0, 0.091751709536137)]
[TestCase(0.0, 1.0, Double.PositiveInfinity, 0.0, 0.5)]
[TestCase(0.0, 1.0, Double.PositiveInfinity, 1.0, 0.841344746068543)]
[TestCase(0.0, 1.0, Double.PositiveInfinity, 2.0, 0.977249868051821)]
public void ValidateCumulativeDistribution(double location, double scale, double dof, double x, double c)
{
var n = new StudentT(location, scale, dof);
AssertHelpers.AlmostEqual(c, n.CumulativeDistribution(x), 13);

164
src/UnitTests/DistributionTests/Continuous/WeibullTests.cs

@ -1,4 +1,4 @@
// <copyright file="WeibullTests.cs" company="Math.NET">
// <copyright file="WeibullTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="shape">Shape value.</param>
/// <param name="scale">Scale value.</param>
[Test, Combinatorial]
public void CanCreateWeibull([Values(1.0, 10.0)] double shape, [Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(1.0, 0.1)]
[TestCase(10.0, 1.0)]
[TestCase(11.0, 10.0)]
[TestCase(12.0, Double.PositiveInfinity)]
public void CanCreateWeibull(double shape, double scale)
{
var n = new Weibull(shape, scale);
Assert.AreEqual(shape, n.Shape);
@ -64,8 +67,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// </summary>
/// <param name="shape">Shape value.</param>
/// <param name="scale">Scale value.</param>
[Test, Sequential]
public void WeibullCreateFailsWithBadParameters([Values(Double.NaN, 1.0, Double.NaN, 1.0, -1.0, -1.0, 0.0, 0.0, 1.0)] double shape, [Values(1.0, Double.NaN, Double.NaN, -1.0, 1.0, -1.0, 0.0, 1.0, 0.0)] double scale)
[TestCase(Double.NaN, 1.0)]
[TestCase(1.0, Double.NaN)]
[TestCase(Double.NaN, Double.NaN)]
[TestCase(1.0, -1.0)]
[TestCase(-1.0, 1.0)]
[TestCase(-1.0, -1.0)]
[TestCase(0.0, 0.0)]
[TestCase(0.0, 1.0)]
[TestCase(1.0, 0.0)]
public void WeibullCreateFailsWithBadParameters(double shape, double scale)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Weibull(shape, scale));
}
@ -84,8 +95,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set shape.
/// </summary>
/// <param name="shape">Shape value.</param>
[Test]
public void CanSetShape([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double shape)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetShape(double shape)
{
new Weibull(1.0, 1.0)
{
@ -97,8 +111,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set shape fails with negative shape.
/// </summary>
/// <param name="shape">Shape value.</param>
[Test]
public void SetShapeFailsWithNegativeShape([Values(-1.0, -0.0, 0.0)] double shape)
[TestCase(-1.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
public void SetShapeFailsWithNegativeShape(double shape)
{
var n = new Weibull(1.0, 1.0);
Assert.Throws<ArgumentOutOfRangeException>(() => n.Shape = shape);
@ -108,8 +124,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Can set scale.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void CanSetScale([Values(0.1, 1.0, 10.0, Double.PositiveInfinity)] double scale)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetScale(double scale)
{
new Weibull(1.0, 1.0)
{
@ -121,8 +140,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// Set scale fails with negative scale.
/// </summary>
/// <param name="scale">Scale value.</param>
[Test]
public void SetScaleFailsWithNegativeScale([Values(-1.0, -0.0, 0.0)] double scale)
[TestCase(-1.0)]
[TestCase(-0.0)]
[TestCase(0.0)]
public void SetScaleFailsWithNegativeScale(double scale)
{
var n = new Weibull(1.0, 1.0);
Assert.Throws<ArgumentOutOfRangeException>(() => n.Scale = scale);
@ -134,11 +155,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="mean">Expected value.</param>
[Test, Sequential]
public void ValidateMean(
[Values(1.0, 1.0, 10.0, 10.0)] double shape,
[Values(0.1, 1.0, 10.0, 1.0)] double scale,
[Values(0.1, 1.0, 9.5135076986687318362924871772654021925505786260884, 0.95135076986687318362924871772654021925505786260884)] double mean)
[TestCase(1.0, 0.1, 0.1)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(10.0, 10.0, 9.5135076986687318362924871772654021925505786260884)]
[TestCase(10.0, 1.0, 0.95135076986687318362924871772654021925505786260884)]
public void ValidateMean(double shape, double scale, double mean)
{
var n = new Weibull(shape, scale);
AssertHelpers.AlmostEqual(mean, n.Mean, 13);
@ -150,11 +171,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="var">Expected value.</param>
[Test, Sequential]
public void ValidateVariance(
[Values(1.0, 1.0, 10.0, 10.0)] double shape,
[Values(0.1, 1.0, 10.0, 1.0)] double scale,
[Values(0.01, 1.0, 1.3100455073468309147154581687505295026863354547057, 0.013100455073468309147154581687505295026863354547057)] double var)
[TestCase(1.0, 0.1, 0.01)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(10.0, 10.0, 1.3100455073468309147154581687505295026863354547057)]
[TestCase(10.0, 1.0, 0.013100455073468309147154581687505295026863354547057)]
public void ValidateVariance(double shape, double scale, double var)
{
var n = new Weibull(shape, scale);
AssertHelpers.AlmostEqual(var, n.Variance, 13);
@ -166,11 +187,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="sdev">Expected value.</param>
[Test, Sequential]
public void ValidateStdDev(
[Values(1.0, 1.0, 10.0, 10.0)] double shape,
[Values(0.1, 1.0, 10.0, 1.0)] double scale,
[Values(0.1, 1.0, 1.1445721940300799194124723631014002560036613065794, 0.11445721940300799194124723631014002560036613065794)] double sdev)
[TestCase(1.0, 0.1, 0.1)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(10.0, 10.0, 1.1445721940300799194124723631014002560036613065794)]
[TestCase(10.0, 1.0, 0.11445721940300799194124723631014002560036613065794)]
public void ValidateStdDev(double shape, double scale, double sdev)
{
var n = new Weibull(shape, scale);
AssertHelpers.AlmostEqual(sdev, n.StdDev, 13);
@ -182,11 +203,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="skewness">Expected value.</param>
[Test, Sequential]
public void ValidateSkewness(
[Values(1.0, 1.0, 10.0, 10.0)] double shape,
[Values(0.1, 1.0, 10.0, 1.0)] double scale,
[Values(2.0, 2.0, -0.63763713390314440916597757156663888653981696212127, -0.63763713390314440916597757156663888653981696212127)] double skewness)
[TestCase(1.0, 0.1, 2.0)]
[TestCase(1.0, 1.0, 2.0)]
[TestCase(10.0, 10.0, -0.63763713390314440916597757156663888653981696212127)]
[TestCase(10.0, 1.0, -0.63763713390314440916597757156663888653981696212127)]
public void ValidateSkewness(double shape, double scale, double skewness)
{
var n = new Weibull(shape, scale);
AssertHelpers.AlmostEqual(skewness, n.Skewness, 11);
@ -198,11 +219,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="mode">Expected value.</param>
[Test, Sequential]
public void ValidateMode(
[Values(1.0, 1.0, 10.0, 10.0)] double shape,
[Values(0.1, 1.0, 10.0, 1.0)] double scale,
[Values(0.0, 0.0, 9.8951925820621439264623017041980483215553841533709, 0.98951925820621439264623017041980483215553841533709)] double mode)
[TestCase(1.0, 0.1, 0.0)]
[TestCase(1.0, 1.0, 0.0)]
[TestCase(10.0, 10.0, 9.8951925820621439264623017041980483215553841533709)]
[TestCase(10.0, 1.0, 0.98951925820621439264623017041980483215553841533709)]
public void ValidateMode(double shape, double scale, double mode)
{
var n = new Weibull(shape, scale);
Assert.AreEqual(mode, n.Mode);
@ -214,11 +235,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="shape">Shape value.</param>
/// <param name="scale">Scale value.</param>
/// <param name="median">Expected value.</param>
[Test, Sequential]
public void ValidateMedian(
[Values(1.0, 1.0, 10.0, 10.0)] double shape,
[Values(0.1, 1.0, 10.0, 1.0)] double scale,
[Values(0.069314718055994530941723212145817656807550013436026, 0.69314718055994530941723212145817656807550013436026, 9.6401223546778973665856033763604752124634905617583, 0.96401223546778973665856033763604752124634905617583)] double median)
[TestCase(1.0, 0.1, 0.069314718055994530941723212145817656807550013436026)]
[TestCase(1.0, 1.0, 0.69314718055994530941723212145817656807550013436026)]
[TestCase(10.0, 10.0, 9.6401223546778973665856033763604752124634905617583)]
[TestCase(10.0, 1.0, 0.96401223546778973665856033763604752124634905617583)]
public void ValidateMedian(double shape, double scale, double median)
{
var n = new Weibull(shape, scale);
AssertHelpers.AlmostEqual(median, n.Median, 13);
@ -251,12 +272,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="scale">Scale value.</param>
/// <param name="x">Input X value.</param>
/// <param name="pdf">Expected value.</param>
[Test, Sequential]
public void ValidateDensity(
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0)] double shape,
[Values(0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0)] double scale,
[Values(0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0)] double x,
[Values(10.0, 0.00045399929762484851535591515560550610237918088866565, 3.7200759760208359629596958038631183373588922923768e-43, 1.0, 0.36787944117144232159552377016146086744581113103177, 0.000045399929762484851535591515560550610237918088866565, 0.0, 9.9999999990000000000499999999983333333333750000000e-10, 0.36787944117144232159552377016146086744581113103177, 0.0, 3.6787944117144232159552377016146086744581113103177, 0.0)] double pdf)
[TestCase(1.0, 0.1, 0.0, 10.0)]
[TestCase(1.0, 0.1, 1.0, 0.00045399929762484851535591515560550610237918088866565)]
[TestCase(1.0, 0.1, 10.0, 3.7200759760208359629596958038631183373588922923768e-43)]
[TestCase(1.0, 1.0, 0.0, 1.0)]
[TestCase(1.0, 1.0, 1.0, 0.36787944117144232159552377016146086744581113103177)]
[TestCase(1.0, 1.0, 10.0, 0.000045399929762484851535591515560550610237918088866565)]
[TestCase(10.0, 10.0, 0.0, 0.0)]
[TestCase(10.0, 10.0, 1.0, 9.9999999990000000000499999999983333333333750000000e-10)]
[TestCase(10.0, 10.0, 10.0, 0.36787944117144232159552377016146086744581113103177)]
[TestCase(10.0, 1.0, 0.0, 0.0)]
[TestCase(10.0, 1.0, 1.0, 3.6787944117144232159552377016146086744581113103177)]
[TestCase(10.0, 1.0, 10.0, 0.0)]
public void ValidateDensity(double shape, double scale, double x, double pdf)
{
var n = new Weibull(shape, scale);
AssertHelpers.AlmostEqual(pdf, n.Density(x), 14);
@ -269,12 +297,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="scale">Scale value.</param>
/// <param name="x">Input X value.</param>
/// <param name="pdfln">Expected value.</param>
[Test, Sequential]
public void ValidateDensityLn(
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0)] double shape,
[Values(0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0)] double scale,
[Values(0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0)] double x,
[Values(2.3025850929940456840179914546843642076011014886288, -7.6974149070059543159820085453156357923988985113712, -97.697414907005954315982008545315635792398898511371, 0.0, -1.0, -10.0, Double.NegativeInfinity, -20.723265837046411156161923092159277868409913397659, -1.0, Double.NegativeInfinity, 1.3025850929940456840179914546843642076011014886288, -9.999999976974149070059543159820085453156357923988985113712e9)] double pdfln)
[TestCase(1.0, 0.1, 0.0, 2.3025850929940456840179914546843642076011014886288)]
[TestCase(1.0, 0.1, 1.0, -7.6974149070059543159820085453156357923988985113712)]
[TestCase(1.0, 0.1, 10.0, -97.697414907005954315982008545315635792398898511371)]
[TestCase(1.0, 1.0, 0.0, 0.0)]
[TestCase(1.0, 1.0, 1.0, -1.0)]
[TestCase(1.0, 1.0, 10.0, -10.0)]
[TestCase(10.0, 10.0, 0.0, Double.NegativeInfinity)]
[TestCase(10.0, 10.0, 1.0, -20.723265837046411156161923092159277868409913397659)]
[TestCase(10.0, 10.0, 10.0, -1.0)]
[TestCase(10.0, 1.0, 0.0, Double.NegativeInfinity)]
[TestCase(10.0, 1.0, 1.0, 1.3025850929940456840179914546843642076011014886288)]
[TestCase(10.0, 1.0, 10.0, -9.999999976974149070059543159820085453156357923988985113712e9)]
public void ValidateDensityLn(double shape, double scale, double x, double pdfln)
{
var n = new Weibull(shape, scale);
AssertHelpers.AlmostEqual(pdfln, n.DensityLn(x), 14);
@ -345,12 +380,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Continuous
/// <param name="scale">Scale value.</param>
/// <param name="x">Input X value.</param>
/// <param name="cdf">Expected value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0)] double shape,
[Values(0.1, 0.1, 0.1, 1.0, 1.0, 1.0, 10.0, 10.0, 10.0, 1.0, 1.0, 1.0)] double scale,
[Values(0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0, 0.0, 1.0, 10.0)] double x,
[Values(0.0, 0.99995460007023751514846440848443944938976208191113, 0.99999999999999999999999999999999999999999996279924, 0.0, 0.63212055882855767840447622983853913255418886896823, 0.99995460007023751514846440848443944938976208191113, 0.0, 9.9999999995000000000166666666662500000000083333333e-11, 0.63212055882855767840447622983853913255418886896823, 0.0, 0.63212055882855767840447622983853913255418886896823, 1.0)] double cdf)
[TestCase(1.0, 0.1, 0.0, 0.0)]
[TestCase(1.0, 0.1, 1.0, 0.99995460007023751514846440848443944938976208191113)]
[TestCase(1.0, 0.1, 10.0, 0.99999999999999999999999999999999999999999996279924)]
[TestCase(1.0, 1.0, 0.0, 0.0)]
[TestCase(1.0, 1.0, 1.0, 0.63212055882855767840447622983853913255418886896823)]
[TestCase(1.0, 1.0, 10.0, 0.99995460007023751514846440848443944938976208191113)]
[TestCase(10.0, 10.0, 0.0, 0.0)]
[TestCase(10.0, 10.0, 1.0, 9.9999999995000000000166666666662500000000083333333e-11)]
[TestCase(10.0, 10.0, 10.0, 0.63212055882855767840447622983853913255418886896823)]
[TestCase(10.0, 1.0, 0.0, 0.0)]
[TestCase(10.0, 1.0, 1.0, 0.63212055882855767840447622983853913255418886896823)]
[TestCase(10.0, 1.0, 10.0, 1.0)]
public void ValidateCumulativeDistribution(double shape, double scale, double x, double cdf)
{
var n = new Weibull(shape, scale);
AssertHelpers.AlmostEqual(cdf, n.CumulativeDistribution(x), 15);

99
src/UnitTests/DistributionTests/Discrete/BernoulliTests.cs

@ -50,8 +50,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can create Bernoulli.
/// </summary>
/// <param name="p">Probability of one.</param>
[Test]
public void CanCreateBernoulli([Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0)]
[TestCase(0.3)]
[TestCase(1.0)]
public void CanCreateBernoulli(double p)
{
var bernoulli = new Bernoulli(p);
Assert.AreEqual(p, bernoulli.P);
@ -61,8 +63,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Bernoulli create fails with bad parameters.
/// </summary>
/// <param name="p">Probability of one.</param>
[Test]
public void BernoulliCreateFailsWithBadParameters([Values(Double.NaN, -1.0, 2.0)] double p)
[TestCase(Double.NaN)]
[TestCase(-1.0)]
[TestCase(2.0)]
public void BernoulliCreateFailsWithBadParameters(double p)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Bernoulli(p));
}
@ -81,8 +85,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set probability of one.
/// </summary>
/// <param name="p">Probability of one.</param>
[Test]
public void CanSetProbabilityOfOne([Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0)]
[TestCase(0.3)]
[TestCase(1.0)]
public void CanSetProbabilityOfOne(double p)
{
new Bernoulli(0.3)
{
@ -94,8 +100,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set probability of one fails with bad values.
/// </summary>
/// <param name="p">Probability of one.</param>
[Test]
public void SetProbabilityOfOneFails([Values(Double.NaN, -1.0, 2.0)] double p)
[TestCase(Double.NaN)]
[TestCase(-1.0)]
[TestCase(2.0)]
public void SetProbabilityOfOneFails(double p)
{
var b = new Bernoulli(0.3);
Assert.Throws<ArgumentOutOfRangeException>(() => b.P = p);
@ -105,8 +113,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Validate entropy.
/// </summary>
/// <param name="p">Probability of one.</param>
[Test]
public void ValidateEntropy([Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0)]
[TestCase(0.3)]
[TestCase(1.0)]
public void ValidateEntropy(double p)
{
var b = new Bernoulli(p);
AssertHelpers.AlmostEqual(-((1.0 - p) * Math.Log(1.0 - p)) - (p * Math.Log(p)), b.Entropy, 14);
@ -116,8 +126,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Validate skewness.
/// </summary>
/// <param name="p">Probability of one.</param>
[Test]
public void ValidateSkewness([Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0)]
[TestCase(0.3)]
[TestCase(1.0)]
public void ValidateSkewness(double p)
{
var b = new Bernoulli(p);
Assert.AreEqual((1.0 - (2.0 * p)) / Math.Sqrt(p * (1.0 - p)), b.Skewness);
@ -128,8 +140,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="p">Probability of one.</param>
/// <param name="m">Expected value.</param>
[Test, Sequential]
public void ValidateMode([Values(0.0, 0.3, 1.0)] double p, [Values(0.0, 0.0, 1.0)] double m)
[TestCase(0.0, 0.0)]
[TestCase(0.3, 0.0)]
[TestCase(1.0, 1.0)]
public void ValidateMode(double p, double m)
{
var b = new Bernoulli(p);
Assert.AreEqual(m, b.Mode);
@ -171,11 +185,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="p">Probability of one.</param>
/// <param name="x">Input X value.</param>
/// <param name="d">Expected value.</param>
[Test, Sequential]
public void ValidateProbability(
[Values(0.0, 0.0, 0.0, 0.0, 0.3, 0.3, 0.3, 0.3, 1.0, 1.0, 1.0, 1.0)] double p,
[Values(-1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2)] int x,
[Values(0.0, 1.0, 0.0, 0.0, 0.0, 0.7, 0.3, 0.0, 0.0, 0.0, 1.0, 0.0)] double d)
[TestCase(0.0, -1, 0.0)]
[TestCase(0.0, 0, 1.0)]
[TestCase(0.0, 1, 0.0)]
[TestCase(0.0, 2, 0.0)]
[TestCase(0.3, -1, 0.0)]
[TestCase(0.3, 0, 0.7)]
[TestCase(0.3, 1, 0.3)]
[TestCase(0.3, 2, 0.0)]
[TestCase(1.0, -1, 0.0)]
[TestCase(1.0, 0, 0.0)]
[TestCase(1.0, 1, 1.0)]
[TestCase(1.0, 2, 0.0)]
public void ValidateProbability(double p, int x, double d)
{
var b = new Bernoulli(p);
Assert.AreEqual(d, b.Probability(x));
@ -187,11 +209,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="p">Probability of one.</param>
/// <param name="x">Input X value.</param>
/// <param name="dln">Expected value.</param>
[Test, Sequential]
public void ValidateProbabilityLn(
[Values(0.0, 0.0, 0.0, 0.0, 0.3, 0.3, 0.3, 0.3, 1.0, 1.0, 1.0, 1.0)] double p,
[Values(-1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2)] int x,
[Values(Double.NegativeInfinity, 0.0, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, -0.35667494393873244235395440410727451457180907089949815, -1.2039728043259360296301803719337238685164245381839102, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, 0.0, Double.NegativeInfinity)] double dln)
[TestCase(0.0, -1, Double.NegativeInfinity)]
[TestCase(0.0, 0, 0.0)]
[TestCase(0.0, 1, Double.NegativeInfinity)]
[TestCase(0.0, 2, Double.NegativeInfinity)]
[TestCase(0.3, -1, Double.NegativeInfinity)]
[TestCase(0.3, 0, -0.35667494393873244235395440410727451457180907089949815)]
[TestCase(0.3, 1, -1.2039728043259360296301803719337238685164245381839102)]
[TestCase(0.3, 2, Double.NegativeInfinity)]
[TestCase(1.0, -1, Double.NegativeInfinity)]
[TestCase(1.0, 0, Double.NegativeInfinity)]
[TestCase(1.0, 1, 0.0)]
[TestCase(1.0, 2, Double.NegativeInfinity)]
public void ValidateProbabilityLn(double p, int x, double dln)
{
var b = new Bernoulli(p);
Assert.AreEqual(dln, b.ProbabilityLn(x));
@ -261,11 +291,22 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="p">Probability of one.</param>
/// <param name="x">Input X value.</param>
/// <param name="cdf">Expected value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.3, 0.3, 0.3, 0.3, 1.0, 1.0, 1.0, 1.0, 1.0)] double p,
[Values(-1.0, 0.0, 0.5, 1.0, 2.0, -1.0, 0.0, 0.5, 1.0, 2.0, -1.0, 0.0, 0.5, 1.0, 2.0)] double x,
[Values(0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.7, 0.7, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0)] double cdf)
[TestCase(0.0, -1.0, 0.0)]
[TestCase(0.0, 0.0, 1.0)]
[TestCase(0.0, 0.5, 1.0)]
[TestCase(0.0, 1.0, 1.0)]
[TestCase(0.0, 2.0, 1.0)]
[TestCase(0.3, -1.0, 0.0)]
[TestCase(0.3, 0.0, 0.7)]
[TestCase(0.3, 0.5, 0.7)]
[TestCase(0.3, 1.0, 1.0)]
[TestCase(0.3, 2.0, 1.0)]
[TestCase(1.0, -1.0, 0.0)]
[TestCase(1.0, 0.0, 0.0)]
[TestCase(1.0, 0.5, 0.0)]
[TestCase(1.0, 1.0, 1.0)]
[TestCase(1.0, 2.0, 1.0)]
public void ValidateCumulativeDistribution(double p, double x, double cdf)
{
var b = new Bernoulli(p);
Assert.AreEqual(cdf, b.CumulativeDistribution(x));

105
src/UnitTests/DistributionTests/Discrete/BinomialTests.cs

@ -51,8 +51,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="p">Success probability.</param>
/// <param name="n">Number of trials.</param>
[Test, Sequential]
public void CanCreateBinomial([Values(0.0, 0.3, 1.0)] double p, [Values(4, 3, 2)] int n)
[TestCase(0.0, 4)]
[TestCase(0.3, 3)]
[TestCase(1.0, 2)]
public void CanCreateBinomial(double p, int n)
{
var bernoulli = new Binomial(p, n);
Assert.AreEqual(p, bernoulli.P);
@ -63,8 +65,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="p">Success probability.</param>
/// <param name="n">Number of trials.</param>
[Test, Sequential]
public void BinomialCreateFailsWithBadParameters([Values(Double.NaN, -1.0, 2.0, 0.3)] double p, [Values(1, 1, 1, -2)] int n)
[TestCase(Double.NaN, 1)]
[TestCase(-1.0, 1)]
[TestCase(2.0, 1)]
[TestCase(0.3, -2)]
public void BinomialCreateFailsWithBadParameters(double p, int n)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Binomial(p, n));
}
@ -84,8 +89,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="p">Success probability.</param>
/// <param name="n">Number of trials.</param>
[Test, Sequential]
public void CanSetSuccessProbability([Values(0.0, 0.3, 1.0)] double p, [Values(4, 3, 2)] int n)
[TestCase(0.0, 4)]
[TestCase(0.3, 3)]
[TestCase(1.0, 2)]
public void CanSetSuccessProbability(double p, int n)
{
new Binomial(0.3, n)
{
@ -97,8 +104,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set success probability fails with bad values.
/// </summary>
/// <param name="p">Success probability.</param>
[Test]
public void SetProbabilityOfOneFails([Values(Double.NaN, -1.0, 2.0)] double p)
[TestCase(Double.NaN)]
[TestCase(-1.0)]
[TestCase(2.0)]
public void SetProbabilityOfOneFails(double p)
{
var b = new Binomial(0.3, 1);
Assert.Throws<ArgumentOutOfRangeException>(() => b.P = p);
@ -110,8 +119,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="p">Success probability.</param>
/// <param name="n">Number of trials.</param>
/// <param name="e">Expected value.</param>
[Test, Sequential]
public void ValidateEntropy([Values(0.0, 0.3, 1.0)] double p, [Values(4, 3, 2)] int n, [Values(0.0, 1.1404671643037712668976423399228972051669206536461, 0.0)] double e)
[TestCase(0.0, 4, 0.0)]
[TestCase(0.3, 3, 1.1404671643037712668976423399228972051669206536461)]
[TestCase(1.0, 2, 0.0)]
public void ValidateEntropy(double p, int n, double e)
{
var b = new Binomial(p, n);
AssertHelpers.AlmostEqual(e, b.Entropy, 14);
@ -122,8 +133,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="p">Success probability.</param>
/// <param name="n">Number of trials.</param>
[Test, Sequential]
public void ValidateSkewness([Values(0.0, 0.3, 1.0)] double p, [Values(4, 3, 2)] int n)
[TestCase(0.0, 4)]
[TestCase(0.3, 3)]
[TestCase(1.0, 2)]
public void ValidateSkewness(double p, int n)
{
var b = new Binomial(p, n);
Assert.AreEqual((1.0 - (2.0 * p)) / Math.Sqrt(n * p * (1.0 - p)), b.Skewness);
@ -135,8 +148,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="p">Success probability.</param>
/// <param name="n">Number of trials.</param>
/// <param name="m">Expected value.</param>
[Test, Sequential]
public void ValidateMode([Values(0.0, 0.3, 1.0)] double p, [Values(4, 3, 2)] int n, [Values(0, 1, 2)] int m)
[TestCase(0.0, 4, 0)]
[TestCase(0.3, 3, 1)]
[TestCase(1.0, 2, 2)]
public void ValidateMode(double p, int n, int m)
{
var b = new Binomial(p, n);
Assert.AreEqual(m, b.Mode);
@ -169,12 +184,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="n">Number of trials.</param>
/// <param name="x">Input X value.</param>
/// <param name="d">Expected value.</param>
[Test, Sequential]
public void ValidateProbability(
[Values(0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.300000, 0.300000, 0.300000, 0.300000, 0.300000, 0.300000, 0.300000, 0.300000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000)] double p,
[Values(1, 1, 3, 3, 3, 10, 10, 10, 1, 1, 3, 3, 3, 10, 10, 10, 1, 1, 3, 3, 3, 10, 10, 10)] int n,
[Values(0, 1, 0, 1, 3, 0, 1, 10, 0, 1, 0, 1, 3, 0, 1, 10, 0, 1, 0, 1, 3, 0, 1, 10)] int x,
[Values(1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.69999999999999995559107901499373838305473327636719, 0.2999999999999999888977697537484345957636833190918, 0.34299999999999993471888615204079956461021032657166, 0.44099999999999992772448109690231306411849135972008, 0.026999999999999997002397833512077451789759292859569, 0.02824752489999998207939855277004937778546385011091, 0.12106082099999992639752977030555903089040470780077, 0.0000059048999999999978147480206303047454017251032868501, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0)] double d)
[TestCase(0.000000, 1, 0, 1.0)]
[TestCase(0.000000, 1, 1, 0.0)]
[TestCase(0.000000, 3, 0, 1.0)]
[TestCase(0.000000, 3, 1, 0.0)]
[TestCase(0.000000, 3, 3, 0.0)]
[TestCase(0.000000, 10, 0, 1.0)]
[TestCase(0.000000, 10, 1, 0.0)]
[TestCase(0.000000, 10, 10, 0.0)]
[TestCase(0.300000, 1, 0, 0.69999999999999995559107901499373838305473327636719)]
[TestCase(0.300000, 1, 1, 0.2999999999999999888977697537484345957636833190918)]
[TestCase(0.300000, 3, 0, 0.34299999999999993471888615204079956461021032657166)]
[TestCase(0.300000, 3, 1, 0.44099999999999992772448109690231306411849135972008)]
[TestCase(0.300000, 3, 3, 0.026999999999999997002397833512077451789759292859569)]
[TestCase(0.300000, 10, 0, 0.02824752489999998207939855277004937778546385011091)]
[TestCase(0.300000, 10, 1, 0.12106082099999992639752977030555903089040470780077)]
[TestCase(0.300000, 10, 10, 0.0000059048999999999978147480206303047454017251032868501)]
[TestCase(1.000000, 1, 0, 0.0)]
[TestCase(1.000000, 1, 1, 1.0)]
[TestCase(1.000000, 3, 0, 0.0)]
[TestCase(1.000000, 3, 1, 0.0)]
[TestCase(1.000000, 3, 3, 1.0)]
[TestCase(1.000000, 10, 0, 0.0)]
[TestCase(1.000000, 10, 1, 0.0)]
[TestCase(1.000000, 10, 10, 1.0)]
public void ValidateProbability(double p, int n, int x, double d)
{
var b = new Binomial(p, n);
AssertHelpers.AlmostEqual(d, b.Probability(x), 14);
@ -187,12 +221,31 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="n">Number of trials.</param>
/// <param name="x">Input X value.</param>
/// <param name="dln">Expected value.</param>
[Test, Sequential]
public void ValidateProbabilityLn(
[Values(0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.300000, 0.300000, 0.300000, 0.300000, 0.300000, 0.300000, 0.300000, 0.300000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000)] double p,
[Values(1, 1, 3, 3, 3, 10, 10, 10, 1, 1, 3, 3, 3, 10, 10, 10, 1, 1, 3, 3, 3, 10, 10, 10)] int n,
[Values(0, 1, 0, 1, 3, 0, 1, 10, 0, 1, 0, 1, 3, 0, 1, 10, 0, 1, 0, 1, 3, 0, 1, 10)] int x,
[Values(0.0, Double.NegativeInfinity, 0.0, Double.NegativeInfinity, Double.NegativeInfinity, 0.0, Double.NegativeInfinity, Double.NegativeInfinity, -0.3566749439387324423539544041072745145718090708995, -1.2039728043259360296301803719337238685164245381839, -1.0700248318161973270618632123218235437154272126985, -0.81871040353529122294284394322574719301255212216016, -3.6119184129778080888905411158011716055492736145517, -3.566749439387324423539544041072745145718090708995, -2.1114622067804823267977785542148302920616046876506, -12.039728043259360296301803719337238685164245381839, Double.NegativeInfinity, 0.0, Double.NegativeInfinity, Double.NegativeInfinity, 0.0, Double.NegativeInfinity, Double.NegativeInfinity, 0.0)] double dln)
[TestCase(0.000000, 1, 0, 0.0)]
[TestCase(0.000000, 1, 1, Double.NegativeInfinity)]
[TestCase(0.000000, 3, 0, 0.0)]
[TestCase(0.000000, 3, 1, Double.NegativeInfinity)]
[TestCase(0.000000, 3, 3, Double.NegativeInfinity)]
[TestCase(0.000000, 10, 0, 0.0)]
[TestCase(0.000000, 10, 1, Double.NegativeInfinity)]
[TestCase(0.000000, 10, 10, Double.NegativeInfinity)]
[TestCase(0.300000, 1, 0, -0.3566749439387324423539544041072745145718090708995)]
[TestCase(0.300000, 1, 1, -1.2039728043259360296301803719337238685164245381839)]
[TestCase(0.300000, 3, 0, -1.0700248318161973270618632123218235437154272126985)]
[TestCase(0.300000, 3, 1, -0.81871040353529122294284394322574719301255212216016)]
[TestCase(0.300000, 3, 3, -3.6119184129778080888905411158011716055492736145517)]
[TestCase(0.300000, 10, 0, -3.566749439387324423539544041072745145718090708995)]
[TestCase(0.300000, 10, 1, -2.1114622067804823267977785542148302920616046876506)]
[TestCase(0.300000, 10, 10, -12.039728043259360296301803719337238685164245381839)]
[TestCase(1.000000, 1, 0, Double.NegativeInfinity)]
[TestCase(1.000000, 1, 1, 0.0)]
[TestCase(1.000000, 3, 0, Double.NegativeInfinity)]
[TestCase(1.000000, 3, 1, Double.NegativeInfinity)]
[TestCase(1.000000, 3, 3, 0.0)]
[TestCase(1.000000, 10, 0, Double.NegativeInfinity)]
[TestCase(1.000000, 10, 1, Double.NegativeInfinity)]
[TestCase(1.000000, 10, 10, 0.0)]
public void ValidateProbabilityLn(double p, int n, int x, double dln)
{
var b = new Binomial(p, n);
AssertHelpers.AlmostEqual(dln, b.ProbabilityLn(x), 14);

89
src/UnitTests/DistributionTests/Discrete/ConwayMaxwellPoissonTests.cs

@ -1,4 +1,4 @@
// <copyright file="ConwayMaxwellPoissonTests.cs" company="Math.NET">
// <copyright file="ConwayMaxwellPoissonTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="lambda">Lambda value.</param>
/// <param name="nu">Nu parameter.</param>
[Test, Combinatorial]
public void CanCreateConwayMaxwellPoisson([Values(0.1, 1.0, 2.5, 10.0, Double.PositiveInfinity)] double lambda, [Values(0.0, 2.5, Double.PositiveInfinity)] double nu)
[TestCase(0.1, 0.0)]
[TestCase(1.0, 2.5)]
[TestCase(2.5, 3.0)]
[TestCase(10.0, 3.5)]
[TestCase(Double.PositiveInfinity, Double.PositiveInfinity)]
public void CanCreateConwayMaxwellPoisson(double lambda, double nu)
{
var d = new ConwayMaxwellPoisson(lambda, nu);
Assert.AreEqual(lambda, d.Lambda);
@ -82,8 +86,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set lambda.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void CanSetLambda([Values(0.1, 3.0, 10.0, Double.PositiveInfinity)] double lambda)
[TestCase(0.1)]
[TestCase(3.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetLambda(double lambda)
{
new ConwayMaxwellPoisson(1.0, 2.0)
{
@ -95,8 +102,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set Nu.
/// </summary>
/// <param name="nu">Nu parameter.</param>
[Test]
public void CanSetNu([Values(0.0, 3.0, 10.0, Double.PositiveInfinity)] double nu)
[TestCase(0.0)]
[TestCase(3.0)]
[TestCase(10.0)]
[TestCase(Double.PositiveInfinity)]
public void CanSetNu(double nu)
{
new ConwayMaxwellPoisson(1.0, 2.0)
{
@ -108,8 +118,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set lambda with bad values fails.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void SetLambdaFails([Values(0.0, -0.0, -1.0, Double.NegativeInfinity)] double lambda)
[TestCase(0.0)]
[TestCase(-0.0)]
[TestCase(-1.0)]
[TestCase(Double.NegativeInfinity)]
public void SetLambdaFails(double lambda)
{
var d = new ConwayMaxwellPoisson(1.0, 2.0);
Assert.Throws<ArgumentOutOfRangeException>(() => d.Lambda = lambda);
@ -119,8 +132,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set Nu with bad values fails.
/// </summary>
/// <param name="nu">Nu parameter.</param>
[Test]
public void SetNuFails([Values(-0.1, -1.0, -10.0, Double.NegativeInfinity)] double nu)
[TestCase(-0.1)]
[TestCase(-1.0)]
[TestCase(-10.0)]
[TestCase(Double.NegativeInfinity)]
public void SetNuFails(double nu)
{
var d = new ConwayMaxwellPoisson(1.0, 2.0);
Assert.Throws<ArgumentOutOfRangeException>(() => d.Nu = nu);
@ -172,11 +188,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="lambda">Lambda value.</param>
/// <param name="nu">Nu parameter.</param>
/// <param name="mean">Expected value.</param>
[Test, Sequential]
public void ValidateMean(
[Values(1, 2, 10, 20, 1, 2)] int lambda,
[Values(1, 1, 1, 1, 2, 2)] int nu,
[Values(1.0, 2.0, 10.0, 20.0, 0.697774657964008, 1.12635723962342)] double mean)
[TestCase(1, 1, 1.0)]
[TestCase(2, 1, 2.0)]
[TestCase(10, 1, 10.0)]
[TestCase(20, 1, 20.0)]
[TestCase(1, 2, 0.697774657964008)]
[TestCase(2, 2, 1.12635723962342)]
public void ValidateMean(int lambda, int nu, double mean)
{
var d = new ConwayMaxwellPoisson(lambda, nu);
AssertHelpers.AlmostEqual(mean, d.Mean, 10);
@ -209,12 +227,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="nu">Nu parameter.</param>
/// <param name="x">Input X value.</param>
/// <param name="p">Expected value.</param>
[Test, Sequential]
public void ValidateProbability(
[Values(1.0, 1.0, 2.0, 2.0, 2.0, 2.0)] double lambda,
[Values(1.0, 1.0, 1.0, 1.0, 2.0, 2.0)] double nu,
[Values(1, 2, 1, 2, 1, 3)] int x,
[Values(0.367879441171442, 0.183939720585721, 0.270670566473225, 0.270670566473225, 0.470328074204904, 0.052258674911656)] double p)
[TestCase(1.0, 1.0, 1, 0.367879441171442)]
[TestCase(1.0, 1.0, 2, 0.183939720585721)]
[TestCase(2.0, 1.0, 1, 0.270670566473225)]
[TestCase(2.0, 1.0, 2, 0.270670566473225)]
[TestCase(2.0, 2.0, 1, 0.470328074204904)]
[TestCase(2.0, 2.0, 3, 0.052258674911656)]
public void ValidateProbability(double lambda, double nu, int x, double p)
{
var d = new ConwayMaxwellPoisson(lambda, nu);
AssertHelpers.AlmostEqual(p, d.Probability(x), 13);
@ -227,12 +246,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="nu">Nu parameter.</param>
/// <param name="x">Input X value.</param>
/// <param name="pln">Expected value.</param>
[Test, Sequential]
public void ValidateProbabilityLn(
[Values(1.0, 1.0, 2.0, 2.0, 2.0, 2.0)] double lambda,
[Values(1.0, 1.0, 1.0, 1.0, 2.0, 2.0)] double nu,
[Values(1, 2, 1, 2, 1, 3)] int x,
[Values(-1.0, -1.69314718055995, -1.30685281944005, -1.30685281944005, -0.754324797564617, -2.95154937490084)] double pln)
[TestCase(1.0, 1.0, 1, -1.0)]
[TestCase(1.0, 1.0, 2, -1.69314718055995)]
[TestCase(2.0, 1.0, 1, -1.30685281944005)]
[TestCase(2.0, 1.0, 2, -1.30685281944005)]
[TestCase(2.0, 2.0, 1, -0.754324797564617)]
[TestCase(2.0, 2.0, 3, -2.95154937490084)]
public void ValidateProbabilityLn(double lambda, double nu, int x, double pln)
{
var d = new ConwayMaxwellPoisson(lambda, nu);
AssertHelpers.AlmostEqual(pln, d.ProbabilityLn(x), 13);
@ -266,12 +286,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="nu">Nu parameter.</param>
/// <param name="x">Input X value.</param>
/// <param name="cdf">Expected value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(1.0, 1.0, 2.0, 2.0, 2.0, 2.0)] double lambda,
[Values(1.0, 1.0, 1.0, 1.0, 2.0, 2.0)] double nu,
[Values(1, 2, 1, 2, 1, 3)] int x,
[Values(0.735758882342885, 0.919698602928606, 0.406005849709838, 0.676676416183064, 0.705492111307356, 0.992914823321464)] double cdf)
[TestCase(1.0, 1.0, 1, 0.735758882342885)]
[TestCase(1.0, 1.0, 2, 0.919698602928606)]
[TestCase(2.0, 1.0, 1, 0.406005849709838)]
[TestCase(2.0, 1.0, 2, 0.676676416183064)]
[TestCase(2.0, 2.0, 1, 0.705492111307356)]
[TestCase(2.0, 2.0, 3, 0.992914823321464)]
public void ValidateCumulativeDistribution(double lambda, double nu, int x, double cdf)
{
var d = new ConwayMaxwellPoisson(lambda, nu);
AssertHelpers.AlmostEqual(cdf, d.CumulativeDistribution(x), 13);

102
src/UnitTests/DistributionTests/Discrete/DiscreteUniformTests.cs

@ -51,8 +51,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="l">Lower bound.</param>
/// <param name="u">Upper bound.</param>
[Test, Sequential]
public void CanCreateDiscreteUniform([Values(-10, 0, 10, 20)] int l, [Values(10, 4, 20, 20)] int u)
[TestCase(-10, 10)]
[TestCase(0, 4)]
[TestCase(10, 20)]
[TestCase(20, 20)]
public void CanCreateDiscreteUniform(int l, int u)
{
var du = new DiscreteUniform(l, u);
Assert.AreEqual(l, du.LowerBound);
@ -64,8 +67,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="l">Lower bound.</param>
/// <param name="u">Upper bound.</param>
[Test, Sequential]
public void DiscreteUniformCreateFailsWithBadParameters([Values(-1, 6)] int l, [Values(-2, 5)] int u)
[TestCase(-1, -2)]
[TestCase(6, 5)]
public void DiscreteUniformCreateFailsWithBadParameters(int l, int u)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new DiscreteUniform(l, u));
}
@ -84,8 +88,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set lower bound.
/// </summary>
/// <param name="p">Lower bound.</param>
[Test]
public void CanSetLowerBound([Values(0, 3, 10)] int p)
[TestCase(0)]
[TestCase(3)]
[TestCase(10)]
public void CanSetLowerBound(int p)
{
new DiscreteUniform(0, 10)
{
@ -97,8 +103,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set upper bound.
/// </summary>
/// <param name="p">Upper bound.</param>
[Test]
public void CanSetUpperBound([Values(0, 3, 10)] int p)
[TestCase(0)]
[TestCase(3)]
[TestCase(10)]
public void CanSetUpperBound(int p)
{
new DiscreteUniform(0, 10)
{
@ -110,8 +118,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set lower bound with bad values fails.
/// </summary>
/// <param name="p">Lower bound.</param>
[Test]
public void SetLowerBoundFails([Values(11, 20)] int p)
[TestCase(11)]
[TestCase(20)]
public void SetLowerBoundFails(int p)
{
var b = new DiscreteUniform(0, 10);
Assert.Throws<ArgumentOutOfRangeException>(() => b.LowerBound = p);
@ -121,8 +130,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set upper bound with bad values fails
/// </summary>
/// <param name="p">Upper bound.</param>
[Test]
public void SetUpperBoundFails([Values(-11, -20)] int p)
[TestCase(-11)]
[TestCase(-20)]
public void SetUpperBoundFails(int p)
{
var b = new DiscreteUniform(0, 10);
Assert.Throws<ArgumentOutOfRangeException>(() => b.UpperBound = p);
@ -134,8 +144,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="l">Lower bound.</param>
/// <param name="u">Upper bound.</param>
/// <param name="e">Expceted value.</param>
[Test, Sequential]
public void ValidateEntropy([Values(-10, 0, 10, 20)] int l, [Values(10, 4, 20, 20)] int u, [Values(3.0445224377234229965005979803657054342845752874046093, 1.6094379124341003746007593332261876395256013542685181, 2.3978952727983705440619435779651292998217068539374197, 0.0)] double e)
[TestCase(-10, 10, 3.0445224377234229965005979803657054342845752874046093)]
[TestCase(0, 4, 1.6094379124341003746007593332261876395256013542685181)]
[TestCase(10, 20, 2.3978952727983705440619435779651292998217068539374197)]
[TestCase(20, 20, 0.0)]
public void ValidateEntropy(int l, int u, double e)
{
var du = new DiscreteUniform(l, u);
AssertHelpers.AlmostEqual(e, du.Entropy, 14);
@ -146,8 +159,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="l">Lower bound.</param>
/// <param name="u">Upper bound.</param>
[Test, Sequential]
public void ValidateSkewness([Values(-10, 0, 10, 20)] int l, [Values(10, 4, 20, 20)] int u)
[TestCase(-10, 10)]
[TestCase(0, 4)]
[TestCase(10, 20)]
[TestCase(20, 20)]
public void ValidateSkewness(int l, int u)
{
var du = new DiscreteUniform(l, u);
Assert.AreEqual(0.0, du.Skewness);
@ -159,8 +175,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="l">Lower bound.</param>
/// <param name="u">Upper bound.</param>
/// <param name="m">Expceted value.</param>
[Test, Sequential]
public void ValidateMode([Values(-10, 0, 10, 20)] int l, [Values(10, 4, 20, 20)] int u, [Values(0, 2, 15, 20)] int m)
[TestCase(-10, 10, 0)]
[TestCase(0, 4, 2)]
[TestCase(10, 20, 15)]
[TestCase(20, 20, 20)]
public void ValidateMode(int l, int u, int m)
{
var du = new DiscreteUniform(l, u);
Assert.AreEqual(m, du.Mode);
@ -172,8 +191,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="l">Lower bound.</param>
/// <param name="u">Upper bound.</param>
/// <param name="m">Expceted value.</param>
[Test, Sequential]
public void ValidateMedian([Values(-10, 0, 10, 20)] int l, [Values(10, 4, 20, 20)] int u, [Values(0, 2, 15, 20)] int m)
[TestCase(-10, 10, 0)]
[TestCase(0, 4, 2)]
[TestCase(10, 20, 15)]
[TestCase(20, 20, 20)]
public void ValidateMedian(int l, int u, int m)
{
var du = new DiscreteUniform(l, u);
Assert.AreEqual(m, du.Median);
@ -185,8 +207,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="l">Lower bound.</param>
/// <param name="u">Upper bound.</param>
/// <param name="m">Expceted value.</param>
[Test, Sequential]
public void ValidateMean([Values(-10, 0, 10, 20)] int l, [Values(10, 4, 20, 20)] int u, [Values(0, 2, 15, 20)] int m)
[TestCase(-10, 10, 0)]
[TestCase(0, 4, 2)]
[TestCase(10, 20, 15)]
[TestCase(20, 20, 20)]
public void ValidateMean(int l, int u, int m)
{
var du = new DiscreteUniform(l, u);
Assert.AreEqual(m, du.Mean);
@ -219,8 +244,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="u">Upper bound.</param>
/// <param name="x">Input X value.</param>
/// <param name="p">Expceted value.</param>
[Test, Sequential]
public void ValidateProbability([Values(-10, -10, -10, -10, -10)] int l, [Values(10, 10, 10, -10, -10)] int u, [Values(-5, 1, 10, 0, -10)] int x, [Values(1 / 21.0, 1 / 21.0, 1 / 21.0, 0.0, 1.0)] double p)
[TestCase(-10, 10, -5, 1 / 21.0)]
[TestCase(-10, 10, 1, 1 / 21.0)]
[TestCase(-10, 10, 10, 1 / 21.0)]
[TestCase(-10, -10, 0, 0.0)]
[TestCase(-10, -10, -10, 1.0)]
public void ValidateProbability(int l, int u, int x, double p)
{
var b = new DiscreteUniform(l, u);
Assert.AreEqual(p, b.Probability(x));
@ -233,12 +262,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="u">Upper bound.</param>
/// <param name="x">Input X value.</param>
/// <param name="dln">Expceted value.</param>
[Test, Sequential]
public void ValidateProbabilityLn(
[Values(-10, -10, -10, -10, -10)] int l,
[Values(10, 10, 10, -10, -10)] int u,
[Values(-5, 1, 10, 0, -10)] int x,
[Values(-3.0445224377234229965005979803657054342845752874046093, -3.0445224377234229965005979803657054342845752874046093, -3.0445224377234229965005979803657054342845752874046093, Double.NegativeInfinity, 0.0)] double dln)
[TestCase(-10, 10, -5, -3.0445224377234229965005979803657054342845752874046093)]
[TestCase(-10, 10, 1, -3.0445224377234229965005979803657054342845752874046093)]
[TestCase(-10, 10, 10, -3.0445224377234229965005979803657054342845752874046093)]
[TestCase(-10, -10, 0, Double.NegativeInfinity)]
[TestCase(-10, -10, -10, 0.0)]
public void ValidateProbabilityLn(int l, int u, int x, double dln)
{
var b = new DiscreteUniform(l, u);
Assert.AreEqual(dln, b.ProbabilityLn(x));
@ -309,12 +338,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="u">Upper bound.</param>
/// <param name="x">Input X value.</param>
/// <param name="cdf">Expceted value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(-10, -10, -10, -10, -10, -10)] int l,
[Values(10, 10, 10, -10, -10, -10)] int u,
[Values(-5, 1, 10, 0, -10, -11)] double x,
[Values(6.0 / 21.0, 12.0 / 21.0, 1.0, 1.0, 1.0, 0.0)] double cdf)
[TestCase(-10, 10, -5, 6.0 / 21.0)]
[TestCase(-10, 10, 1, 12.0 / 21.0)]
[TestCase(-10, 10, 10, 1.0)]
[TestCase(-10, -10, 0, 1.0)]
[TestCase(-10, -10, -10, 1.0)]
[TestCase(-10, -10, -11, 0.0)]
public void ValidateCumulativeDistribution(int l, int u, double x, double cdf)
{
var b = new DiscreteUniform(l, u);
Assert.AreEqual(cdf, b.CumulativeDistribution(x));

82
src/UnitTests/DistributionTests/Discrete/GeometricTests.cs

@ -1,4 +1,4 @@
// <copyright file="GeometricTests.cs" company="Math.NET">
// <copyright file="GeometricTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -50,8 +50,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can create Geometric.
/// </summary>
/// <param name="p">Probability of generating a one.</param>
[Test]
public void CanCreateGeometric([Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0)]
[TestCase(0.3)]
[TestCase(1.0)]
public void CanCreateGeometric(double p)
{
var d = new Geometric(p);
Assert.AreEqual(p, d.P);
@ -61,8 +63,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Geometric create fails with bad parameters.
/// </summary>
/// <param name="p">Probability of generating a one.</param>
[Test]
public void GeometricCreateFailsWithBadParameters([Values(Double.NaN, -1.0, 2.0)] double p)
[TestCase(Double.NaN)]
[TestCase(-1.0)]
[TestCase(2.0)]
public void GeometricCreateFailsWithBadParameters(double p)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Geometric(p));
}
@ -81,8 +85,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set probability of one.
/// </summary>
/// <param name="p">Probability of generating a one.</param>
[Test]
public void CanSetProbabilityOfOne([Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0)]
[TestCase(0.3)]
[TestCase(1.0)]
public void CanSetProbabilityOfOne(double p)
{
new Geometric(0.3)
{
@ -94,8 +100,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set probability of one with a bad value fails.
/// </summary>
/// <param name="p">Probability of generating a one.</param>
[Test]
public void SetProbabilityOfOneFails([Values(Double.NaN, -1.0, 2.0)] double p)
[TestCase(Double.NaN)]
[TestCase(-1.0)]
[TestCase(2.0)]
public void SetProbabilityOfOneFails(double p)
{
var d = new Geometric(0.3);
Assert.Throws<ArgumentOutOfRangeException>(() => d.P = p);
@ -105,8 +113,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Validate entropy.
/// </summary>
/// <param name="p">Probability of generating a one.</param>
[Test]
public void ValidateEntropy([Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0)]
[TestCase(0.3)]
[TestCase(1.0)]
public void ValidateEntropy(double p)
{
var d = new Geometric(p);
Assert.AreEqual(((-p * Math.Log(p, 2.0)) - ((1.0 - p) * Math.Log(1.0 - p, 2.0))) / p, d.Entropy);
@ -116,8 +126,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Validate skewness.
/// </summary>
/// <param name="p">Probability of generating a one.</param>
[Test]
public void ValidateSkewness([Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0)]
[TestCase(0.3)]
[TestCase(1.0)]
public void ValidateSkewness(double p)
{
var d = new Geometric(p);
Assert.AreEqual((2.0 - p) / Math.Sqrt(1.0 - p), d.Skewness);
@ -127,8 +139,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Validate mode.
/// </summary>
/// <param name="p">Probability of generating a one.</param>
[Test]
public void ValidateMode([Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0)]
[TestCase(0.3)]
[TestCase(1.0)]
public void ValidateMode(double p)
{
var d = new Geometric(p);
Assert.AreEqual(1, d.Mode);
@ -138,8 +152,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Validate median.
/// </summary>
/// <param name="p">Probability of generating a one.</param>
[Test]
public void ValidateMedian([Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0)]
[TestCase(0.3)]
[TestCase(1.0)]
public void ValidateMedian(double p)
{
var d = new Geometric(p);
Assert.AreEqual((int)Math.Ceiling(-Math.Log(2.0) / Math.Log(1 - p)), d.Median);
@ -170,8 +186,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="p">Probability of generating a one.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateProbability([Values(0.0, 0.3, 1.0)] double p, [Values(-1, 0, 1, 2)] int x)
[TestCase(0.0, -1)]
[TestCase(0.3, 0)]
[TestCase(1.0, 1)]
[TestCase(1.0, 2)]
public void ValidateProbability(double p, int x)
{
var d = new Geometric(p);
if (x > 0)
@ -190,11 +209,19 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="p">Probability of generating a one.</param>
/// <param name="x">Input X value.</param>
/// <param name="pln">Expected value.</param>
[Test, Sequential]
public void ValidateProbabilityLn(
[Values(0.0, 0.0, 0.0, 0.0, 0.3, 0.3, 0.3, 0.3, 1.0, 1.0, 1.0, 1.0)] double p,
[Values(-1, 0, 1, 2, -1, 0, 1, 2, -1, 0, 1, 2)] int x,
[Values(Double.NegativeInfinity, 0.0, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, -0.35667494393873244235395440410727451457180907089949815, -1.2039728043259360296301803719337238685164245381839102, Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity, 0.0, Double.NegativeInfinity)] double pln)
[TestCase(0.0, -1, Double.NegativeInfinity)]
[TestCase(0.0, 0, 0.0)]
[TestCase(0.0, 1, Double.NegativeInfinity)]
[TestCase(0.0, 2, Double.NegativeInfinity)]
[TestCase(0.3, -1, Double.NegativeInfinity)]
[TestCase(0.3, 0, -0.35667494393873244235395440410727451457180907089949815)]
[TestCase(0.3, 1, -1.2039728043259360296301803719337238685164245381839102)]
[TestCase(0.3, 2, Double.NegativeInfinity)]
[TestCase(1.0, -1, Double.NegativeInfinity)]
[TestCase(1.0, 0, Double.NegativeInfinity)]
[TestCase(1.0, 1, 0.0)]
[TestCase(1.0, 2, Double.NegativeInfinity)]
public void ValidateProbabilityLn(double p, int x, double pln)
{
var d = new Geometric(p);
if (x > 0)
@ -233,8 +260,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="p">Probability of generating a one.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateCumulativeDistribution([Values(0.0, 0.3, 1.0)] double p, [Values(-1, 0, 1, 2)] int x)
[TestCase(0.0, -1)]
[TestCase(0.3, 0)]
[TestCase(1.0, 1)]
[TestCase(1.0, 2)]
public void ValidateCumulativeDistribution(double p, int x)
{
var d = new Geometric(p);
Assert.AreEqual(1.0 - Math.Pow(1.0 - p, x), d.CumulativeDistribution(x));

138
src/UnitTests/DistributionTests/Discrete/HypergeometricTests.cs

@ -1,4 +1,4 @@
// <copyright file="HypergeometricTests.cs" company="Math.NET">
// <copyright file="HypergeometricTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -52,8 +52,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="size">Population size.</param>
/// <param name="m">M parameter.</param>
/// <param name="n">N parameter.</param>
[Test, Sequential]
public void CanCreateHypergeometric([Values(0, 1, 2, 2, 10, 10)] int size, [Values(0, 1, 1, 2, 1, 5)] int m, [Values(0, 1, 1, 2, 1, 3)] int n)
[TestCase(0, 0, 0)]
[TestCase(1, 1, 1)]
[TestCase(2, 1, 1)]
[TestCase(2, 2, 2)]
[TestCase(10, 1, 1)]
[TestCase(10, 5, 3)]
public void CanCreateHypergeometric(int size, int m, int n)
{
var d = new Hypergeometric(size, m, n);
Assert.AreEqual(size, d.PopulationSize);
@ -67,8 +72,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="size">Population size.</param>
/// <param name="m">M parameter.</param>
/// <param name="n">N parameter.</param>
[Test, Sequential]
public void HypergeometricCreateFailsWithBadParameters([Values(2, 10, -2, 0)] int size, [Values(3, 5, 1, 1)] int m, [Values(2, 20, 1, 1)] int n)
[TestCase(2, 3, 2)]
[TestCase(10, 5, 20)]
[TestCase(-2, 1, 1)]
[TestCase(0, 1, 1)]
public void HypergeometricCreateFailsWithBadParameters(int size, int m, int n)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Hypergeometric(size, m, n));
}
@ -87,8 +95,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set size.
/// </summary>
/// <param name="size">Population size.</param>
[Test]
public void CanSetSize([Values(5, 10, 20)] int size)
[TestCase(5)]
[TestCase(10)]
[TestCase(20)]
public void CanSetSize(int size)
{
new Hypergeometric(10, 1, 1)
{
@ -100,8 +110,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set size fails with bad values.
/// </summary>
/// <param name="size">Population size.</param>
[Test]
public void SetSizeFails([Values(-1, 0)] int size)
[TestCase(-1)]
[TestCase(0)]
public void SetSizeFails(int size)
{
var d = new Hypergeometric(10, 1, 1);
Assert.Throws<ArgumentOutOfRangeException>(() => d.PopulationSize = size);
@ -111,8 +122,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set M.
/// </summary>
/// <param name="m">M parameter.</param>
[Test]
public void CanSetm([Values(0, 1, 2, 5)] int m)
[TestCase(0)]
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
public void CanSetm(int m)
{
new Hypergeometric(10, 1, 1)
{
@ -124,8 +138,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set M fails with bad values.
/// </summary>
/// <param name="m">M parameter.</param>
[Test]
public void SetmFails([Values(11, -1)] int m)
[TestCase(11)]
[TestCase(-1)]
public void SetmFails(int m)
{
var d = new Hypergeometric(10, 1, 1);
Assert.Throws<ArgumentOutOfRangeException>(() => d.M = m);
@ -135,8 +150,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set N.
/// </summary>
/// <param name="n">N parameter.</param>
[Test]
public void CanSetn([Values(0, 1, 2, 5)] int n)
[TestCase(0)]
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
public void CanSetn(int n)
{
new Hypergeometric(10, 1, 1)
{
@ -148,8 +166,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set N fails with bad values.
/// </summary>
/// <param name="n">N parameter.</param>
[Test]
public void SetnFails([Values(11, -1)] int n)
[TestCase(11)]
[TestCase(-1)]
public void SetnFails(int n)
{
var d = new Hypergeometric(10, 1, 1);
Assert.Throws<ArgumentOutOfRangeException>(() => d.N = n);
@ -171,8 +190,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="size">Population size.</param>
/// <param name="m">M parameter.</param>
/// <param name="n">N parameter.</param>
[Test, Sequential]
public void ValidateSkewness([Values(0, 1, 2, 2, 10, 10)] int size, [Values(0, 1, 1, 2, 1, 5)] int m, [Values(0, 1, 1, 2, 1, 3)] int n)
[TestCase(0, 0, 0)]
[TestCase(1, 1, 1)]
[TestCase(2, 1, 1)]
[TestCase(2, 2, 2)]
[TestCase(10, 1, 1)]
[TestCase(10, 5, 3)]
public void ValidateSkewness(int size, int m, int n)
{
var d = new Hypergeometric(size, m, n);
Assert.AreEqual((Math.Sqrt(size - 1.0) * (size - (2 * n)) * (size - (2 * m))) / (Math.Sqrt(n * m * (size - m) * (size - n)) * (size - 2.0)), d.Skewness);
@ -184,8 +208,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="size">Population size.</param>
/// <param name="m">M parameter.</param>
/// <param name="n">N parameter.</param>
[Test, Sequential]
public void ValidateMode([Values(0, 1, 2, 2, 10, 10)] int size, [Values(0, 1, 1, 2, 1, 5)] int m, [Values(0, 1, 1, 2, 1, 3)] int n)
[TestCase(0, 0, 0)]
[TestCase(1, 1, 1)]
[TestCase(2, 1, 1)]
[TestCase(2, 2, 2)]
[TestCase(10, 1, 1)]
[TestCase(10, 5, 3)]
public void ValidateMode(int size, int m, int n)
{
var d = new Hypergeometric(size, m, n);
Assert.AreEqual((n + 1) * (m + 1) / (size + 2), d.Mode);
@ -207,8 +236,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="size">Population size.</param>
/// <param name="m">M parameter.</param>
/// <param name="n">N parameter.</param>
[Test, Sequential]
public void ValidateMinimum([Values(0, 1, 2, 2, 10, 10)] int size, [Values(0, 1, 1, 2, 1, 5)] int m, [Values(0, 1, 1, 2, 1, 3)] int n)
[TestCase(0, 0, 0)]
[TestCase(1, 1, 1)]
[TestCase(2, 1, 1)]
[TestCase(2, 2, 2)]
[TestCase(10, 1, 1)]
[TestCase(10, 5, 3)]
public void ValidateMinimum(int size, int m, int n)
{
var d = new Hypergeometric(size, m, n);
Assert.AreEqual(Math.Max(0, n + m - size), d.Minimum);
@ -220,8 +254,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="size">Population size.</param>
/// <param name="m">M parameter.</param>
/// <param name="n">N parameter.</param>
[Test, Sequential]
public void ValidateMaximum([Values(0, 1, 2, 2, 10, 10)] int size, [Values(0, 1, 1, 2, 1, 5)] int m, [Values(0, 1, 1, 2, 1, 3)] int n)
[TestCase(0, 0, 0)]
[TestCase(1, 1, 1)]
[TestCase(2, 1, 1)]
[TestCase(2, 2, 2)]
[TestCase(10, 1, 1)]
[TestCase(10, 5, 3)]
public void ValidateMaximum(int size, int m, int n)
{
var d = new Hypergeometric(size, m, n);
Assert.AreEqual(Math.Min(m, n), d.Maximum);
@ -234,12 +273,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="m">M parameter.</param>
/// <param name="n">N parameter.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateProbability(
[Values(0, 1, 2, 2, 2, 10, 10, 10, 10)] int size,
[Values(0, 1, 1, 1, 2, 1, 1, 5, 5)] int m,
[Values(0, 1, 1, 1, 2, 1, 1, 3, 3)] int n,
[Values(0, 1, 0, 1, 2, 0, 1, 1, 3)] int x)
[TestCase(0, 0, 0, 0)]
[TestCase(1, 1, 1, 1)]
[TestCase(2, 1, 1, 0)]
[TestCase(2, 1, 1, 1)]
[TestCase(2, 2, 2, 2)]
[TestCase(10, 1, 1, 0)]
[TestCase(10, 1, 1, 1)]
[TestCase(10, 5, 3, 1)]
[TestCase(10, 5, 3, 3)]
public void ValidateProbability(int size, int m, int n, int x)
{
var d = new Hypergeometric(size, m, n);
Assert.AreEqual(SpecialFunctions.Binomial(m, x) * SpecialFunctions.Binomial(size - m, n - x) / SpecialFunctions.Binomial(size, n), d.Probability(x));
@ -252,12 +295,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="m">M parameter.</param>
/// <param name="n">N parameter.</param>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateProbabilityLn(
[Values(0, 1, 2, 2, 2, 10, 10, 10, 10)] int size,
[Values(0, 1, 1, 1, 2, 1, 1, 5, 5)] int m,
[Values(0, 1, 1, 1, 2, 1, 1, 3, 3)] int n,
[Values(0, 1, 0, 1, 2, 0, 1, 1, 3)] int x)
[TestCase(0, 0, 0, 0)]
[TestCase(1, 1, 1, 1)]
[TestCase(2, 1, 1, 0)]
[TestCase(2, 1, 1, 1)]
[TestCase(2, 2, 2, 2)]
[TestCase(10, 1, 1, 0)]
[TestCase(10, 1, 1, 1)]
[TestCase(10, 5, 3, 1)]
[TestCase(10, 5, 3, 3)]
public void ValidateProbabilityLn(int size, int m, int n, int x)
{
var d = new Hypergeometric(size, m, n);
Assert.AreEqual(Math.Log(d.Probability(x)), d.ProbabilityLn(x));
@ -292,13 +339,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="n">N parameter.</param>
/// <param name="x">Input X value.</param>
/// <param name="cdf">Expected value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(0, 1, 2, 2, 2, 10, 10, 10, 10)] int size,
[Values(0, 1, 1, 1, 2, 1, 1, 5, 5)] int m,
[Values(0, 1, 1, 1, 2, 1, 1, 3, 3)] int n,
[Values(0.5, 1.1, 0.3, 1.2, 2.4, 0.3, 1.2, 1.1, 3.0)] double x,
[Values(1.0, 1.0, 0.5, 1.0, 1.0, 0.9, 1.0, 0.5, 0.916666666666667)] double cdf)
[TestCase(0, 0, 0, 0.5, 1.0)]
[TestCase(1, 1, 1, 1.1, 1.0)]
[TestCase(2, 1, 1, 0.3, 0.5)]
[TestCase(2, 1, 1, 1.2, 1.0)]
[TestCase(2, 2, 2, 2.4, 1.0)]
[TestCase(10, 1, 1, 0.3, 0.9)]
[TestCase(10, 1, 1, 1.2, 1.0)]
[TestCase(10, 5, 3, 1.1, 0.5)]
[TestCase(10, 5, 3, 3.0, 0.916666666666667)]
public void ValidateCumulativeDistribution(int size, int m, int n, double x, double cdf)
{
var d = new Hypergeometric(size, m, n);
AssertHelpers.AlmostEqual(cdf, d.CumulativeDistribution(x), 14);

79
src/UnitTests/DistributionTests/Discrete/NegativeBinomialTests.cs

@ -1,4 +1,4 @@
// <copyright file="NegativeBinomialTests.cs" company="Math.NET">
// <copyright file="NegativeBinomialTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="r">Number of trials.</param>
/// <param name="p">Probability of success.</param>
[Test, Combinatorial]
public void CanCreateNegativeBinomial([Values(0.0, 0.1, 1.0)] double r, [Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0, 0.0)]
[TestCase(0.1, 0.3)]
[TestCase(1.0, 1.0)]
public void CanCreateNegativeBinomial(double r, double p)
{
var d = new NegativeBinomial(r, p);
Assert.AreEqual(r, d.R);
@ -64,8 +66,15 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="r">Number of trials.</param>
/// <param name="p">Probability of success.</param>
[Test, Sequential]
public void NegativeBinomialCreateFailsWithBadParameters([Values(0.0, 0.0, 0.0, Double.NegativeInfinity, -1.0, Double.NaN, Double.NegativeInfinity, Double.NaN)] double r, [Values(Double.NaN, -1.0, 2.0, 0.0, 0.3, 1.0, Double.NaN, Double.NaN)] double p)
[TestCase(0.0, Double.NaN)]
[TestCase(0.0, -1.0)]
[TestCase(0.0, 2.0)]
[TestCase(Double.NegativeInfinity, 0.0)]
[TestCase(-1.0, 0.3)]
[TestCase(Double.NaN, 1.0)]
[TestCase(Double.NegativeInfinity, Double.NaN)]
[TestCase(Double.NaN, Double.NaN)]
public void NegativeBinomialCreateFailsWithBadParameters(double r, double p)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new NegativeBinomial(r, p));
}
@ -84,8 +93,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set R.
/// </summary>
/// <param name="r">Number of trials.</param>
[Test]
public void CanSetR([Values(0.0, 0.1, 1.0)] double r)
[TestCase(0.0)]
[TestCase(0.1)]
[TestCase(1.0)]
public void CanSetR(double r)
{
new NegativeBinomial(1.0, 0.5)
{
@ -97,8 +108,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set R fails with bad values.
/// </summary>
/// <param name="r">Number of trials.</param>
[Test]
public void SetRFails([Values(Double.NaN, -1.0, Double.NegativeInfinity)] double r)
[TestCase(Double.NaN)]
[TestCase(-1.0)]
[TestCase(Double.NegativeInfinity)]
public void SetRFails(double r)
{
var d = new NegativeBinomial(1.0, 0.5);
Assert.Throws<ArgumentOutOfRangeException>(() => d.R = r);
@ -108,8 +121,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set probability of one.
/// </summary>
/// <param name="p">Probability of success.</param>
[Test]
public void CanSetProbabilityOfOne([Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0)]
[TestCase(0.3)]
[TestCase(1.0)]
public void CanSetProbabilityOfOne(double p)
{
new NegativeBinomial(1.0, 0.5)
{
@ -121,8 +136,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set probability of one fails with bad values.
/// </summary>
/// <param name="p">Probability of success.</param>
[Test]
public void SetProbabilityOfOneFails([Values(Double.NaN, -1.0, 2.0)] double p)
[TestCase(Double.NaN)]
[TestCase(-1.0)]
[TestCase(2.0)]
public void SetProbabilityOfOneFails(double p)
{
var d = new NegativeBinomial(1.0, 0.5);
Assert.Throws<ArgumentOutOfRangeException>(() => d.P = p);
@ -143,8 +160,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="r">Number of trials.</param>
/// <param name="p">Probability of success.</param>
[Test, Combinatorial]
public void ValidateSkewness([Values(0.0, 0.1, 1.0)] double r, [Values(0.0, 0.3, 1.0)] double p)
[TestCase(0.0, 0.0)]
[TestCase(0.1, 0.3)]
[TestCase(1.0, 1.0)]
public void ValidateSkewness(double r, double p)
{
var b = new NegativeBinomial(r, p);
Assert.AreEqual((2.0 - p) / Math.Sqrt(r * (1.0 - p)), b.Skewness);
@ -155,8 +174,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="r">Number of trials.</param>
/// <param name="p">Probability of success.</param>
[Test, Sequential]
public void ValidateMode([Values(0.0, 0.3, 1.0)] double r, [Values(0.0, 0.0, 1.0)] double p)
[TestCase(0.0, 0.0)]
[TestCase(0.3, 0.0)]
[TestCase(1.0, 1.0)]
public void ValidateMode(double r, double p)
{
var d = new NegativeBinomial(r, p);
if (r > 1)
@ -205,8 +226,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="r">Number of trials.</param>
/// <param name="p">Probability of success.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateProbability([Values(0.0, 0.1, 1.0)] double r, [Values(0.0, 0.3, 1.0)] double p, [Values(0, 1, 2, 3, 5)] int x)
[TestCase(0.0, 0.0, 0)]
[TestCase(0.1, 0.3, 1)]
[TestCase(1.0, 1.0, 2)]
[TestCase(1.0, 1.0, 3)]
[TestCase(1.0, 1.0, 5)]
public void ValidateProbability(double r, double p, int x)
{
var d = new NegativeBinomial(r, p);
Assert.AreEqual(Math.Exp(SpecialFunctions.GammaLn(r + x) - SpecialFunctions.GammaLn(r) - SpecialFunctions.GammaLn(x + 1.0) + (r * Math.Log(p)) + (x * Math.Log(1.0 - p))), d.Probability(x));
@ -218,8 +243,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="r">Number of trials.</param>
/// <param name="p">Probability of success.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateProbabilityLn([Values(0.0, 0.1, 1.0)] double r, [Values(0.0, 0.3, 1.0)] double p, [Values(0, 1, 2, 3, 5)] int x)
[TestCase(0.0, 0.0, 0)]
[TestCase(0.1, 0.3, 1)]
[TestCase(1.0, 1.0, 2)]
[TestCase(1.0, 1.0, 3)]
[TestCase(1.0, 1.0, 5)]
public void ValidateProbabilityLn(double r, double p, int x)
{
var d = new NegativeBinomial(r, p);
Assert.AreEqual(SpecialFunctions.GammaLn(r + x) - SpecialFunctions.GammaLn(r) - SpecialFunctions.GammaLn(x + 1.0) + (r * Math.Log(p)) + (x * Math.Log(1.0 - p)), d.ProbabilityLn(x));
@ -231,8 +260,12 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="r">Number of trials.</param>
/// <param name="p">Probability of success.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateCumulativeDistribution([Values(0.0, 0.1, 1.0)] double r, [Values(0.0, 0.3, 1.0)] double p, [Values(0, 1, 2, 3, 5)] int x)
[TestCase(0.0, 0.0, 0)]
[TestCase(0.1, 0.3, 1)]
[TestCase(1.0, 1.0, 2)]
[TestCase(1.0, 1.0, 3)]
[TestCase(1.0, 1.0, 5)]
public void ValidateCumulativeDistribution(double r, double p, int x)
{
var d = new NegativeBinomial(r, p);
Assert.AreEqual(SpecialFunctions.BetaRegularized(r, x + 1.0, p), d.CumulativeDistribution(x), 1e-12);

95
src/UnitTests/DistributionTests/Discrete/PoissonTests.cs

@ -1,4 +1,4 @@
// <copyright file="PoissonTests.cs" company="Math.NET">
// <copyright file="PoissonTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -50,8 +50,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can create Poisson.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void CanCreatePoisson([Values(1.5, 5.4, 10.8)] double lambda)
[TestCase(1.5)]
[TestCase(5.4)]
[TestCase(10.8)]
public void CanCreatePoisson(double lambda)
{
var d = new Poisson(lambda);
Assert.AreEqual(lambda, d.Lambda);
@ -61,8 +63,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Poisson create fails with bad parameters.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void PoissonCreateFailsWithBadParameters([Values(Double.NaN, -1.5, 0.0)] double lambda)
[TestCase(Double.NaN)]
[TestCase(-1.5)]
[TestCase(0.0)]
public void PoissonCreateFailsWithBadParameters(double lambda)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Poisson(lambda));
}
@ -81,8 +85,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set probability of one.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void CanSetProbabilityOfOne([Values(1.5, 5.4, 10.8)] double lambda)
[TestCase(1.5)]
[TestCase(5.4)]
[TestCase(10.8)]
public void CanSetProbabilityOfOne(double lambda)
{
new Poisson(0.3)
{
@ -94,8 +100,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set probability of one fails with bad value.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void SetProbabilityOfOneFails([Values(Double.NaN, -1.5, 0.0)] double lambda)
[TestCase(Double.NaN)]
[TestCase(-1.5)]
[TestCase(0.0)]
public void SetProbabilityOfOneFails(double lambda)
{
var d = new Poisson(0.3);
Assert.Throws<ArgumentOutOfRangeException>(() => d.Lambda = lambda);
@ -105,8 +113,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Validate entropy.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ValidateEntropy([Values(1.5, 5.4, 10.8)] double lambda)
[TestCase(1.5)]
[TestCase(5.4)]
[TestCase(10.8)]
public void ValidateEntropy(double lambda)
{
var d = new Poisson(lambda);
Assert.AreEqual((0.5 * Math.Log(2 * Math.PI * Math.E * lambda)) - (1.0 / (12.0 * lambda)) - (1.0 / (24.0 * lambda * lambda)) - (19.0 / (360.0 * lambda * lambda * lambda)), d.Entropy);
@ -116,8 +126,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Validate skewness.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ValidateSkewness([Values(1.5, 5.4, 10.8)] double lambda)
[TestCase(1.5)]
[TestCase(5.4)]
[TestCase(10.8)]
public void ValidateSkewness(double lambda)
{
var d = new Poisson(lambda);
Assert.AreEqual(1.0 / Math.Sqrt(lambda), d.Skewness);
@ -127,8 +139,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Validate mode.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ValidateMode([Values(1.5, 5.4, 10.8)] double lambda)
[TestCase(1.5)]
[TestCase(5.4)]
[TestCase(10.8)]
public void ValidateMode(double lambda)
{
var d = new Poisson(lambda);
Assert.AreEqual((int)Math.Floor(lambda), d.Mode);
@ -138,8 +152,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Validate median.
/// </summary>
/// <param name="lambda">Lambda value.</param>
[Test]
public void ValidateMedian([Values(1.5, 5.4, 10.8)] double lambda)
[TestCase(1.5)]
[TestCase(5.4)]
[TestCase(10.8)]
public void ValidateMedian(double lambda)
{
var d = new Poisson(lambda);
Assert.AreEqual((int)Math.Floor(lambda + (1.0 / 3.0) - (0.02 / lambda)), d.Median);
@ -171,11 +187,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="lambda">Lambda value.</param>
/// <param name="x">Input X value.</param>
/// <param name="result">Expected value.</param>
[Test, Sequential]
public void ValidateProbability(
[Values(1.5, 1.5, 1.5, 5.4, 5.4, 5.4, 10.8, 10.8, 10.8)] double lambda,
[Values(1, 10, 20, 1, 10, 20, 1, 10, 20)] int x,
[Values(0.334695240222645000000000000000, 0.000003545747740570180000000000, 0.000000000000000304971208961018, 0.024389537090108400000000000000, 0.026241240591792300000000000000, 0.000000825202200316548000000000, 0.000220314636840657000000000000, 0.121365183659420000000000000000, 0.003908139778574110000000000000)] double result)
[TestCase(1.5, 1, 0.334695240222645000000000000000)]
[TestCase(1.5, 10, 0.000003545747740570180000000000)]
[TestCase(1.5, 20, 0.000000000000000304971208961018)]
[TestCase(5.4, 1, 0.024389537090108400000000000000)]
[TestCase(5.4, 10, 0.026241240591792300000000000000)]
[TestCase(5.4, 20, 0.000000825202200316548000000000)]
[TestCase(10.8, 1, 0.000220314636840657000000000000)]
[TestCase(10.8, 10, 0.121365183659420000000000000000)]
[TestCase(10.8, 20, 0.003908139778574110000000000000)]
public void ValidateProbability(double lambda, int x, double result)
{
var d = new Poisson(lambda);
Assert.AreEqual(d.Probability(x), result, 1e-12);
@ -187,11 +208,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="lambda">Lambda value.</param>
/// <param name="x">Input X value.</param>
/// <param name="result">Expected value.</param>
[Test, Sequential]
public void ValidateProbabilityLn(
[Values(1.5, 1.5, 1.5, 5.4, 5.4, 5.4, 10.8, 10.8, 10.8)] double lambda,
[Values(1, 10, 20, 1, 10, 20, 1, 10, 20)] int x,
[Values(0.334695240222645000000000000000, 0.000003545747740570180000000000, 0.000000000000000304971208961018, 0.024389537090108400000000000000, 0.026241240591792300000000000000, 0.000000825202200316548000000000, 0.000220314636840657000000000000, 0.121365183659420000000000000000, 0.003908139778574110000000000000)] double result)
[TestCase(1.5, 1, 0.334695240222645000000000000000)]
[TestCase(1.5, 10, 0.000003545747740570180000000000)]
[TestCase(1.5, 20, 0.000000000000000304971208961018)]
[TestCase(5.4, 1, 0.024389537090108400000000000000)]
[TestCase(5.4, 10, 0.026241240591792300000000000000)]
[TestCase(5.4, 20, 0.000000825202200316548000000000)]
[TestCase(10.8, 1, 0.000220314636840657000000000000)]
[TestCase(10.8, 10, 0.121365183659420000000000000000)]
[TestCase(10.8, 20, 0.003908139778574110000000000000)]
public void ValidateProbabilityLn(double lambda, int x, double result)
{
var d = new Poisson(lambda);
Assert.AreEqual(d.ProbabilityLn(x), Math.Log(result), 1e-12);
@ -224,11 +250,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="lambda">Lambda value.</param>
/// <param name="x">Input X value.</param>
/// <param name="result">Expected value.</param>
[Test, Sequential]
public void ValidateCumulativeDistribution(
[Values(1.5, 1.5, 1.5, 5.4, 5.4, 5.4, 10.8, 10.8, 10.8)] double lambda,
[Values(1, 10, 20, 1, 10, 20, 1, 10, 20)] int x,
[Values(0.5578254003710750000000, 0.9999994482467640000000, 1.0000000000000000000000, 0.0289061180327211000000, 0.9774863006897650000000, 0.9999997199928290000000, 0.0002407141402518290000, 0.4839692359955690000000, 0.9961800769608090000000)] double result)
[TestCase(1.5, 1, 0.5578254003710750000000)]
[TestCase(1.5, 10, 0.9999994482467640000000)]
[TestCase(1.5, 20, 1.0000000000000000000000)]
[TestCase(5.4, 1, 0.0289061180327211000000)]
[TestCase(5.4, 10, 0.9774863006897650000000)]
[TestCase(5.4, 20, 0.9999997199928290000000)]
[TestCase(10.8, 1, 0.0002407141402518290000)]
[TestCase(10.8, 10, 0.4839692359955690000000)]
[TestCase(10.8, 20, 0.9961800769608090000000)]
public void ValidateCumulativeDistribution(double lambda, int x, double result)
{
var d = new Poisson(lambda);
Assert.AreEqual(d.CumulativeDistribution(x), result, 1e-12);

86
src/UnitTests/DistributionTests/Discrete/ZipfTests.cs

@ -1,4 +1,4 @@
// <copyright file="ZipfTests.cs" company="Math.NET">
// <copyright file="ZipfTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="s">S parameter.</param>
/// <param name="n">N parameter.</param>
[Test, Combinatorial]
public void CanCreateZipf([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n)
[TestCase(0.1, 1)]
[TestCase(1, 20)]
[TestCase(1, 50)]
public void CanCreateZipf(double s, int n)
{
var d = new Zipf(s, n);
Assert.AreEqual(s, d.S);
@ -64,8 +66,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="s">S parameter.</param>
/// <param name="n">N parameter.</param>
[Test, Combinatorial]
public void ZipfCreateFailsWithBadParameters([Values(0.0)] double s, [Values(-10, 0)] int n)
[TestCase(0.0, -10)]
[TestCase(0.0, 0)]
public void ZipfCreateFailsWithBadParameters(double s, int n)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Zipf(s, n));
}
@ -84,8 +87,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set S.
/// </summary>
/// <param name="s">S parameter.</param>
[Test]
public void CanSetS([Values(0.1, 1.0, 5.0)] double s)
[TestCase(0.1)]
[TestCase(1.0)]
[TestCase(5.0)]
public void CanSetS(double s)
{
new Zipf(1.0, 5)
{
@ -97,8 +102,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set S fails with bad values.
/// </summary>
/// <param name="s">S parameter.</param>
[Test]
public void SetSFails([Values(Double.NaN, -1.0, Double.NegativeInfinity)] double s)
[TestCase(Double.NaN)]
[TestCase(-1.0)]
[TestCase(Double.NegativeInfinity)]
public void SetSFails(double s)
{
var d = new Zipf(1.0, 5);
Assert.Throws<ArgumentOutOfRangeException>(() => d.S = s);
@ -108,8 +115,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Can set N.
/// </summary>
/// <param name="n">N parameter.</param>
[Test]
public void CanSetN([Values(1, 20, 50)] int n)
[TestCase(1)]
[TestCase(20)]
[TestCase(50)]
public void CanSetN(int n)
{
new Zipf(1.0, 5)
{
@ -121,8 +130,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// Set N fails with bad values.
/// </summary>
/// <param name="n">N parameter.</param>
[Test]
public void SetNFails([Values(-1, 0)] int n)
[TestCase(-1)]
[TestCase(0)]
public void SetNFails(int n)
{
var d = new Zipf(1.0, 5);
Assert.Throws<ArgumentOutOfRangeException>(() => d.N = n);
@ -134,11 +144,13 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="s">S parameter.</param>
/// <param name="n">N parameter.</param>
/// <param name="e">Expected value.</param>
[Test, Sequential]
public void ValidateEntropy(
[Values(0.1, 0.1, 0.1, 1.0, 1.0, 1.0)] double s,
[Values(1, 20, 50, 1, 20, 50)] int n,
[Values(0.0, 2.9924075515295949, 3.9078245132371388, 0.0, 2.5279968533953743, 3.1971263138845916)] double e)
[TestCase(0.1, 1, 0.0)]
[TestCase(0.1, 20, 2.9924075515295949)]
[TestCase(0.1, 50, 3.9078245132371388)]
[TestCase(1.0, 1, 0.0)]
[TestCase(1.0, 20, 2.5279968533953743)]
[TestCase(1.0, 50, 3.1971263138845916)]
public void ValidateEntropy(double s, int n, double e)
{
var d = new Zipf(s, n);
AssertHelpers.AlmostEqual(e, d.Entropy, 15);
@ -149,10 +161,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="s">S parameter.</param>
/// <param name="n">N parameter.</param>
[Test, Combinatorial]
public void ValidateSkewness(
[Values(5.0, 10.0)] double s,
[Values(1, 20, 50)] int n)
[TestCase(5.0, 1)]
[TestCase(10.0, 20)]
[TestCase(10.0, 50)]
public void ValidateSkewness(double s, int n)
{
var d = new Zipf(s, n);
if (s > 4)
@ -166,8 +178,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="s">S parameter.</param>
/// <param name="n">N parameter.</param>
[Test, Combinatorial]
public void ValidateMode([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n)
[TestCase(0.1, 1)]
[TestCase(1, 20)]
[TestCase(1, 50)]
public void ValidateMode(double s, int n)
{
var d = new Zipf(s, n);
Assert.AreEqual(1, d.Mode);
@ -198,8 +212,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// </summary>
/// <param name="s">S parameter.</param>
/// <param name="n">N parameter.</param>
[Test, Combinatorial]
public void ValidateMaximum([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n)
[TestCase(0.1, 1)]
[TestCase(1, 20)]
[TestCase(1, 50)]
public void ValidateMaximum(double s, int n)
{
var d = new Zipf(s, n);
Assert.AreEqual(n, d.Maximum);
@ -211,8 +227,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="s">S parameter.</param>
/// <param name="n">N parameter.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateProbability([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n, [Values(1, 15)] int x)
[TestCase(0.1, 1, 1)]
[TestCase(1, 20, 15)]
[TestCase(1, 50, 20)]
public void ValidateProbability(double s, int n, int x)
{
var d = new Zipf(s, n);
Assert.AreEqual((1.0 / Math.Pow(x, s)) / SpecialFunctions.GeneralHarmonic(n, s), d.Probability(x));
@ -224,8 +242,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="s">S parameter.</param>
/// <param name="n">N parameter.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateProbabilityLn([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n, [Values(1, 15)] int x)
[TestCase(0.1, 1, 1)]
[TestCase(1, 20, 15)]
[TestCase(1, 50, 20)]
public void ValidateProbabilityLn(double s, int n, int x)
{
var d = new Zipf(s, n);
Assert.AreEqual(Math.Log(d.Probability(x)), d.ProbabilityLn(x));
@ -265,8 +285,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Discrete
/// <param name="s">S parameter.</param>
/// <param name="n">N parameter.</param>
/// <param name="x">Input X value.</param>
[Test, Combinatorial]
public void ValidateCumulativeDistribution([Values(0.1, 1)] double s, [Values(1, 20, 50)] int n, [Values(2, 15)] int x)
[TestCase(0.1, 1, 2)]
[TestCase(1, 20, 15)]
[TestCase(1, 50, 20)]
public void ValidateCumulativeDistribution(double s, int n, int x)
{
var d = new Zipf(s, n);
var cdf = SpecialFunctions.GeneralHarmonic(x, s) / SpecialFunctions.GeneralHarmonic(n, s);

15
src/UnitTests/DistributionTests/Multivariate/DirichletTests.cs

@ -202,8 +202,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="x">Alphas array.</param>
/// <param name="res">Expected value.</param>
[Test, Sequential]
public void ValidateDensity([Values(new[] { 0.01, 0.03, 0.5 }, new[] { 0.1, 0.2, 0.3, 0.4 })] double[] x, [Values(1335.32600710379, 59.1446044600076)] double res)
[TestCase(new[] { 0.01, 0.03, 0.5 }, 1335.32600710379)]
[TestCase(new[] { 0.1, 0.2, 0.3, 0.4 }, 59.1446044600076)]
public void ValidateDensity(double[] x, double res)
{
var d = new Dirichlet(new[] { 0.1, 0.3, 0.5, 0.8 });
AssertHelpers.AlmostEqual(res, d.Density(x), 12);
@ -213,8 +214,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// Validate density log.
/// </summary>
/// <param name="x">Alpha array.</param>
[Test]
public void ValidateDensityLn([Values(new[] { 0.01, 0.03, 0.5 }, new[] { 0.1, 0.2, 0.3, 0.4 })] double[] x)
[TestCase(new[] { 0.01, 0.03, 0.5, 0.5 })]
[TestCase(new[] { 0.1, 0.2, 0.3, 0.4 })]
public void ValidateDensityLn(double[] x)
{
var d = new Dirichlet(new[] { 0.1, 0.3, 0.5, 0.8 });
AssertHelpers.AlmostEqual(d.DensityLn(x), Math.Log(d.Density(x)), 12);
@ -224,8 +226,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// Validate entropy.
/// </summary>
/// <param name="x">Alpha array.</param>
[Test]
public void ValidateEntropy([Values(new[] { 0.1, 0.3, 0.5, 0.8 }, new[] { 0.1, 0.2, 0.3, 0.4 })] double[] x)
[TestCase(new[] { 0.1, 0.3, 0.5, 0.8 })]
[TestCase(new[] { 0.1, 0.2, 0.3, 0.4 })]
public void ValidateEntropy(double[] x)
{
var d = new Dirichlet(x);

55
src/UnitTests/DistributionTests/Multivariate/InverseWishartTests.cs

@ -1,4 +1,4 @@
// <copyright file="InverseWishartTests.cs" company="Math.NET">
// <copyright file="InverseWishartTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -52,8 +52,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void CanCreateInverseWishart([Values(0.1, 1.0, 5.0)] double nu, [Values(2, 5)] int order)
[TestCase(0.1, 2)]
[TestCase(1.0, 5)]
[TestCase(5.0, 5)]
public void CanCreateInverseWishart(double nu, int order)
{
var matrix = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order);
var d = new InverseWishart(nu, matrix);
@ -73,8 +75,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void FailSCreateInverseWishart([Values(0.1, 1.0, 5.0)] double nu, [Values(2, 5)] int order)
[TestCase(0.1, 2)]
[TestCase(1.0, 5)]
[TestCase(5.0, 5)]
public void FailSCreateInverseWishart(double nu, int order)
{
var matrix = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order);
matrix[0, 0] = 0.0;
@ -87,8 +91,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void FailNuCreateInverseWishart([Values(-1.0, Double.NaN)] double nu, [Values(2, 5)] int order)
[TestCase(-1.0, 2)]
[TestCase(Double.NaN, 5)]
public void FailNuCreateInverseWishart(double nu, int order)
{
var matrix = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order);
Assert.Throws<ArgumentOutOfRangeException>(() => new InverseWishart(nu, matrix));
@ -140,8 +145,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// Can get Nu.
/// </summary>
/// <param name="nu">Nu parameter.</param>
[Test]
public void CanGetNu([Values(1.0, 2.0, 5.0)] double nu)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(5.0)]
public void CanGetNu(double nu)
{
var d = new InverseWishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2));
Assert.AreEqual(nu, d.Nu);
@ -151,8 +158,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// Can set Nu.
/// </summary>
/// <param name="nu">Nu parameter.</param>
[Test]
public void CanSetNu([Values(1.0, 2.0, 5.0)] double nu)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(5.0)]
public void CanSetNu(double nu)
{
new InverseWishart(1.0, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2))
{
@ -196,8 +205,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void ValidateMean([Values(0.1, 1.0, 5.0)] double nu, [Values(2, 5)] int order)
[TestCase(0.1, 2)]
[TestCase(1.0, 5)]
[TestCase(5.0, 5)]
public void ValidateMean(double nu, int order)
{
var d = new InverseWishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order));
@ -216,8 +227,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void ValidateMode([Values(0.1, 1.0, 5.0)] double nu, [Values(2, 5)] int order)
[TestCase(0.1, 2)]
[TestCase(1.0, 5)]
[TestCase(5.0, 5)]
public void ValidateMode(double nu, int order)
{
var d = new InverseWishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order));
@ -236,8 +249,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void ValidateVariance([Values(0.1, 1.0, 5.0)] double nu, [Values(2, 5)] int order)
[TestCase(0.1, 2)]
[TestCase(1.0, 5)]
[TestCase(5.0, 5)]
public void ValidateVariance(double nu, int order)
{
var d = new InverseWishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order));
@ -258,8 +273,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="density">Expected value.</param>
[Test, Sequential]
public void ValidateDensity([Values(1.0, 2.0, 5.0)] double nu, [Values(0.03228684517430723, 0.018096748360719193, 0.00043049126899076171)] double density)
[TestCase(1.0, 0.03228684517430723)]
[TestCase(2.0, 0.018096748360719193)]
[TestCase(5.0, 0.00043049126899076171)]
public void ValidateDensity(double nu, double density)
{
const int Order = 1;
var matrix = new DenseMatrix(Order);

90
src/UnitTests/DistributionTests/Multivariate/MatrixNormalTests.cs

@ -1,4 +1,4 @@
// <copyright file="MatrixNormalTests.cs" company="Math.NET">
// <copyright file="MatrixNormalTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -43,8 +43,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="n">Matrix rows count.</param>
/// <param name="p">Matrix columns count.</param>
[Test, Combinatorial]
public void CanCreateMatrixNormal([Values(1, 3, 10)] int n, [Values(1, 3, 10)] int p)
[TestCase(1, 1)]
[TestCase(3, 3)]
[TestCase(10, 10)]
public void CanCreateMatrixNormal(int n, int p)
{
var matrixM = MatrixLoader.GenerateRandomDenseMatrix(n, p);
var matrixV = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n);
@ -85,14 +87,15 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="columnsOfV">Covariance matrix columns.</param>
/// <param name="rowsOfK">Covariance matrix rows (for columns)</param>
/// <param name="columnsOfK">Covariance matrix columns (for columns)</param>
[Test, Sequential]
public void FailCreateMatrixNormal(
[Values(2, 2, 2, 2, 5, 5, 5, 5)] int rowsOfM,
[Values(2, 2, 2, 2, 2, 2, 2, 2)] int columnsOfM,
[Values(3, 2, 2, 2, 6, 5, 5, 5)] int rowsOfV,
[Values(2, 3, 2, 2, 5, 6, 5, 5)] int columnsOfV,
[Values(2, 2, 3, 2, 2, 2, 3, 2)] int rowsOfK,
[Values(2, 2, 2, 3, 2, 2, 2, 3)] int columnsOfK)
[TestCase(2, 2, 3, 2, 2, 2)]
[TestCase(2, 2, 2, 3, 2, 2)]
[TestCase(2, 2, 2, 2, 3, 2)]
[TestCase(2, 2, 2, 2, 2, 3)]
[TestCase(5, 2, 6, 5, 2, 2)]
[TestCase(5, 2, 5, 6, 2, 2)]
[TestCase(5, 2, 5, 5, 3, 2)]
[TestCase(5, 2, 5, 5, 2, 3)]
public void FailCreateMatrixNormal(int rowsOfM, int columnsOfM, int rowsOfV, int columnsOfV, int rowsOfK, int columnsOfK)
{
var matrixM = MatrixLoader.GenerateRandomDenseMatrix(rowsOfM, columnsOfM);
var matrixV = MatrixLoader.GenerateRandomDenseMatrix(rowsOfV, columnsOfV);
@ -156,8 +159,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="n">Matrix rows count.</param>
/// <param name="p">Matrix columns count.</param>
[Test, Combinatorial]
public void CanGetM([Values(1, 3, 10)] int n, [Values(1, 3, 10)] int p)
[TestCase(1, 1)]
[TestCase(3, 3)]
[TestCase(10, 10)]
public void CanGetM(int n, int p)
{
var matrixM = MatrixLoader.GenerateRandomDenseMatrix(n, p);
var d = new MatrixNormal(matrixM, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
@ -175,8 +180,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="n">Matrix rows count.</param>
/// <param name="p">Matrix columns count.</param>
[Test, Combinatorial]
public void CanSetM([Values(1, 3, 10)] int n, [Values(1, 3, 10)] int p)
[TestCase(1, 1)]
[TestCase(3, 3)]
[TestCase(10, 10)]
public void CanSetM(int n, int p)
{
new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p))
{
@ -189,8 +196,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="n">Matrix rows count.</param>
/// <param name="p">Matrix columns count.</param>
[Test, Combinatorial]
public void CanGetV([Values(1, 3, 10)] int n, [Values(1, 3, 10)] int p)
[TestCase(1, 1)]
[TestCase(3, 3)]
[TestCase(10, 10)]
public void CanGetV(int n, int p)
{
var matrixV = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n);
var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), matrixV, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
@ -208,8 +217,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="n">Matrix rows count.</param>
/// <param name="p">Matrix columns count.</param>
[Test, Combinatorial]
public void CanSetV([Values(1, 3, 10)] int n, [Values(1, 3, 10)] int p)
[TestCase(1, 1)]
[TestCase(3, 3)]
[TestCase(10, 10)]
public void CanSetV(int n, int p)
{
new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p))
{
@ -222,8 +233,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="n">Matrix rows count.</param>
/// <param name="p">Matrix columns count.</param>
[Test, Combinatorial]
public void CanGetK([Values(1, 3, 10)] int n, [Values(1, 3, 10)] int p)
[TestCase(1, 1)]
[TestCase(3, 3)]
[TestCase(10, 10)]
public void CanGetK(int n, int p)
{
var matrixK = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p);
var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), matrixK);
@ -241,8 +254,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="n">Matrix rows count.</param>
/// <param name="p">Matrix columns count.</param>
[Test, Combinatorial]
public void CanSetK([Values(1, 3, 10)] int n, [Values(1, 3, 10)] int p)
[TestCase(1, 1)]
[TestCase(3, 3)]
[TestCase(10, 10)]
public void CanSetK(int n, int p)
{
new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p))
{
@ -289,8 +304,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="n">Matrix rows count.</param>
/// <param name="p">Matrix columns count.</param>
[Test, Sequential]
public void CanSample([Values(1, 3, 10)] int n, [Values(1, 3, 10)] int p)
[TestCase(1, 1)]
[TestCase(3, 3)]
[TestCase(10, 10)]
public void CanSample(int n, int p)
{
var d = new MatrixNormal(MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
d.Sample();
@ -301,8 +318,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="n">Matrix rows count.</param>
/// <param name="p">Matrix columns count.</param>
[Test, Sequential]
public void CanSampleStatic([Values(1, 3, 10)] int n, [Values(1, 3, 10)] int p)
[TestCase(1, 1)]
[TestCase(3, 3)]
[TestCase(10, 10)]
public void CanSampleStatic(int n, int p)
{
MatrixNormal.Sample(new Random(), MatrixLoader.GenerateRandomDenseMatrix(n, p), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(n), MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(p));
}
@ -316,14 +335,15 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="columnsOfV">Covariance matrix columns.</param>
/// <param name="rowsOfK">Covariance matrix rows (for columns)</param>
/// <param name="columnsOfK">Covariance matrix columns (for columns)</param>
[Test, Sequential]
public void FailSampleStatic(
[Values(2, 2, 2, 2, 5, 5, 5, 5)] int rowsOfM,
[Values(2, 2, 2, 2, 2, 2, 2, 2)] int columnsOfM,
[Values(3, 2, 2, 2, 6, 5, 5, 5)] int rowsOfV,
[Values(2, 3, 2, 2, 5, 6, 5, 5)] int columnsOfV,
[Values(2, 2, 3, 2, 2, 2, 3, 2)] int rowsOfK,
[Values(2, 2, 2, 3, 2, 2, 2, 3)] int columnsOfK)
[TestCase(2, 2, 3, 2, 2, 2)]
[TestCase(2, 2, 2, 3, 2, 2)]
[TestCase(2, 2, 2, 2, 3, 2)]
[TestCase(2, 2, 2, 2, 2, 3)]
[TestCase(5, 2, 6, 5, 2, 2)]
[TestCase(5, 2, 5, 6, 2, 2)]
[TestCase(5, 2, 5, 5, 3, 2)]
[TestCase(5, 2, 5, 5, 2, 3)]
public void FailSampleStatic(int rowsOfM, int columnsOfM, int rowsOfV, int columnsOfV, int rowsOfK, int columnsOfK)
{
Assert.Throws<ArgumentOutOfRangeException>(() => MatrixNormal.Sample(new Random(), MatrixLoader.GenerateRandomDenseMatrix(rowsOfM, columnsOfM), MatrixLoader.GenerateRandomDenseMatrix(rowsOfV, columnsOfV), MatrixLoader.GenerateRandomDenseMatrix(rowsOfK, columnsOfK)));
}

42
src/UnitTests/DistributionTests/Multivariate/MultinomialTests.cs

@ -141,11 +141,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="p">Proportion of ratios.</param>
/// <param name="n">Number of trials.</param>
/// <param name="res">Expected value.</param>
[Test, Sequential]
public void ValidateSkewness(
[Values(new[] { 0.3, 0.7 }, new[] { 0.1, 0.3, 0.6 }, new[] { 0.15, 0.35, 0.3, 0.2 })] double[] p,
[Values(5, 10, 20)] int n,
[Values(new[] { 0.390360029179413, -0.390360029179413 }, new[] { 0.843274042711568, 0.276026223736942, -0.129099444873581 }, new[] { 0.438357003759605, 0.140642169281549, 0.195180014589707, 0.335410196624968 })] double[] res)
[TestCase(new[] { 0.3, 0.7 }, 5, new[] { 0.390360029179413, -0.390360029179413 })]
[TestCase(new[] { 0.1, 0.3, 0.6 }, 10, new[] { 0.843274042711568, 0.276026223736942, -0.129099444873581 })]
[TestCase(new[] { 0.15, 0.35, 0.3, 0.2 }, 20, new[] { 0.438357003759605, 0.140642169281549, 0.195180014589707, 0.335410196624968 })]
public void ValidateSkewness(double[] p, int n, double[] res)
{
var b = new Multinomial(p, n);
for (var i = 0; i < b.P.Length; i++)
@ -160,11 +159,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="p">Proportion of ratios.</param>
/// <param name="n">Number of trials.</param>
/// <param name="res">Expected value.</param>
[Test, Sequential]
public void ValidateVariance(
[Values(new[] { 0.3, 0.7 }, new[] { 0.1, 0.3, 0.6 }, new[] { 0.15, 0.35, 0.3, 0.2 })] double[] p,
[Values(5, 10, 20)] int n,
[Values(new[] { 1.05, 1.05 }, new[] { 0.9, 2.1, 2.4 }, new[] { 2.55, 4.55, 4.2, 3.2 })] double[] res)
[TestCase(new[] { 0.3, 0.7 }, 5, new[] { 1.05, 1.05 })]
[TestCase(new[] { 0.1, 0.3, 0.6 }, 10, new[] { 0.9, 2.1, 2.4 })]
[TestCase(new[] { 0.15, 0.35, 0.3, 0.2 }, 20, new[] { 2.55, 4.55, 4.2, 3.2 })]
public void ValidateVariance(double[] p, int n, double[] res)
{
var b = new Multinomial(p, n);
for (var i = 0; i < b.P.Length; i++)
@ -179,11 +177,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="p">Proportion of ratios.</param>
/// <param name="n">Number of trials.</param>
/// <param name="res">Expected value.</param>
[Test, Sequential]
public void ValidateMean(
[Values(new[] { 0.3, 0.7 }, new[] { 0.1, 0.3, 0.6 }, new[] { 0.15, 0.35, 0.3, 0.2 })] double[] p,
[Values(5, 10, 20)] int n,
[Values(new[] { 1.5, 3.5 }, new[] { 1.0, 3.0, 6.0 }, new[] { 3.0, 7.0, 6.0, 4.0 })] double[] res)
[TestCase(new[] { 0.3, 0.7 }, 5, new[] { 1.5, 3.5 })]
[TestCase(new[] { 0.1, 0.3, 0.6 }, 10, new[] { 1.0, 3.0, 6.0 })]
[TestCase(new[] { 0.15, 0.35, 0.3, 0.2 }, 20, new[] { 3.0, 7.0, 6.0, 4.0 })]
public void ValidateMean(double[] p, int n, double[] res)
{
var b = new Multinomial(p, n);
for (var i = 0; i < b.P.Length; i++)
@ -198,11 +195,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="p">Proportion of ratios.</param>
/// <param name="x">Input X value.</param>
/// <param name="res">Expected value.</param>
[Test, Sequential]
public void ValidateProbability(
[Values(new[] { 0.3, 0.7 }, new[] { 0.1, 0.3, 0.6 }, new[] { 0.15, 0.35, 0.3, 0.2 })] double[] p,
[Values(new[] { 1, 9 }, new[] { 1, 3, 6 }, new[] { 1, 1, 1, 7 })] int[] x,
[Values(0.121060821, 0.105815808, 0.000145152)] double res)
[TestCase(new[] { 0.3, 0.7 }, new[] { 1, 9 }, 0.121060821)]
[TestCase(new[] { 0.1, 0.3, 0.6 }, new[] { 1, 3, 6 }, 0.105815808)]
[TestCase(new[] { 0.15, 0.35, 0.3, 0.2 }, new[] { 1, 1, 1, 7 }, 0.000145152)]
public void ValidateProbability(double[] p, int[] x, double res)
{
var b = new Multinomial(p, x.Sum());
AssertHelpers.AlmostEqual(b.Probability(x), res, 12);
@ -212,8 +208,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// Validate probability log.
/// </summary>
/// <param name="x">Input X value.</param>
[Test, Sequential]
public void ValidateProbabilityLn([Values(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, new[] { 1, 1, 1, 2, 2, 2, 3, 3, 3 }, new[] { 5, 6, 7, 8, 7, 6, 5, 4, 3 })] int[] x)
[TestCase(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 })]
[TestCase(new[] { 1, 1, 1, 2, 2, 2, 3, 3, 3 })]
[TestCase(new[] { 5, 6, 7, 8, 7, 6, 5, 4, 3 })]
public void ValidateProbabilityLn(int[] x)
{
var b = new Multinomial(_largeP, x.Sum());
AssertHelpers.AlmostEqual(b.ProbabilityLn(x), Math.Log(b.Probability(x)), 12);

100
src/UnitTests/DistributionTests/Multivariate/NormalGammaTests.cs

@ -44,8 +44,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Combinatorial]
public void CanCreateNormalGamma([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 2.0, 2.0, 2.0)]
public void CanCreateNormalGamma(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
@ -62,8 +63,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Sequential]
public void CanGetDensityAndDensityLn([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 1.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 1.0, 2.0, 2.0)]
public void CanGetDensityAndDensityLn(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
Assert.AreEqual(ng.DensityLn(meanLocation, precShape), Math.Log(ng.Density(meanLocation, precShape)), 1e-14);
@ -87,8 +89,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Combinatorial]
public void CanGetMeanLocation([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 2.0, 2.0, 2.0)]
public void CanGetMeanLocation(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
Assert.AreEqual(meanLocation, ng.MeanLocation);
@ -101,8 +104,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Combinatorial]
public void CanSetMeanLocation([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 2.0, 2.0, 2.0)]
public void CanSetMeanLocation(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale)
{
@ -122,8 +126,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Combinatorial]
public void CanGetMeanScale([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 2.0, 2.0, 2.0)]
public void CanGetMeanScale(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
Assert.AreEqual(meanScale, ng.MeanScale);
@ -136,8 +141,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Combinatorial]
public void CanSetMeanScale([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 2.0, 2.0, 2.0)]
public void CanSetMeanScale(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale)
{
@ -156,8 +162,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Combinatorial]
public void CanGetPrecisionShape([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 2.0, 2.0, 2.0)]
public void CanGetPrecisionShape(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
Assert.AreEqual(precShape, ng.PrecisionShape);
@ -170,8 +177,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Combinatorial]
public void CanSetPrecisionShape([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 2.0, 2.0, 2.0)]
public void CanSetPrecisionShape(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale)
{
@ -190,8 +198,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Combinatorial]
public void CanGetPrecisionInverseScale([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 2.0, 2.0, 2.0)]
public void CanGetPrecisionInverseScale(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
Assert.AreEqual(precInvScale, ng.PrecisionInverseScale);
@ -204,8 +213,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Combinatorial]
public void CanSetPrecisionPrecisionInverseScale([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 2.0, 2.0, 2.0)]
public void CanSetPrecisionPrecisionInverseScale(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale)
{
@ -227,8 +237,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanMarginalMean">Mean marginal mean.</param>
/// <param name="meanMarginalScale">Mean marginal scale.</param>
/// <param name="meanMarginalDoF">Mean marginal degrees of freedom.</param>
[Test, Sequential]
public void CanGetMeanMarginal([Values(0.0, 10.0, 10.0)] double meanLocation, [Values(1.0, 1.0, 1.0)] double meanScale, [Values(1.0, 2.0, 2.0)] double precShape, [Values(1.0, 2.0, Double.PositiveInfinity)] double precInvScale, [Values(0.0, 10.0, 10.0)] double meanMarginalMean, [Values(1.0, 1.0, 0.5)] double meanMarginalScale, [Values(2.0, 4.0, Double.PositiveInfinity)] double meanMarginalDoF)
[TestCase(0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 2.0)]
[TestCase(10.0, 1.0, 2.0, 2.0, 10.0, 1.0, 4.0)]
[TestCase(10.0, 1.0, 2.0, Double.PositiveInfinity, 10.0, 0.5, Double.PositiveInfinity)]
public void CanGetMeanMarginal(double meanLocation, double meanScale, double precShape, double precInvScale, double meanMarginalMean, double meanMarginalScale, double meanMarginalDoF)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
var mm = ng.MeanMarginal();
@ -244,8 +256,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Combinatorial]
public void CanGetPrecisionMarginal([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0, Double.PositiveInfinity)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 2.0, 2.0, 2.0)]
[TestCase(10.0, 2.0, 2.0, Double.PositiveInfinity)]
public void CanGetPrecisionMarginal(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
var pm = ng.PrecisionMarginal();
@ -262,8 +276,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="precInvScale">Precision inverse scale.</param>
/// <param name="meanMean">Mean value.</param>
/// <param name="meanPrecision">Mean precision.</param>
[Test, Sequential]
public void CanGetMean([Values(0.0, 10.0, 10.0)] double meanLocation, [Values(1.0, 1.0, 1.0)] double meanScale, [Values(1.0, 2.0, 2.0)] double precShape, [Values(1.0, 2.0, Double.PositiveInfinity)] double precInvScale, [Values(0.0, 10.0, 10.0)] double meanMean, [Values(1.0, 1.0, 2.0)] double meanPrecision)
[TestCase(0.0, 1.0, 1.0, 1.0, 0.0, 1.0)]
[TestCase(10.0, 1.0, 2.0, 2.0, 10.0, 1.0)]
[TestCase(10.0, 1.0, 2.0, Double.PositiveInfinity, 10.0, 2.0)]
public void CanGetMean(double meanLocation, double meanScale, double precShape, double precInvScale, double meanMean, double meanPrecision)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
Assert.AreEqual(meanMean, ng.Mean.Mean);
@ -299,8 +315,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// <param name="meanScale">Mean scale.</param>
/// <param name="precShape">Precision shape.</param>
/// <param name="precInvScale">Precision inverse scale.</param>
[Test, Combinatorial]
public void ValidateVariance([Values(0.0, 10.0)] double meanLocation, [Values(1.0, 2.0)] double meanScale, [Values(1.0, 2.0)] double precShape, [Values(1.0, 2.0, Double.PositiveInfinity)] double precInvScale)
[TestCase(0.0, 1.0, 1.0, 1.0)]
[TestCase(10.0, 2.0, 2.0, 2.0)]
[TestCase(10.9, 2.0, 2.0, Double.PositiveInfinity)]
public void ValidateVariance(double meanLocation, double meanScale, double precShape, double precInvScale)
{
var ng = new NormalGamma(meanLocation, meanScale, precShape, precInvScale);
var x = precInvScale / (meanScale * (precShape - 1));
@ -332,16 +350,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
// Check the precision distribution.
CommonDistributionTests.VapnikChervonenkisTest(
CommonDistributionTests.Error,
CommonDistributionTests.ErrorProbability,
precs,
CommonDistributionTests.Error,
CommonDistributionTests.ErrorProbability,
precs,
precMarginal);
// Check the mean distribution.
CommonDistributionTests.VapnikChervonenkisTest(
CommonDistributionTests.Error,
CommonDistributionTests.ErrorProbability,
means,
CommonDistributionTests.Error,
CommonDistributionTests.ErrorProbability,
means,
meanMarginal);
}
@ -364,16 +382,16 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
// Check the precision distribution.
CommonDistributionTests.VapnikChervonenkisTest(
CommonDistributionTests.Error,
CommonDistributionTests.ErrorProbability,
precs,
CommonDistributionTests.Error,
CommonDistributionTests.ErrorProbability,
precs,
precMarginal);
// Check the mean distribution.
CommonDistributionTests.VapnikChervonenkisTest(
CommonDistributionTests.Error,
CommonDistributionTests.ErrorProbability,
means,
CommonDistributionTests.Error,
CommonDistributionTests.ErrorProbability,
means,
meanMarginal);
}
}

56
src/UnitTests/DistributionTests/Multivariate/WishartTests.cs

@ -1,4 +1,4 @@
// <copyright file="WishartTests.cs" company="Math.NET">
// <copyright file="WishartTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -52,8 +52,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void CanCreateWishart([Values(0.1, 1.0, 5.0)] double nu, [Values(2, 5)] int order)
[TestCase(0.1, 2)]
[TestCase(1.0, 5)]
[TestCase(5.0, 5)]
public void CanCreateWishart(double nu, int order)
{
var matrix = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order);
@ -74,8 +76,11 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void FailSCreateWishart([Values(0.0, 0.1, 1.0, 5.0)] double nu, [Values(2, 5)] int order)
[TestCase(0.0, 2)]
[TestCase(0.1, 5)]
[TestCase(1.0, 2)]
[TestCase(5.0, 5)]
public void FailSCreateWishart(double nu, int order)
{
var matrix = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order);
matrix[0, 0] = 0.0;
@ -88,8 +93,9 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void FailNuCreateWishart([Values(-1.0, Double.NaN)] double nu, [Values(2, 5)] int order)
[TestCase(-1.0, 2)]
[TestCase(Double.NaN, 5)]
public void FailNuCreateWishart(double nu, int order)
{
var matrix = MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order);
Assert.Throws<ArgumentOutOfRangeException>(() => new InverseWishart(nu, matrix));
@ -141,8 +147,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// Can get Nu.
/// </summary>
/// <param name="nu">Nu parameter.</param>
[Test]
public void CanGetNu([Values(1.0, 2.0, 5.0)] double nu)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(5.0)]
public void CanGetNu(double nu)
{
var d = new Wishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2));
Assert.AreEqual(nu, d.Nu);
@ -152,8 +160,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// Can set Nu.
/// </summary>
/// <param name="nu">Nu parameter.</param>
[Test]
public void CanSetNu([Values(1.0, 2.0, 5.0)] double nu)
[TestCase(1.0)]
[TestCase(2.0)]
[TestCase(5.0)]
public void CanSetNu(double nu)
{
new Wishart(1.0, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(2))
{
@ -197,8 +207,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void ValidateMean([Values(0.1, 1.0, 5.0)] double nu, [Values(2, 5)] int order)
[TestCase(0.1, 2)]
[TestCase(1.0, 5)]
[TestCase(5.0, 5)]
public void ValidateMean(double nu, int order)
{
var d = new Wishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order));
@ -217,8 +229,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void ValidateMode([Values(0.1, 1.0, 5.0)] double nu, [Values(2, 5)] int order)
[TestCase(0.1, 2)]
[TestCase(1.0, 5)]
[TestCase(5.0, 5)]
public void ValidateMode(double nu, int order)
{
var d = new Wishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order));
@ -237,8 +251,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="order">Scale matrix order.</param>
[Test, Combinatorial]
public void ValidateVariance([Values(0.1, 1.0, 5.0)] double nu, [Values(2, 5)] int order)
[TestCase(0.1, 2)]
[TestCase(1.0, 5)]
[TestCase(5.0, 5)]
public void ValidateVariance(double nu, int order)
{
var d = new Wishart(nu, MatrixLoader.GenerateRandomPositiveDefiniteDenseMatrix(order));
@ -257,8 +273,10 @@ namespace MathNet.Numerics.UnitTests.DistributionTests.Multivariate
/// </summary>
/// <param name="nu">Nu parameter.</param>
/// <param name="density">Expected value.</param>
[Test, Sequential]
public void ValidateDensity([Values(1.0, 2.0, 5.0)] double nu, [Values(0.014644982561926487, 0.041042499311949421, 0.12204152134938706)] double density)
[TestCase(1.0, 0.014644982561926487)]
[TestCase(2.0, 0.041042499311949421)]
[TestCase(5.0, 0.12204152134938706)]
public void ValidateDensity(double nu, double density)
{
const int Order = 1;
var matrix = new DenseMatrix(Order);

10
src/UnitTests/IntegralTransformsTests/FourierTest.cs

@ -1,4 +1,4 @@
// <copyright file="FourierTest.cs" company="Math.NET">
// <copyright file="FourierTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -92,18 +92,18 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
var dft = new DiscreteFourierTransform();
Assert.Throws(
typeof(ArgumentException),
typeof(ArgumentException),
() => dft.Radix2Forward(samples, FourierOptions.Default));
Assert.Throws(
typeof(ArgumentException),
typeof(ArgumentException),
() => dft.Radix2Inverse(samples, FourierOptions.Default));
Assert.Throws(
typeof(ArgumentException),
typeof(ArgumentException),
() => DiscreteFourierTransform.Radix2(samples, -1));
Assert.Throws(
typeof(ArgumentException),
typeof(ArgumentException),
() => DiscreteFourierTransform.Radix2Parallel(samples, -1));
}
}

36
src/UnitTests/IntegralTransformsTests/HartleyTest.cs

@ -1,4 +1,4 @@
// <copyright file="HartleyTest.cs" company="Math.NET">
// <copyright file="HartleyTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -54,17 +54,17 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// <param name="dft">DFT function delegate.</param>
/// <param name="hartley">Hartley transform delegate.</param>
private static void VerifyMatchesDft(
double[] samples,
double maximumError,
bool inverse,
Action<Complex[]> dft,
double[] samples,
double maximumError,
bool inverse,
Action<Complex[]> dft,
Func<double[], double[]> hartley)
{
var hartleyReal = hartley(samples);
var fourierComplex = Array.ConvertAll(samples, s => new Complex(s, inverse ? -s : s));
var fourierComplex = ArrayHelpers.ConvertAll(samples, s => new Complex(s, inverse ? -s : s));
dft(fourierComplex);
var fourierReal = Array.ConvertAll(fourierComplex, s => s.Real);
var fourierReal = ArrayHelpers.ConvertAll(fourierComplex, s => s.Real);
AssertHelpers.AlmostEqualList(fourierReal, hartleyReal, maximumError);
}
@ -74,23 +74,25 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// </summary>
/// <param name="hartleyOptions">Hartley transformation options.</param>
/// <param name="fourierOptions">Fourier transformation options.</param>
[Test, Sequential]
public void NaiveMatchesDft([Values(HartleyOptions.Default, HartleyOptions.AsymmetricScaling, HartleyOptions.NoScaling)] HartleyOptions hartleyOptions, [Values(FourierOptions.Default, FourierOptions.AsymmetricScaling, FourierOptions.NoScaling)] FourierOptions fourierOptions)
[TestCase(HartleyOptions.Default, FourierOptions.Default)]
[TestCase(HartleyOptions.AsymmetricScaling, FourierOptions.AsymmetricScaling)]
[TestCase(HartleyOptions.NoScaling, FourierOptions.NoScaling)]
public void NaiveMatchesDft(HartleyOptions hartleyOptions, FourierOptions fourierOptions)
{
var dht = new DiscreteHartleyTransform();
var samples = SignalGenerator.Random(x => x, _uniform, 0x80);
VerifyMatchesDft(
samples,
1e-5,
false,
s => Transform.FourierForward(s, fourierOptions),
samples,
1e-5,
false,
s => Transform.FourierForward(s, fourierOptions),
s => dht.NaiveForward(s, hartleyOptions));
VerifyMatchesDft(
samples,
1e-5,
true,
s => Transform.FourierInverse(s, fourierOptions),
samples,
1e-5,
true,
s => Transform.FourierInverse(s, fourierOptions),
s => dht.NaiveInverse(s, hartleyOptions));
}
}

58
src/UnitTests/IntegralTransformsTests/InverseTransformTest.cs

@ -1,4 +1,4 @@
// <copyright file="InverseTransformTest.cs" company="Math.NET">
// <copyright file="InverseTransformTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -53,9 +53,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// <param name="forward">Forward delegate.</param>
/// <param name="inverse">Inverse delegate.</param>
private void VerifyIsReversibleComplex(
int count,
double maximumError,
Func<Complex[], Complex[]> forward,
int count,
double maximumError,
Func<Complex[], Complex[]> forward,
Func<Complex[], Complex[]> inverse)
{
var samples = SignalGenerator.Random((u, v) => new Complex(u, v), _uniform, count);
@ -79,9 +79,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// <param name="forward">Forward delegate.</param>
/// <param name="inverse">Inverse delegate.</param>
private void VerifyIsReversibleReal(
int count,
double maximumError,
Func<double[], double[]> forward,
int count,
double maximumError,
Func<double[], double[]> forward,
Func<double[], double[]> inverse)
{
var samples = SignalGenerator.Random(x => x, _uniform, count);
@ -101,15 +101,16 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// Fourier naive is reversible.
/// </summary>
/// <param name="options">Fourier options.</param>
[Test]
public void FourierNaiveIsReversible([Values(FourierOptions.Default, FourierOptions.Matlab)] FourierOptions options)
[TestCase(FourierOptions.Default)]
[TestCase(FourierOptions.Matlab)]
public void FourierNaiveIsReversible(FourierOptions options)
{
var dft = new DiscreteFourierTransform();
VerifyIsReversibleComplex(
0x80,
1e-12,
s => dft.NaiveForward(s, options),
0x80,
1e-12,
s => dft.NaiveForward(s, options),
s => dft.NaiveInverse(s, options));
}
@ -117,19 +118,20 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// Fourier radix2xx is reversible.
/// </summary>
/// <param name="options">Fourier options.</param>
[Test]
public void FourierRadix2IsReversible([Values(FourierOptions.Default, FourierOptions.Matlab)] FourierOptions options)
[TestCase(FourierOptions.Default)]
[TestCase(FourierOptions.Matlab)]
public void FourierRadix2IsReversible(FourierOptions options)
{
var dft = new DiscreteFourierTransform();
VerifyIsReversibleComplex(
0x8000,
1e-12,
0x8000,
1e-12,
s =>
{
dft.Radix2Forward(s, options);
return s;
},
},
s =>
{
dft.Radix2Inverse(s, options);
@ -141,19 +143,20 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// Fourier bluestein is reversible.
/// </summary>
/// <param name="options">Fourier options.</param>
[Test]
public void FourierBluesteinIsReversible([Values(FourierOptions.Default, FourierOptions.Matlab)] FourierOptions options)
[TestCase(FourierOptions.Default)]
[TestCase(FourierOptions.Matlab)]
public void FourierBluesteinIsReversible(FourierOptions options)
{
var dft = new DiscreteFourierTransform();
VerifyIsReversibleComplex(
0x7FFF,
1e-12,
0x7FFF,
1e-12,
s =>
{
dft.BluesteinForward(s, options);
return s;
},
},
s =>
{
dft.BluesteinInverse(s, options);
@ -165,15 +168,16 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// Hartley naive is reversible.
/// </summary>
/// <param name="options">Hartley options.</param>
[Test]
public void HartleyNaiveIsReversible([Values(HartleyOptions.Default, HartleyOptions.AsymmetricScaling)] HartleyOptions options)
[TestCase(HartleyOptions.Default)]
[TestCase(HartleyOptions.AsymmetricScaling)]
public void HartleyNaiveIsReversible(HartleyOptions options)
{
var dht = new DiscreteHartleyTransform();
VerifyIsReversibleReal(
0x80,
1e-9,
s => dht.NaiveForward(s, options),
0x80,
1e-9,
s => dht.NaiveForward(s, options),
s => dht.NaiveInverse(s, options));
}

98
src/UnitTests/IntegralTransformsTests/MatchingNaiveTransformTest.cs

@ -1,4 +1,4 @@
// <copyright file="MatchingNaiveTransformTest.cs" company="Math.NET">
// <copyright file="MatchingNaiveTransformTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -53,9 +53,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// <param name="naive">Naive transform.</param>
/// <param name="fast">Fast delegate.</param>
private static void VerifyMatchesNaiveComplex(
Complex[] samples,
double maximumError,
Func<Complex[], Complex[]> naive,
Complex[] samples,
double maximumError,
Func<Complex[], Complex[]> naive,
Action<Complex[]> fast)
{
var spectrumNaive = naive(samples);
@ -71,22 +71,24 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// Fourier Radix2XX matches naive on real sine.
/// </summary>
/// <param name="options">Fourier options.</param>
[Test]
public void FourierRadix2MatchesNaiveOnRealSine([Values(FourierOptions.Default, FourierOptions.Matlab, FourierOptions.NumericalRecipes)] FourierOptions options)
[TestCase(FourierOptions.Default)]
[TestCase(FourierOptions.Matlab)]
[TestCase(FourierOptions.NumericalRecipes)]
public void FourierRadix2MatchesNaiveOnRealSine(FourierOptions options)
{
var dft = new DiscreteFourierTransform();
var samples = SignalGenerator.EquidistantPeriodic(w => new Complex(Math.Sin(w), 0), Constants.Pi2, 0, 16);
VerifyMatchesNaiveComplex(
samples,
1e-12,
s => dft.NaiveForward(s, options),
samples,
1e-12,
s => dft.NaiveForward(s, options),
s => dft.Radix2Forward(s, options));
VerifyMatchesNaiveComplex(
samples,
1e-12,
s => dft.NaiveInverse(s, options),
samples,
1e-12,
s => dft.NaiveInverse(s, options),
s => dft.Radix2Inverse(s, options));
}
@ -94,22 +96,24 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// Fourier Radix2XX matches naive on random.
/// </summary>
/// <param name="options">Fourier options.</param>
[Test]
public void FourierRadix2MatchesNaiveOnRandom([Values(FourierOptions.Default, FourierOptions.Matlab, FourierOptions.NumericalRecipes)] FourierOptions options)
[TestCase(FourierOptions.Default)]
[TestCase(FourierOptions.Matlab)]
[TestCase(FourierOptions.NumericalRecipes)]
public void FourierRadix2MatchesNaiveOnRandom(FourierOptions options)
{
var dft = new DiscreteFourierTransform();
var samples = SignalGenerator.Random((u, v) => new Complex(u, v), _uniform, 0x80);
VerifyMatchesNaiveComplex(
samples,
1e-12,
s => dft.NaiveForward(s, options),
samples,
1e-12,
s => dft.NaiveForward(s, options),
s => dft.Radix2Forward(s, options));
VerifyMatchesNaiveComplex(
samples,
1e-12,
s => dft.NaiveInverse(s, options),
samples,
1e-12,
s => dft.NaiveInverse(s, options),
s => dft.Radix2Inverse(s, options));
}
@ -117,22 +121,24 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// Fourier bluestein matches naive on real sine non-power of two.
/// </summary>
/// <param name="options">Fourier options.</param>
[Test]
public void FourierBluesteinMatchesNaiveOnRealSineNonPowerOfTwo([Values(FourierOptions.Default, FourierOptions.Matlab, FourierOptions.NumericalRecipes)] FourierOptions options)
[TestCase(FourierOptions.Default)]
[TestCase(FourierOptions.Matlab)]
[TestCase(FourierOptions.NumericalRecipes)]
public void FourierBluesteinMatchesNaiveOnRealSineNonPowerOfTwo(FourierOptions options)
{
var dft = new DiscreteFourierTransform();
var samples = SignalGenerator.EquidistantPeriodic(w => new Complex(Math.Sin(w), 0), Constants.Pi2, 0, 14);
VerifyMatchesNaiveComplex(
samples,
1e-12,
s => dft.NaiveForward(s, options),
samples,
1e-12,
s => dft.NaiveForward(s, options),
s => dft.BluesteinForward(s, options));
VerifyMatchesNaiveComplex(
samples,
1e-12,
s => dft.NaiveInverse(s, options),
samples,
1e-12,
s => dft.NaiveInverse(s, options),
s => dft.BluesteinInverse(s, options));
}
@ -140,22 +146,24 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// Fourier bluestein matches naive on random power of two.
/// </summary>
/// <param name="options">Fourier options.</param>
[Test]
public void FourierBluesteinMatchesNaiveOnRandomPowerOfTwo([Values(FourierOptions.Default, FourierOptions.Matlab, FourierOptions.NumericalRecipes)] FourierOptions options)
[TestCase(FourierOptions.Default)]
[TestCase(FourierOptions.Matlab)]
[TestCase(FourierOptions.NumericalRecipes)]
public void FourierBluesteinMatchesNaiveOnRandomPowerOfTwo(FourierOptions options)
{
var dft = new DiscreteFourierTransform();
var samples = SignalGenerator.Random((u, v) => new Complex(u, v), _uniform, 0x80);
VerifyMatchesNaiveComplex(
samples,
1e-12,
s => dft.NaiveForward(s, options),
samples,
1e-12,
s => dft.NaiveForward(s, options),
s => dft.BluesteinForward(s, options));
VerifyMatchesNaiveComplex(
samples,
1e-12,
s => dft.NaiveInverse(s, options),
samples,
1e-12,
s => dft.NaiveInverse(s, options),
s => dft.BluesteinInverse(s, options));
}
@ -163,21 +171,23 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// Fourier bluestein matches naive on random non-power of two.
/// </summary>
/// <param name="options">Fourier options.</param>
[Test]
public void FourierBluesteinMatchesNaiveOnRandomNonPowerOfTwo([Values(FourierOptions.Default, FourierOptions.Matlab, FourierOptions.NumericalRecipes)] FourierOptions options)
[TestCase(FourierOptions.Default)]
[TestCase(FourierOptions.Matlab)]
[TestCase(FourierOptions.NumericalRecipes)]
public void FourierBluesteinMatchesNaiveOnRandomNonPowerOfTwo(FourierOptions options)
{
var dft = new DiscreteFourierTransform();
var samples = SignalGenerator.Random((u, v) => new Complex(u, v), _uniform, 0x7F);
VerifyMatchesNaiveComplex(
samples,
1e-12,
s => dft.NaiveForward(s, options),
samples,
1e-12,
s => dft.NaiveForward(s, options),
s => dft.BluesteinForward(s, options));
VerifyMatchesNaiveComplex(
samples,
1e-12,
s => dft.NaiveInverse(s, options),
samples,
1e-12,
s => dft.NaiveInverse(s, options),
s => dft.BluesteinInverse(s, options));
}
}

12
src/UnitTests/IntegralTransformsTests/ParsevalTheoremTest.cs

@ -1,4 +1,4 @@
// <copyright file="ParsevalTheoremTest.cs" company="Math.NET">
// <copyright file="ParsevalTheoremTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -50,8 +50,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// Fourier default transform satisfies parsevals theorem.
/// </summary>
/// <param name="count">Samples count.</param>
[Test]
public void FourierDefaultTransformSatisfiesParsevalsTheorem([Values(0x1000, 0x7FF)] int count)
[TestCase(0x1000)]
[TestCase(0x7FF)]
public void FourierDefaultTransformSatisfiesParsevalsTheorem(int count)
{
var samples = SignalGenerator.Random((u, v) => new Complex(u, v), _uniform, count);
@ -72,8 +73,9 @@ namespace MathNet.Numerics.UnitTests.IntegralTransformsTests
/// Hartley default naive satisfies parsevals theorem.
/// </summary>
/// <param name="count">Samples count.</param>
[Test]
public void HartleyDefaultNaiveSatisfiesParsevalsTheorem([Values(0x40, 0x1F)] int count)
[TestCase(0x40)]
[TestCase(0x1F)]
public void HartleyDefaultNaiveSatisfiesParsevalsTheorem(int count)
{
var samples = SignalGenerator.Random(x => x, _uniform, count);

85
src/UnitTests/IntegrationTests/IntegrationTest.cs

@ -1,4 +1,4 @@
// <copyright file="IntegrationTest.cs" company="Math.NET">
// <copyright file="IntegrationTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -69,15 +69,15 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
public void TestIntegratePortal()
{
Assert.AreEqual(
TargetAreaA,
Integrate.OnClosedInterval(TargetFunctionA, StartA, StopA),
1e-5,
TargetAreaA,
Integrate.OnClosedInterval(TargetFunctionA, StartA, StopA),
1e-5,
"Basic");
Assert.AreEqual(
TargetAreaA,
Integrate.OnClosedInterval(TargetFunctionA, StartA, StopA, 1e-10),
1e-10,
TargetAreaA,
Integrate.OnClosedInterval(TargetFunctionA, StartA, StopA, 1e-10),
1e-10,
"Basic Target 1e-10");
}
@ -85,16 +85,17 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
/// Test double exponential transformation algorithm.
/// </summary>
/// <param name="targetRelativeError">Relative error.</param>
[Test]
public void TestDoubleExponentialTransformationAlgorithm([Values(1e-5, 1e-13)] double targetRelativeError)
[TestCase(1e-5)]
[TestCase(1e-13)]
public void TestDoubleExponentialTransformationAlgorithm(double targetRelativeError)
{
var algorithm = new DoubleExponentialTransformation();
Assert.AreEqual(
TargetAreaA,
algorithm.Integrate(TargetFunctionA, StartA, StopA, targetRelativeError),
targetRelativeError * TargetAreaA,
"DET Adaptive {0}",
TargetAreaA,
algorithm.Integrate(TargetFunctionA, StartA, StopA, targetRelativeError),
targetRelativeError * TargetAreaA,
"DET Adaptive {0}",
targetRelativeError);
}
@ -105,9 +106,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
public void TrapeziumRuleSupportsTwoPointIntegration()
{
Assert.AreEqual(
TargetAreaA,
NewtonCotesTrapeziumRule.IntegrateTwoPoint(TargetFunctionA, StartA, StopA),
0.4 * TargetAreaA,
TargetAreaA,
NewtonCotesTrapeziumRule.IntegrateTwoPoint(TargetFunctionA, StartA, StopA),
0.4 * TargetAreaA,
"Direct (1 Partition)");
}
@ -116,14 +117,18 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
/// </summary>
/// <param name="partitions">Partitions count.</param>
/// <param name="maxRelativeError">Maximum relative error.</param>
[Test, Sequential]
public void TrapeziumRuleSupportsCompositeIntegration([Values(1, 5, 10, 50, 1000)] int partitions, [Values(3.5e-1, 1e-1, 2e-2, 6e-4, 1.5e-6)] double maxRelativeError)
[TestCase(1, 3.5e-1)]
[TestCase(5, 1e-1)]
[TestCase(10, 2e-2)]
[TestCase(50, 6e-4)]
[TestCase(1000, 1.5e-6)]
public void TrapeziumRuleSupportsCompositeIntegration(int partitions, double maxRelativeError)
{
Assert.AreEqual(
TargetAreaA,
NewtonCotesTrapeziumRule.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions),
maxRelativeError * TargetAreaA,
"Composite {0} Partitions",
TargetAreaA,
NewtonCotesTrapeziumRule.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions),
maxRelativeError * TargetAreaA,
"Composite {0} Partitions",
partitions);
}
@ -131,14 +136,16 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
/// Trapezium rule supports adaptive integration.
/// </summary>
/// <param name="targetRelativeError">Relative error</param>
[Test]
public void TrapeziumRuleSupportsAdaptiveIntegration([Values(1e-1, 1e-5, 1e-10)] double targetRelativeError)
[TestCase(1e-1)]
[TestCase(1e-5)]
[TestCase(1e-10)]
public void TrapeziumRuleSupportsAdaptiveIntegration(double targetRelativeError)
{
Assert.AreEqual(
TargetAreaA,
NewtonCotesTrapeziumRule.IntegrateAdaptive(TargetFunctionA, StartA, StopA, targetRelativeError),
targetRelativeError * TargetAreaA,
"Adaptive {0}",
TargetAreaA,
NewtonCotesTrapeziumRule.IntegrateAdaptive(TargetFunctionA, StartA, StopA, targetRelativeError),
targetRelativeError * TargetAreaA,
"Adaptive {0}",
targetRelativeError);
}
@ -149,9 +156,9 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
public void SimpsonRuleSupportsThreePointIntegration()
{
Assert.AreEqual(
TargetAreaA,
SimpsonRule.IntegrateThreePoint(TargetFunctionA, StartA, StopA),
0.2 * TargetAreaA,
TargetAreaA,
SimpsonRule.IntegrateThreePoint(TargetFunctionA, StartA, StopA),
0.2 * TargetAreaA,
"Direct (2 Partitions)");
}
@ -160,14 +167,18 @@ namespace MathNet.Numerics.UnitTests.IntegrationTests
/// </summary>
/// <param name="partitions">Partitions count.</param>
/// <param name="maxRelativeError">Maximum relative error.</param>
[Test, Sequential]
public void SimpsonRuleSupportsCompositeIntegration([Values(2, 6, 10, 50, 1000)] int partitions, [Values(1.7e-1, 1.2e-1, 8e-3, 8e-6, 5e-11)] double maxRelativeError)
[TestCase(2, 1.7e-1)]
[TestCase(6, 1.2e-1)]
[TestCase(10, 8e-3)]
[TestCase(50, 8e-6)]
[TestCase(1000, 5e-11)]
public void SimpsonRuleSupportsCompositeIntegration(int partitions, double maxRelativeError)
{
Assert.AreEqual(
TargetAreaA,
SimpsonRule.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions),
maxRelativeError * TargetAreaA,
"Composite {0} Partitions",
TargetAreaA,
SimpsonRule.IntegrateComposite(TargetFunctionA, StartA, StopA, partitions),
maxRelativeError * TargetAreaA,
"Composite {0} Partitions",
partitions);
}
}

41
src/UnitTests/InterpolationTests/AkimaSplineTest.cs

@ -1,4 +1,4 @@
// <copyright file="AkimaSplineTest.cs" company="Math.NET">
// <copyright file="AkimaSplineTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -34,11 +34,21 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>
/// AkimaSpline test case.
/// </summary>
[TestFixture]
public class AkimaSplineTest
{
readonly double[] _t = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 };
readonly double[] _x = new[] { 1.0, 2.0, -1.0, 0.0, 1.0 };
/// <summary>
/// Sample points.
/// </summary>
private readonly double[] _t = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 };
/// <summary>
/// Sample values.
/// </summary>
private readonly double[] _x = new[] { 1.0, 2.0, -1.0, 0.0, 1.0 };
/// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points.
@ -62,11 +72,19 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that at points other than the provided sample points, the interpolation matches the one computed by Maple as a reference.
/// </summary>
[Test, Sequential]
public void FitsAtArbitraryPointsWithMaple(
[Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t,
[Values(-0.52, 1.826, 0.25, -1.006, -0.9, -0.6, 0.2, 9, -151)] double x,
[Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15)] double maxAbsoluteError)
/// <param name="t">Sample point.</param>
/// <param name="x">Sample value.</param>
/// <param name="maxAbsoluteError">Maximum absolute error.</param>
[TestCase(-2.4, -0.52, 1e-15)]
[TestCase(-0.9, 1.826, 1e-15)]
[TestCase(-0.5, 0.25, 1e-15)]
[TestCase(-0.1, -1.006, 1e-15)]
[TestCase(0.1, -0.9, 1e-15)]
[TestCase(0.4, -0.6, 1e-15)]
[TestCase(1.2, 0.2, 1e-15)]
[TestCase(10.0, 9, 1e-15)]
[TestCase(-10.0, -151, 1e-15)]
public void FitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
{
IInterpolation interpolation = new AkimaSplineInterpolation(_t, _x);
@ -82,8 +100,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that the interpolation supports the linear case appropriately
/// </summary>
[Test]
public void SupportsLinearCase([Values(5, 7, 15)] int samples)
/// <param name="samples">Samples array.</param>
[TestCase(5)]
[TestCase(7)]
[TestCase(15)]
public void SupportsLinearCase(int samples)
{
double[] x, y, xtest, ytest;
LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples);

36
src/UnitTests/InterpolationTests/BulirschStoerRationalTest.cs

@ -1,4 +1,4 @@
// <copyright file="BulirschStoerRationalTest.cs" company="Math.NET">
// <copyright file="BulirschStoerRationalTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -34,11 +34,21 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>
/// BulirschStoerRational test case.
/// </summary>
[TestFixture]
public class BulirschStoerRationalTest
{
readonly double[] _t = new[] { 0d, 1, 3, 4, 5 };
readonly double[] _x = new[] { 0d, 3, 1000, -1000, 3 };
/// <summary>
/// Sample points.
/// </summary>
private readonly double[] _t = new[] { 0d, 1, 3, 4, 5 };
/// <summary>
/// Sample values.
/// </summary>
private readonly double[] _x = new[] { 0d, 3, 1000, -1000, 3 };
/// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points.
@ -57,16 +67,26 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that at points other than the provided sample points, the interpolation matches the one computed by Maple as a reference.
/// </summary>
/// <param name="t">Sample point.</param>
/// <param name="x">Sample value.</param>
/// <param name="maxAbsoluteError">Maximum absolute error.</param>
/// <remarks>
/// Maple:
/// with(CurveFitting);
/// evalf(subs({x=0.1},RationalInterpolation([[0,0],[1,3],[3,1000],[4,-1000], [5,3]], x)),20);
/// </remarks>
[Test, Sequential]
public void FitsAtArbitraryPointsWithMaple(
[Values(0.1, 0.4, 1.1, 3.01, 3.02, 3.03, 3.1, 3.2, 4.5, 10.0, -10.0)] double t,
[Values(.19389203383553566255, .88132900698869875369, 3.5057665681580626913, 1548.7666642693586902, 3362.2564334253633516, -22332.603641443806014, -440.30323769822443789, -202.42421196280566349, 21.208249625210155439, -4.8936986959784751517, -3.6017584308603731307)] double x,
[Values(1e-14, 1e-14, 1e-15, 1e-10, 1e-10, 1e-8, 1e-11, 1e-12, 1e-12, 1e-13, 1e-13)] double maxAbsoluteError)
[TestCase(0.1, .19389203383553566255, 1e-14)]
[TestCase(0.4, .88132900698869875369, 1e-14)]
[TestCase(1.1, 3.5057665681580626913, 1e-15)]
[TestCase(3.01, 1548.7666642693586902, 1e-10)]
[TestCase(3.02, 3362.2564334253633516, 1e-10)]
[TestCase(3.03, -22332.603641443806014, 1e-8)]
[TestCase(3.1, -440.30323769822443789, 1e-11)]
[TestCase(3.2, -202.42421196280566349, 1e-12)]
[TestCase(4.5, 21.208249625210155439, 1e-12)]
[TestCase(10.0, -4.8936986959784751517, 1e-13)]
[TestCase(-10.0, -3.6017584308603731307, 1e-13)]
public void FitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
{
IInterpolation interpolation = new BulirschStoerRationalInterpolation(_t, _x);

77
src/UnitTests/InterpolationTests/CubicSplineTest.cs

@ -1,4 +1,4 @@
// <copyright file="CubicSplineTest.cs" company="Math.NET">
// <copyright file="CubicSplineTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -34,11 +34,21 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>
/// CubicSpline Test case.
/// </summary>
[TestFixture]
public class CubicSplineTest
{
readonly double[] _t = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 };
readonly double[] _x = new[] { 1.0, 2.0, -1.0, 0.0, 1.0 };
/// <summary>
/// Sample points.
/// </summary>
private readonly double[] _t = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 };
/// <summary>
/// Sample values.
/// </summary>
private readonly double[] _x = new[] { 1.0, 2.0, -1.0, 0.0, 1.0 };
/// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points.
@ -62,16 +72,24 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that at points other than the provided sample points, the interpolation matches the one computed by Maple as a reference.
/// </summary>
/// <param name="t">Sample point.</param>
/// <param name="x">Sample value.</param>
/// <param name="maxAbsoluteError">Maximum absolute error.</param>
/// <remarks>
/// Maple:
/// with(CurveFitting);
/// evalf(subs({x=-2.4},Spline([[-2,1],[-1,2],[0,-1],[1,0],[2,1]], x, degree=3, endpoints='natural')),20);
/// </remarks>
[Test, Sequential]
public void NaturalFitsAtArbitraryPointsWithMaple(
[Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t,
[Values(.144, 1.7906428571428571429, .47321428571428571431, -.80992857142857142857, -1.1089285714285714286, -1.0285714285714285714, .30285714285714285716, 189, 677)] double x,
[Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-12)] double maxAbsoluteError)
[TestCase(-2.4, .144, 1e-15)]
[TestCase(-0.9, 1.7906428571428571429, 1e-15)]
[TestCase(-0.5, .47321428571428571431, 1e-15)]
[TestCase(-0.1, -.80992857142857142857, 1e-15)]
[TestCase(0.1, -1.1089285714285714286, 1e-15)]
[TestCase(0.4, -1.0285714285714285714, 1e-15)]
[TestCase(1.2, .30285714285714285716, 1e-15)]
[TestCase(10.0, 189, 1e-15)]
[TestCase(-10.0, 677, 1e-12)]
public void NaturalFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
{
IInterpolation interpolation = new CubicSplineInterpolation(_t, _x);
@ -105,16 +123,24 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that at points other than the provided sample points, the interpolation matches the one computed by Maple as a reference.
/// </summary>
/// <param name="t">Sample point.</param>
/// <param name="x">Sample value.</param>
/// <param name="maxAbsoluteError">Maximum absolute error.</param>
/// <remarks>
/// Maple:
/// with(CurveFitting);
/// evalf(subs({x=-2.4},Spline([[-2,1],[-1,2],[0,-1],[1,0],[2,1]], x, degree=3, endpoints=[1,-1])),20);
/// </remarks>
[Test, Sequential]
public void FixedFirstDerivativeFitsAtArbitraryPointsWithMaple(
[Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t,
[Values(1.12, 1.8243928571428571428, .54910714285714285715, -.78903571428571428572, -1.1304642857142857143, -1.1040000000000000000, .4148571428571428571, -608.14285714285714286, 1330.1428571428571429)] double x,
[Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-12, 1e-12)] double maxAbsoluteError)
[TestCase(-2.4, 1.12, 1e-15)]
[TestCase(-0.9, 1.8243928571428571428, 1e-15)]
[TestCase(-0.5, .54910714285714285715, 1e-15)]
[TestCase(-0.1, -.78903571428571428572, 1e-15)]
[TestCase(0.1, -1.1304642857142857143, 1e-15)]
[TestCase(0.4, -1.1040000000000000000, 1e-15)]
[TestCase(1.2, .4148571428571428571, 1e-15)]
[TestCase(10.0, -608.14285714285714286, 1e-12)]
[TestCase(-10.0, 1330.1428571428571429, 1e-12)]
public void FixedFirstDerivativeFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
{
IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.FirstDerivative, 1.0, SplineBoundaryCondition.FirstDerivative, -1.0);
@ -148,16 +174,24 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that at points other than the provided sample points, the interpolation matches the one computed by Maple as a reference.
/// </summary>
/// <param name="t">Sample point.</param>
/// <param name="x">Sample value.</param>
/// <param name="maxAbsoluteError">Maximum absolute error.</param>
/// <remarks>
/// Maple:
/// with(CurveFitting);
/// evalf(subs({x=-2.4},Spline([[-2,1],[-1,2],[0,-1],[1,0],[2,1]], x, degree=3, endpoints=Matrix(2,13,{(1,3)=1,(1,13)=-5,(2,10)=1,(2,13)=-1}))),20);
/// </remarks>
[Test, Sequential]
public void FixedSecondDerivativeFitsAtArbitraryPointsWithMaple(
[Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t,
[Values(-.8999999999999999993, 1.7590357142857142857, .41517857142857142854, -.82010714285714285714, -1.1026071428571428572, -1.0211428571428571429, .31771428571428571421, 39, -37)] double x,
[Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-13, 1e-12)] double maxAbsoluteError)
[TestCase(-2.4, -.8999999999999999993, 1e-15)]
[TestCase(-0.9, 1.7590357142857142857, 1e-15)]
[TestCase(-0.5, .41517857142857142854, 1e-15)]
[TestCase(-0.1, -.82010714285714285714, 1e-15)]
[TestCase(0.1, -1.1026071428571428572, 1e-15)]
[TestCase(0.4, -1.0211428571428571429, 1e-15)]
[TestCase(1.2, .31771428571428571421, 1e-15)]
[TestCase(10.0, 39, 1e-13)]
[TestCase(-10.0, -37, 1e-12)]
public void FixedSecondDerivativeFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
{
IInterpolation interpolation = new CubicSplineInterpolation(_t, _x, SplineBoundaryCondition.SecondDerivative, -5.0, SplineBoundaryCondition.SecondDerivative, -1.0);
@ -172,8 +206,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that the interpolation supports the linear case appropriately
/// </summary>
[Test]
public void NaturalSupportsLinearCase([Values(2, 4, 12)] int samples)
/// <param name="samples">Samples array.</param>
[TestCase(2)]
[TestCase(4)]
[TestCase(12)]
public void NaturalSupportsLinearCase(int samples)
{
double[] x, y, xtest, ytest;
LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples);

48
src/UnitTests/InterpolationTests/EquidistantPolynomialTest.cs

@ -1,4 +1,4 @@
// <copyright file="EquidistantPolynomialTest.cs" company="Math.NET">
// <copyright file="EquidistantPolynomialTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -34,11 +34,26 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>
/// EquidistantPolynomial Test case.
/// </summary>
[TestFixture]
public class EquidistantPolynomialTest
{
const double _tmin = 0.0, _tmax = 4.0;
readonly double[] _x = new[] { 0.0, 3.0, 2.5, 1.0, 3.0 };
/// <summary>
/// Left bound;
/// </summary>
private const double Tmin = 0.0;
/// <summary>
/// Right bound.
/// </summary>
private const double Tmax = 4.0;
/// <summary>
/// Sample values.
/// </summary>
private readonly double[] _x = new[] { 0.0, 3.0, 2.5, 1.0, 3.0 };
/// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points.
@ -46,7 +61,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
[Test]
public void FitsAtSamplePoints()
{
IInterpolation interpolation = new EquidistantPolynomialInterpolation(_tmin, _tmax, _x);
IInterpolation interpolation = new EquidistantPolynomialInterpolation(Tmin, Tmax, _x);
for (int i = 0; i < _x.Length; i++)
{
@ -57,18 +72,24 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that at points other than the provided sample points, the interpolation matches the one computed by Maple as a reference.
/// </summary>
/// <param name="t">Sample point.</param>
/// <param name="x">Sample value.</param>
/// <param name="maxAbsoluteError">Maximum absolute error.</param>
/// <remarks>
/// Maple:
/// with(CurveFitting);
/// evalf(subs({x=0.1},PolynomialInterpolation([[0,0],[1,3],[2,2.5],[3,1],[4,3]], x)),20);
/// </remarks>
[Test, Sequential]
public void FitsAtArbitraryPointsWithMaple(
[Values(0.1, 0.4, 1.1, 3.2, 4.5, 10.0, -10.0)] double t,
[Values(.487425, 1.6968, 3.081925, .9408, 7.265625, 592.5, 657.5)] double x,
[Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-14, 1e-10, 1e-9)] double maxAbsoluteError)
[TestCase(0.1, .487425, 1e-15)]
[TestCase(0.4, 1.6968, 1e-15)]
[TestCase(1.1, 3.081925, 1e-15)]
[TestCase(3.2, .9408, 1e-15)]
[TestCase(4.5, 7.265625, 1e-14)]
[TestCase(10.0, 592.5, 1e-10)]
[TestCase(-10.0, 657.5, 1e-9)]
public void FitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
{
IInterpolation interpolation = new EquidistantPolynomialInterpolation(_tmin, _tmax, _x);
IInterpolation interpolation = new EquidistantPolynomialInterpolation(Tmin, Tmax, _x);
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
}
@ -76,8 +97,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that the interpolation supports the linear case appropriately
/// </summary>
[Test]
public void SupportsLinearCase([Values(2, 4, 12)] int samples)
/// <param name="samples">Samples array.</param>
[TestCase(2)]
[TestCase(4)]
[TestCase(12)]
public void SupportsLinearCase(int samples)
{
double[] x, y, xtest, ytest;
LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples);

45
src/UnitTests/InterpolationTests/FloaterHormannRationalTest.cs

@ -1,4 +1,4 @@
// <copyright file="FloaterHormannRationalTest.cs" company="Math.NET">
// <copyright file="FloaterHormannRationalTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -34,11 +34,21 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>
/// FloaterHormannRational test case.
/// </summary>
[TestFixture]
public class FloaterHormannRationalTest
{
readonly double[] _t = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 };
readonly double[] _x = new[] { 1.0, 2.0, -1.0, 0.0, 1.0 };
/// <summary>
/// Sample points.
/// </summary>
private readonly double[] _t = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 };
/// <summary>
/// Sample values.
/// </summary>
private readonly double[] _x = new[] { 1.0, 2.0, -1.0, 0.0, 1.0 };
/// <summary>
/// Verifies that the interpolation matches the given value at all the provided polynomial sample points.
@ -57,16 +67,24 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that at points other than the provided polynomial sample points, the interpolation matches the one computed by Maple as a reference.
/// </summary>
/// <param name="t">Sample point.</param>
/// <param name="x">Sample value.</param>
/// <param name="maxAbsoluteError">Maximum absolute error.</param>
/// <remarks>
/// Maple:
/// with(CurveFitting);
/// PolynomialInterpolation([[-2,1],[-1,2],[0,-1],[1,0],[2,1]], x);
/// </remarks>
[Test, Sequential]
public void PolynomialFitsAtArbitraryPointsWithMaple(
[Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t,
[Values(-4.5968, 1.65395, 0.21875, -0.84205, -1.10805, -1.1248, 0.5392, -4431.0, -5071.0)] double x,
[Values(1e-14, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-9, 1e-9)] double maxAbsoluteError)
[TestCase(-2.4, -4.5968, 1e-14)]
[TestCase(-0.9, 1.65395, 1e-15)]
[TestCase(-0.5, 0.21875, 1e-15)]
[TestCase(-0.1, -0.84205, 1e-15)]
[TestCase(0.1, -1.10805, 1e-15)]
[TestCase(0.4, -1.1248, 1e-15)]
[TestCase(1.2, 0.5392, 1e-15)]
[TestCase(10.0, -4431.0, 1e-9)]
[TestCase(-10.0, -5071.0, 1e-9)]
public void PolynomialFitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
{
IInterpolation interpolation = new EquidistantPolynomialInterpolation(_t, _x);
@ -82,10 +100,10 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
var t = new double[40];
var x = new double[40];
const double step = 10.0 / 39.0;
const double Step = 10.0 / 39.0;
for (int i = 0; i < t.Length; i++)
{
double tt = -5 + (i * step);
double tt = -5 + (i * Step);
t[i] = tt;
x[i] = 1.0 / (1.0 + (tt * tt));
}
@ -101,8 +119,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that the interpolation supports the linear case appropriately
/// </summary>
[Test]
public void SupportsLinearCase([Values(2, 4, 12)] int samples)
/// <param name="samples">Samples array.</param>
[TestCase(2)]
[TestCase(4)]
[TestCase(12)]
public void SupportsLinearCase(int samples)
{
double[] x, y, xtest, ytest;
LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples);

28
src/UnitTests/InterpolationTests/LinearInterpolationCase.cs

@ -1,4 +1,4 @@
// <copyright file="LinearInterpolationCase.cs" company="Math.NET">
// <copyright file="LinearInterpolationCase.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -33,15 +33,29 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using Distributions;
using Numerics.Random;
/// <summary>
/// LinearInterpolation test case.
/// </summary>
internal static class LinearInterpolationCase
{
/// <summary>
/// Build linear samples.
/// </summary>
/// <param name="x">X sample values.</param>
/// <param name="y">Y samples values.</param>
/// <param name="xtest">X test values.</param>
/// <param name="ytest">Y test values.</param>
/// <param name="samples">Sample values.</param>
/// <param name="sampleOffset">Sample offset.</param>
/// <param name="slope">Slope number.</param>
/// <param name="intercept">Intercept criteria.</param>
public static void Build(out double[] x, out double[] y, out double[] xtest, out double[] ytest, int samples = 3, double sampleOffset = -0.5, double slope = 2.0, double intercept = -1.0)
{
// Fixed-seed "random" distribution to ensure we always test with the same data
var uniform = new ContinuousUniform
{
RandomSource = new MersenneTwister(42)
};
{
RandomSource = new MersenneTwister(42)
};
// build linear samples
x = new double[samples];
@ -49,7 +63,7 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
for (int i = 0; i < x.Length; i++)
{
x[i] = i + sampleOffset;
y[i] = x[i] * slope + intercept;
y[i] = (x[i] * slope) + intercept;
}
// build linear test vectors randomly between the sample points
@ -60,14 +74,14 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
// y = const
xtest[0] = sampleOffset - uniform.Sample();
xtest[1] = sampleOffset + uniform.Sample();
ytest[0] = ytest[1] = sampleOffset * slope + intercept;
ytest[0] = ytest[1] = (sampleOffset * slope) + intercept;
}
else
{
for (int i = 0; i < xtest.Length; i++)
{
xtest[i] = (i - 1) + sampleOffset + uniform.Sample();
ytest[i] = xtest[i] * slope + intercept;
ytest[i] = (xtest[i] * slope) + intercept;
}
}
}

41
src/UnitTests/InterpolationTests/LinearSplineTest.cs

@ -1,4 +1,4 @@
// <copyright file="LinearSplineTest.cs" company="Math.NET">
// <copyright file="LinearSplineTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -34,11 +34,21 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>
/// LinearSpline test case
/// </summary>
[TestFixture]
public class LinearSplineTest
{
readonly double[] _t = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 };
readonly double[] _x = new[] { 1.0, 2.0, -1.0, 0.0, 1.0 };
/// <summary>
/// Sample points.
/// </summary>
private readonly double[] _t = new[] { -2.0, -1.0, 0.0, 1.0, 2.0 };
/// <summary>
/// Sample values.
/// </summary>
private readonly double[] _x = new[] { 1.0, 2.0, -1.0, 0.0, 1.0 };
/// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points.
@ -62,16 +72,24 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that at points other than the provided sample points, the interpolation matches the one computed by Maple as a reference.
/// </summary>
/// <param name="t">Sample point.</param>
/// <param name="x">Sample value.</param>
/// <param name="maxAbsoluteError">Maximum absolute error.</param>
/// <remarks>
/// Maple:
/// f := x -> piecewise(x&lt;-1,3+x,x&lt;0,-1-3*x,x&lt;1,-1+x,-1+x);
/// f(x)
/// </remarks>
[Test, Sequential]
public void FitsAtArbitraryPointsWithMaple(
[Values(-2.4, -0.9, -0.5, -0.1, 0.1, 0.4, 1.2, 10.0, -10.0)] double t,
[Values(.6, 1.7, .5, -.7, -.9, -.6, .2, 9.0, -7.0)] double x,
[Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15)] double maxAbsoluteError)
[TestCase(-2.4, .6, 1e-15)]
[TestCase(-0.9, 1.7, 1e-15)]
[TestCase(-0.5, .5, 1e-15)]
[TestCase(-0.1, -.7, 1e-15)]
[TestCase(0.1, -.9, 1e-15)]
[TestCase(0.4, -.6, 1e-15)]
[TestCase(1.2, .2, 1e-15)]
[TestCase(10.0, 9.0, 1e-15)]
[TestCase(-10.0, -7.0, 1e-15)]
public void FitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
{
IInterpolation interpolation = new LinearSplineInterpolation(_t, _x);
@ -86,8 +104,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that the interpolation supports the linear case appropriately
/// </summary>
[Test]
public void SupportsLinearCase([Values(2, 4, 12)] int samples)
/// <param name="samples">Samples array.</param>
[TestCase(2)]
[TestCase(4)]
[TestCase(12)]
public void SupportsLinearCase(int samples)
{
double[] x, y, xtest, ytest;
LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples);

41
src/UnitTests/InterpolationTests/NevillePolynomialTest.cs

@ -1,4 +1,4 @@
// <copyright file="NevillePolynomialTest.cs" company="Math.NET">
// <copyright file="NevillePolynomialTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -34,11 +34,21 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>
/// NevillePolynomial test case.
/// </summary>
[TestFixture]
public class NevillePolynomialTest
{
readonly double[] _t = new[] { 0.0, 1.0, 3.0, 4.0 };
readonly double[] _x = new[] { 0.0, 3.0, 1.0, 3.0 };
/// <summary>
/// Sample points.
/// </summary>
private readonly double[] _t = new[] { 0.0, 1.0, 3.0, 4.0 };
/// <summary>
/// Sample values.
/// </summary>
private readonly double[] _x = new[] { 0.0, 3.0, 1.0, 3.0 };
/// <summary>
/// Verifies that the interpolation matches the given value at all the provided sample points.
@ -62,18 +72,24 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that at points other than the provided sample points, the interpolation matches the one computed by Maple as a reference.
/// </summary>
/// <param name="t">Sample point.</param>
/// <param name="x">Sample value.</param>
/// <param name="maxAbsoluteError">Maximum absolute error.</param>
/// <remarks>
/// Maple:
/// with(CurveFitting);
/// evalf(subs({x=0.1},PolynomialInterpolation([[0,0],[1,3],[3,1],[4,3]], x)),20);
/// </remarks>
[Test, Sequential]
public void FitsAtArbitraryPointsWithMaple(
[Values(0.1, 0.4, 1.1, 3.2, 4.5, 10.0, -10.0)] double t,
[Values(.57225, 1.884, 3.0314166666666666667, 1.034666666666666667, 6.28125, 277.5, -1010.8333333333333333)] double x,
[Values(1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-15, 1e-12)] double maxAbsoluteError)
[TestCase(0.1, .57225, 1e-15)]
[TestCase(0.4, 1.884, 1e-15)]
[TestCase(1.1, 3.0314166666666666667, 1e-15)]
[TestCase(3.2, 1.034666666666666667, 1e-15)]
[TestCase(4.5, 6.28125, 1e-15)]
[TestCase(10.0, 277.5, 1e-15)]
[TestCase(-10.0, -1010.8333333333333333, 1e-12)]
public void FitsAtArbitraryPointsWithMaple(double t, double x, double maxAbsoluteError)
{
IInterpolation interpolation = new NevillePolynomialInterpolation(_t, _x);
IInterpolation interpolation = new NevillePolynomialInterpolation(_t, _x);
Assert.AreEqual(x, interpolation.Interpolate(t), maxAbsoluteError, "Interpolation at {0}", t);
@ -86,8 +102,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
/// <summary>
/// Verifies that the interpolation supports the linear case appropriately
/// </summary>
[Test]
public void SupportsLinearCase([Values(2, 4, 12)] int samples)
/// <param name="samples">Samples array.</param>
[TestCase(2)]
[TestCase(4)]
[TestCase(12)]
public void SupportsLinearCase(int samples)
{
double[] x, y, xtest, ytest;
LinearInterpolationCase.Build(out x, out y, out xtest, out ytest, samples);

25
src/UnitTests/LinearAlgebraProviderTests/Complex/LinearAlgebraProviderTests.cs

@ -1,4 +1,4 @@
// <copyright file="LinearAlgebraProviderTests.cs" company="Math.NET">
// <copyright file="LinearAlgebraProviderTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -29,7 +29,6 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
using System;
using System.Collections.Generic;
using System.Numerics;
using Algorithms.LinearAlgebra;
using LinearAlgebra.Complex;
using LinearAlgebra.Generic;
@ -57,11 +56,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
/// </summary>
private readonly IDictionary<string, DenseMatrix> _matrices = new Dictionary<string, DenseMatrix>
{
{ "Singular3x3", new DenseMatrix(new[,] { { new Complex(1.0, 0), 1.0, 2.0 }, { 1.0, 1.0, 2.0 }, { 1.0, 1.0, 2.0 } }) },
{ "Square3x3", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2, -3.3 }, { 0.0, 1.1, 2.2 }, { -4.4, 5.5, 6.6 } }) },
{ "Square4x4", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2, -3.3, -4.4 }, { 0.0, 1.1, 2.2, 3.3 }, { 1.0, 2.1, 6.2, 4.3 }, { -4.4, 5.5, 6.6, -7.7 } }) },
{ "Singular4x4", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 } }) },
{ "Tall3x2", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2 }, { 0.0, 1.1 }, { -4.4, 5.5 } }) },
{ "Singular3x3", new DenseMatrix(new[,] { { new Complex(1.0, 0), 1.0, 2.0 }, { 1.0, 1.0, 2.0 }, { 1.0, 1.0, 2.0 } }) },
{ "Square3x3", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2, -3.3 }, { 0.0, 1.1, 2.2 }, { -4.4, 5.5, 6.6 } }) },
{ "Square4x4", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2, -3.3, -4.4 }, { 0.0, 1.1, 2.2, 3.3 }, { 1.0, 2.1, 6.2, 4.3 }, { -4.4, 5.5, 6.6, -7.7 } }) },
{ "Singular4x4", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 } }) },
{ "Tall3x2", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2 }, { 0.0, 1.1 }, { -4.4, 5.5 } }) },
{ "Wide2x3", new DenseMatrix(new[,] { { new Complex(-1.1, 0), -2.2, -3.3 }, { 0.0, 1.1, 2.2 } }) }
};
@ -181,7 +180,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
Assert.AreEqual(_x[i] / _y[i], result[i]);
}
}
/// <summary>
/// Can compute L1 norm.
/// </summary>
@ -414,16 +413,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var matrix = _matrices["Square3x3"];
var a = new Complex[matrix.RowCount * matrix.RowCount];
Array.Copy(matrix.Data, a, a.Length);
Control.LinearAlgebraProvider.LUInverse(a, matrix.RowCount);
AssertHelpers.AlmostEqual(a[0], -0.454545454545454, 14);
AssertHelpers.AlmostEqual(a[1], -0.909090909090908, 14);
AssertHelpers.AlmostEqual(a[1], -0.909090909090908, 14);
AssertHelpers.AlmostEqual(a[2], 0.454545454545454, 14);
AssertHelpers.AlmostEqual(a[3], -0.340909090909090, 14);
AssertHelpers.AlmostEqual(a[4], -2.045454545454543, 14);
AssertHelpers.AlmostEqual(a[5], 1.477272727272726, 14);
AssertHelpers.AlmostEqual(a[6], -0.113636363636364, 14);
AssertHelpers.AlmostEqual(a[6], -0.113636363636364, 14);
AssertHelpers.AlmostEqual(a[7], 0.227272727272727, 14);
AssertHelpers.AlmostEqual(a[8], -0.113636363636364, 14);
}
@ -647,7 +646,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
}
}
}
@ -830,7 +829,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex
var b = new[] { new Complex(1.0, 0), 2.0, 3.0, 4.0, 5.0, 6.0 };
var x = new Complex[matrix.ColumnCount * 2];
Control.LinearAlgebraProvider.QRSolve(a, matrix.RowCount, matrix.ColumnCount, b, 2, x);
NotModified(3, 2, a, matrix);
var mb = new DenseMatrix(matrix.RowCount, 2, b);

54
src/UnitTests/LinearAlgebraProviderTests/Complex32/LinearAlgebraProviderTests.cs

@ -1,4 +1,4 @@
// <copyright file="LinearAlgebraProviderTests.cs" company="Math.NET">
// <copyright file="LinearAlgebraProviderTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -28,12 +28,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
{
using System;
using System.Collections.Generic;
using Algorithms.LinearAlgebra;
using LinearAlgebra.Complex32;
using LinearAlgebra.Generic;
using Numerics;
using NUnit.Framework;
/// <summary>
@ -57,11 +55,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
/// </summary>
private readonly IDictionary<string, DenseMatrix> _matrices = new Dictionary<string, DenseMatrix>
{
{ "Singular3x3", new DenseMatrix(new[,] { { new Complex32(1.0f, 0.0f), 1.0f, 2.0f }, { 1.0f, 1.0f, 2.0f }, { 1.0f, 1.0f, 2.0f } }) },
{ "Square3x3", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f, -3.3f }, { 0.0f, 1.1f, 2.2f }, { -4.4f, 5.5f, 6.6f } }) },
{ "Square4x4", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f, -3.3f, -4.4f }, { 0.0f, 1.1f, 2.2f, 3.3f }, { 1.0f, 2.1f, 6.2f, 4.3f }, { -4.4f, 5.5f, 6.6f, -7.7f } }) },
{ "Singular4x4", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f } }) },
{ "Tall3x2", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f }, { 0.0f, 1.1f }, { -4.4f, 5.5f } }) },
{ "Singular3x3", new DenseMatrix(new[,] { { new Complex32(1.0f, 0.0f), 1.0f, 2.0f }, { 1.0f, 1.0f, 2.0f }, { 1.0f, 1.0f, 2.0f } }) },
{ "Square3x3", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f, -3.3f }, { 0.0f, 1.1f, 2.2f }, { -4.4f, 5.5f, 6.6f } }) },
{ "Square4x4", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f, -3.3f, -4.4f }, { 0.0f, 1.1f, 2.2f, 3.3f }, { 1.0f, 2.1f, 6.2f, 4.3f }, { -4.4f, 5.5f, 6.6f, -7.7f } }) },
{ "Singular4x4", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f } }) },
{ "Tall3x2", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f }, { 0.0f, 1.1f }, { -4.4f, 5.5f } }) },
{ "Wide2x3", new DenseMatrix(new[,] { { new Complex32(-1.1f, 0.0f), -2.2f, -3.3f }, { 0.0f, 1.1f, 2.2f } }) }
};
@ -181,7 +179,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
Assert.AreEqual(_x[i] / _y[i], result[i]);
}
}
/// <summary>
/// Can compute L1 norm.
/// </summary>
@ -373,7 +371,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
for (var j = 0; j < c.ColumnCount; j++)
{
var test = 2.2f * x.Row(i) * y.Column(j);
// if they are both close to zero, skip
if (Math.Abs(test.Real) < 1e-7 && Math.Abs(c[i, j].Real) < 1e-7)
{
@ -422,16 +420,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
var matrix = _matrices["Square3x3"];
var a = new Complex32[matrix.RowCount * matrix.RowCount];
Array.Copy(matrix.Data, a, a.Length);
Control.LinearAlgebraProvider.LUInverse(a, matrix.RowCount);
AssertHelpers.AlmostEqual(a[0], -0.454545454545454f, 6);
AssertHelpers.AlmostEqual(a[1], -0.909090909090908f, 6);
AssertHelpers.AlmostEqual(a[1], -0.909090909090908f, 6);
AssertHelpers.AlmostEqual(a[2], 0.454545454545454f, 6);
AssertHelpers.AlmostEqual(a[3], -0.340909090909090f, 6);
AssertHelpers.AlmostEqual(a[4], -2.045454545454543f, 6);
AssertHelpers.AlmostEqual(a[5], 1.477272727272726f, 6);
AssertHelpers.AlmostEqual(a[6], -0.113636363636364f, 6);
AssertHelpers.AlmostEqual(a[6], -0.113636363636364f, 6);
AssertHelpers.AlmostEqual(a[7], 0.227272727272727f, 6);
AssertHelpers.AlmostEqual(a[8], -0.113636363636364f, 6);
}
@ -655,7 +653,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 6);
AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 6);
}
}
}
@ -838,7 +836,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
var b = new[] { new Complex32(1.0f, 0.0f), 2.0f, 3.0f, 4.0f, 5.0f, 6.0f };
var x = new Complex32[matrix.ColumnCount * 2];
Control.LinearAlgebraProvider.QRSolve(a, matrix.RowCount, matrix.ColumnCount, b, 2, x);
NotModified(3, 2, a, matrix);
var mb = new DenseMatrix(matrix.RowCount, 2, b);
@ -1271,7 +1269,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
/// Can solve Ax=b using SVD factorization with a tall A matrix.
/// </summary>
[Test]
public void CanSolveUsingSVDTallMatrix()
public void CanSolveUsingSvdTallMatrix()
{
var matrix = _matrices["Tall3x2"];
var a = new Complex32[matrix.RowCount * matrix.ColumnCount];
@ -1286,10 +1284,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
var mb = new DenseMatrix(matrix.RowCount, 2, b);
var test = (matrix.Transpose() * matrix).Inverse() * matrix.Transpose() * mb;
AssertHelpers.AlmostEqual(test[0, 0], x[0], 6);
AssertHelpers.AlmostEqual(test[1, 0], x[1], 6);
AssertHelpers.AlmostEqual(test[0, 1], x[2], 6);
AssertHelpers.AlmostEqual(test[1, 1], x[3], 6);
AssertHelpers.AlmostEqual(test[0, 0], x[0], 5);
AssertHelpers.AlmostEqual(test[1, 0], x[1], 5);
AssertHelpers.AlmostEqual(test[0, 1], x[2], 5);
AssertHelpers.AlmostEqual(test[1, 1], x[3], 5);
}
/// <summary>
@ -1297,7 +1295,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
/// using a factored matrix.
/// </summary>
[Test]
public void CanSolveUsingSVDSquareMatrixOnFactoredMatrix()
public void CanSolveUsingSvdSquareMatrixOnFactoredMatrix()
{
var matrix = _matrices["Square3x3"];
var a = new Complex32[matrix.RowCount * matrix.ColumnCount];
@ -1316,8 +1314,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
var mx = new DenseMatrix(matrix.ColumnCount, 2, x);
var mb = matrix * mx;
AssertHelpers.AlmostEqual(mb[0, 0], b[0], 6);
AssertHelpers.AlmostEqual(mb[1, 0], b[1], 6);
AssertHelpers.AlmostEqual(mb[0, 0], b[0], 5);
AssertHelpers.AlmostEqual(mb[1, 0], b[1], 5);
AssertHelpers.AlmostEqual(mb[2, 0], b[2], 5);
AssertHelpers.AlmostEqual(mb[0, 1], b[3], 5);
AssertHelpers.AlmostEqual(mb[1, 1], b[4], 5);
@ -1329,7 +1327,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
/// using a factored matrix.
/// </summary>
[Test]
public void CanSolveUsingSVDTallMatrixOnFactoredMatrix()
public void CanSolveUsingSvdTallMatrixOnFactoredMatrix()
{
var matrix = _matrices["Tall3x2"];
var a = new Complex32[matrix.RowCount * matrix.ColumnCount];
@ -1348,10 +1346,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Complex32
var mb = new DenseMatrix(matrix.RowCount, 2, b);
var test = (matrix.Transpose() * matrix).Inverse() * matrix.Transpose() * mb;
AssertHelpers.AlmostEqual(test[0, 0], x[0], 6);
AssertHelpers.AlmostEqual(test[1, 0], x[1], 6);
AssertHelpers.AlmostEqual(test[0, 1], x[2], 6);
AssertHelpers.AlmostEqual(test[1, 1], x[3], 6);
AssertHelpers.AlmostEqual(test[0, 0], x[0], 5);
AssertHelpers.AlmostEqual(test[1, 0], x[1], 5);
AssertHelpers.AlmostEqual(test[0, 1], x[2], 5);
AssertHelpers.AlmostEqual(test[1, 1], x[3], 5);
}
/// <summary>

28
src/UnitTests/LinearAlgebraProviderTests/Double/LinearAlgebraProviderTests.cs

@ -1,4 +1,4 @@
// <copyright file="LinearAlgebraProviderTests.cs" company="Math.NET">
// <copyright file="LinearAlgebraProviderTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -28,11 +28,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
{
using System;
using System.Collections.Generic;
using Algorithms.LinearAlgebra;
using LinearAlgebra.Double;
using LinearAlgebra.Generic;
using NUnit.Framework;
/// <summary>
@ -56,11 +54,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
/// </summary>
private readonly IDictionary<string, DenseMatrix> _matrices = new Dictionary<string, DenseMatrix>
{
{ "Singular3x3", new DenseMatrix(new[,] { { 1.0, 1.0, 2.0 }, { 1.0, 1.0, 2.0 }, { 1.0, 1.0, 2.0 } }) },
{ "Square3x3", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3 }, { 0.0, 1.1, 2.2 }, { -4.4, 5.5, 6.6 } }) },
{ "Square4x4", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3, -4.4 }, { 0.0, 1.1, 2.2, 3.3 }, { 1.0, 2.1, 6.2, 4.3 }, { -4.4, 5.5, 6.6, -7.7 } }) },
{ "Singular4x4", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 } }) },
{ "Tall3x2", new DenseMatrix(new[,] { { -1.1, -2.2 }, { 0.0, 1.1 }, { -4.4, 5.5 } }) },
{ "Singular3x3", new DenseMatrix(new[,] { { 1.0, 1.0, 2.0 }, { 1.0, 1.0, 2.0 }, { 1.0, 1.0, 2.0 } }) },
{ "Square3x3", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3 }, { 0.0, 1.1, 2.2 }, { -4.4, 5.5, 6.6 } }) },
{ "Square4x4", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3, -4.4 }, { 0.0, 1.1, 2.2, 3.3 }, { 1.0, 2.1, 6.2, 4.3 }, { -4.4, 5.5, 6.6, -7.7 } }) },
{ "Singular4x4", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 }, { -1.1, -2.2, -3.3, -4.4 } }) },
{ "Tall3x2", new DenseMatrix(new[,] { { -1.1, -2.2 }, { 0.0, 1.1 }, { -4.4, 5.5 } }) },
{ "Wide2x3", new DenseMatrix(new[,] { { -1.1, -2.2, -3.3 }, { 0.0, 1.1, 2.2 } }) }
};
@ -180,7 +178,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
Assert.AreEqual(_x[i] / _y[i], result[i]);
}
}
/// <summary>
/// Can compute L1 norm.
/// </summary>
@ -413,16 +411,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
var matrix = _matrices["Square3x3"];
var a = new double[matrix.RowCount * matrix.RowCount];
Array.Copy(matrix.Data, a, a.Length);
Control.LinearAlgebraProvider.LUInverse(a, matrix.RowCount);
AssertHelpers.AlmostEqual(a[0], -0.454545454545454, 14);
AssertHelpers.AlmostEqual(a[1], -0.909090909090908, 14);
AssertHelpers.AlmostEqual(a[1], -0.909090909090908, 14);
AssertHelpers.AlmostEqual(a[2], 0.454545454545454, 14);
AssertHelpers.AlmostEqual(a[3], -0.340909090909090, 14);
AssertHelpers.AlmostEqual(a[4], -2.045454545454543, 14);
AssertHelpers.AlmostEqual(a[5], 1.477272727272726, 14);
AssertHelpers.AlmostEqual(a[6], -0.113636363636364, 14);
AssertHelpers.AlmostEqual(a[6], -0.113636363636364, 14);
AssertHelpers.AlmostEqual(a[7], 0.227272727272727, 14);
AssertHelpers.AlmostEqual(a[8], -0.113636363636364, 14);
}
@ -543,7 +541,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
var ipiv = new int[matrix.RowCount];
Control.LinearAlgebraProvider.LUFactor(a, matrix.RowCount, ipiv);
var b = new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
Control.LinearAlgebraProvider.LUSolveFactored(2, a, matrix.RowCount, ipiv, b);
@ -646,7 +644,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 14);
}
}
}
@ -829,7 +827,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Double
var b = new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
var x = new double[matrix.ColumnCount * 2];
Control.LinearAlgebraProvider.QRSolve(a, matrix.RowCount, matrix.ColumnCount, b, 2, x);
NotModified(3, 2, a, matrix);
var mb = new DenseMatrix(matrix.RowCount, 2, b);

28
src/UnitTests/LinearAlgebraProviderTests/Single/LinearAlgebraProviderTests.cs

@ -1,4 +1,4 @@
// <copyright file="LinearAlgebraProviderTests.cs" company="Math.NET">
// <copyright file="LinearAlgebraProviderTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -28,11 +28,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single
{
using System;
using System.Collections.Generic;
using Algorithms.LinearAlgebra;
using LinearAlgebra.Generic;
using LinearAlgebra.Single;
using NUnit.Framework;
/// <summary>
@ -56,11 +54,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single
/// </summary>
private readonly IDictionary<string, DenseMatrix> _matrices = new Dictionary<string, DenseMatrix>
{
{ "Singular3x3", new DenseMatrix(new[,] { { 1.0f, 1.0f, 2.0f }, { 1.0f, 1.0f, 2.0f }, { 1.0f, 1.0f, 2.0f } }) },
{ "Square3x3", new DenseMatrix(new[,] { { -1.1f, -2.2f, -3.3f }, { 0.0f, 1.1f, 2.2f }, { -4.4f, 5.5f, 6.6f } }) },
{ "Square4x4", new DenseMatrix(new[,] { { -1.1f, -2.2f, -3.3f, -4.4f }, { 0.0f, 1.1f, 2.2f, 3.3f }, { 1.0f, 2.1f, 6.2f, 4.3f }, { -4.4f, 5.5f, 6.6f, -7.7f } }) },
{ "Singular4x4", new DenseMatrix(new[,] { { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f } }) },
{ "Tall3x2", new DenseMatrix(new[,] { { -1.1f, -2.2f }, { 0.0f, 1.1f }, { -4.4f, 5.5f } }) },
{ "Singular3x3", new DenseMatrix(new[,] { { 1.0f, 1.0f, 2.0f }, { 1.0f, 1.0f, 2.0f }, { 1.0f, 1.0f, 2.0f } }) },
{ "Square3x3", new DenseMatrix(new[,] { { -1.1f, -2.2f, -3.3f }, { 0.0f, 1.1f, 2.2f }, { -4.4f, 5.5f, 6.6f } }) },
{ "Square4x4", new DenseMatrix(new[,] { { -1.1f, -2.2f, -3.3f, -4.4f }, { 0.0f, 1.1f, 2.2f, 3.3f }, { 1.0f, 2.1f, 6.2f, 4.3f }, { -4.4f, 5.5f, 6.6f, -7.7f } }) },
{ "Singular4x4", new DenseMatrix(new[,] { { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f }, { -1.1f, -2.2f, -3.3f, -4.4f } }) },
{ "Tall3x2", new DenseMatrix(new[,] { { -1.1f, -2.2f }, { 0.0f, 1.1f }, { -4.4f, 5.5f } }) },
{ "Wide2x3", new DenseMatrix(new[,] { { -1.1f, -2.2f, -3.3f }, { 0.0f, 1.1f, 2.2f } }) }
};
@ -180,7 +178,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single
Assert.AreEqual(_x[i] / _y[i], result[i]);
}
}
/// <summary>
/// Can compute L1 norm.
/// </summary>
@ -372,7 +370,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single
for (var j = 0; j < c.ColumnCount; j++)
{
var test = 2.2f * x.Row(i) * y.Column(j);
// if they are both close to zero, skip
if (Math.Abs(test) < 1e-7 && Math.Abs(c[i, j]) < 1e-7)
{
@ -421,16 +419,16 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single
var matrix = _matrices["Square3x3"];
var a = new float[matrix.RowCount * matrix.RowCount];
Array.Copy(matrix.Data, a, a.Length);
Control.LinearAlgebraProvider.LUInverse(a, matrix.RowCount);
AssertHelpers.AlmostEqual(a[0], -0.454545454545454, 6);
AssertHelpers.AlmostEqual(a[1], -0.909090909090908, 6);
AssertHelpers.AlmostEqual(a[1], -0.909090909090908, 6);
AssertHelpers.AlmostEqual(a[2], 0.454545454545454, 6);
AssertHelpers.AlmostEqual(a[3], -0.340909090909090, 6);
AssertHelpers.AlmostEqual(a[4], -2.045454545454543, 6);
AssertHelpers.AlmostEqual(a[5], 1.477272727272726, 6);
AssertHelpers.AlmostEqual(a[6], -0.113636363636364, 6);
AssertHelpers.AlmostEqual(a[6], -0.113636363636364, 6);
AssertHelpers.AlmostEqual(a[7], 0.227272727272727, 6);
AssertHelpers.AlmostEqual(a[8], -0.113636363636364, 6);
}
@ -654,7 +652,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single
{
for (var col = 0; col < matrix.ColumnCount; col++)
{
AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 6);
AssertHelpers.AlmostEqual(matrix[row, col], a[row, col], 6);
}
}
}
@ -837,7 +835,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraProviderTests.Single
var b = new[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f };
var x = new float[matrix.ColumnCount * 2];
Control.LinearAlgebraProvider.QRSolve(a, matrix.RowCount, matrix.ColumnCount, b, 2, x);
NotModified(3, 2, a, matrix);
var mb = new DenseMatrix(matrix.RowCount, 2, b);

24
src/UnitTests/LinearAlgebraTests/Complex/DenseMatrixTests.cs

@ -1,4 +1,4 @@
// <copyright file="DenseMatrixTests.cs" company="Math.NET">
// <copyright file="DenseMatrixTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -87,10 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{
var testData = new Dictionary<string, Matrix>
{
{ "Singular3x3", new DenseMatrix(3, 3, new[] { new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1), new Complex(2.0, 1), new Complex(2.0, 1) }) },
{ "Square3x3", new DenseMatrix(3, 3, new[] { new Complex(-1.1, 1), Complex.Zero, new Complex(-4.4, 1), new Complex(-2.2, 1), new Complex(1.1, 1), new Complex(5.5, 1), new Complex(-3.3, 1), new Complex(2.2, 1), new Complex(6.6, 1) }) },
{ "Square4x4", new DenseMatrix(4, 4, new[] { new Complex(-1.1, 1), Complex.Zero, new Complex(1.0, 1), new Complex(-4.4, 1), new Complex(-2.2, 1), new Complex(1.1, 1), new Complex(2.1, 1), new Complex(5.5, 1), new Complex(-3.3, 1), new Complex(2.2, 1), new Complex(6.2, 1), new Complex(6.6, 1), new Complex(-4.4, 1), new Complex(3.3, 1), new Complex(4.3, 1), new Complex(-7.7, 1) }) },
{ "Tall3x2", new DenseMatrix(3, 2, new[] { new Complex(-1.1, 1), Complex.Zero, new Complex(-4.4, 1), new Complex(-2.2, 1), new Complex(1.1, 1), new Complex(5.5, 1) }) },
{ "Singular3x3", new DenseMatrix(3, 3, new[] { new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1), new Complex(2.0, 1), new Complex(2.0, 1) }) },
{ "Square3x3", new DenseMatrix(3, 3, new[] { new Complex(-1.1, 1), Complex.Zero, new Complex(-4.4, 1), new Complex(-2.2, 1), new Complex(1.1, 1), new Complex(5.5, 1), new Complex(-3.3, 1), new Complex(2.2, 1), new Complex(6.6, 1) }) },
{ "Square4x4", new DenseMatrix(4, 4, new[] { new Complex(-1.1, 1), Complex.Zero, new Complex(1.0, 1), new Complex(-4.4, 1), new Complex(-2.2, 1), new Complex(1.1, 1), new Complex(2.1, 1), new Complex(5.5, 1), new Complex(-3.3, 1), new Complex(2.2, 1), new Complex(6.2, 1), new Complex(6.6, 1), new Complex(-4.4, 1), new Complex(3.3, 1), new Complex(4.3, 1), new Complex(-7.7, 1) }) },
{ "Tall3x2", new DenseMatrix(3, 2, new[] { new Complex(-1.1, 1), Complex.Zero, new Complex(-4.4, 1), new Complex(-2.2, 1), new Complex(1.1, 1), new Complex(5.5, 1) }) },
{ "Wide2x3", new DenseMatrix(2, 3, new[] { new Complex(-1.1, 1), Complex.Zero, new Complex(-2.2, 1), new Complex(1.1, 1), new Complex(-3.3, 1), new Complex(2.2, 1) }) }
};
@ -127,8 +127,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can create a matrix from two-dimensional array.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test]
public void CanCreateMatrixFrom2DArray([Values("Singular3x3", "Singular4x4", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Singular4x4")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanCreateMatrixFrom2DArray(string name)
{
var matrix = new DenseMatrix(TestData2D[name]);
for (var i = 0; i < TestData2D[name].GetLength(0); i++)
@ -176,8 +181,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Identity with wrong order throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
/// <param name="order">The size of the square matrix</param>
[Test]
public void IdentityWithWrongOrderThrowsArgumentOutOfRangeException([Values(0, -1)] int order)
[TestCase(0)]
[TestCase(-1)]
public void IdentityWithWrongOrderThrowsArgumentOutOfRangeException(int order)
{
Assert.Throws<ArgumentOutOfRangeException>(() => DenseMatrix.Identity(order));
}

40
src/UnitTests/LinearAlgebraTests/Complex/DenseVectorTest.TextHandling.cs

@ -1,4 +1,4 @@
// <copyright file="DenseVectorTest.TextHandling.cs" company="Math.NET">
// <copyright file="DenseVectorTest.TextHandling.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -42,8 +42,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="stringToParse">String to parse.</param>
/// <param name="expectedToString">Expected result.</param>
[Test, Sequential]
public void CanParseComplexDenseVectorsWithInvariant([Values("2", "(3)", "[1,2,3]", " [ 1.1 , 2.1 , 3.1 ] ", " [ -1.1 , 2.1 , +3.1 ] ", " [1.2,3.4 , 5.6] ", "[1+1i,2+1i,3+1i]", " [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", " [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", " [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ")] string stringToParse, [Values("(2, 0)", "(3, 0)", "(1, 0),(2, 0),(3, 0)", "(1.1, 0),(2.1, 0),(3.1, 0)", "(-1.1, 0),(2.1, 0),(3.1, 0)", "(1.2, 0),(3.4, 0),(5.6, 0)", "(1, 1),(2, 1),(3, 1)", "(1.1, 1),(2.1, 1),(3.1, 1)", "(-1.1, 1),(2.1, -1),(3.1, 1)", "(1.2, 2.3),(3.4, 4.5),(5.6, 6.7)")] string expectedToString)
[TestCase("2", "(2, 0)")]
[TestCase("(3)", "(3, 0)")]
[TestCase("[1,2,3]", "(1, 0),(2, 0),(3, 0)")]
[TestCase(" [ 1.1 , 2.1 , 3.1 ] ", "(1.1, 0),(2.1, 0),(3.1, 0)")]
[TestCase(" [ -1.1 , 2.1 , +3.1 ] ", "(-1.1, 0),(2.1, 0),(3.1, 0)")]
[TestCase(" [1.2,3.4 , 5.6] ", "(1.2, 0),(3.4, 0),(5.6, 0)")]
[TestCase("[1+1i,2+1i,3+1i]", "(1, 1),(2, 1),(3, 1)")]
[TestCase(" [ 1.1 + 1i , 2.1+1i , 3.1+1i ] ", "(1.1, 1),(2.1, 1),(3.1, 1)")]
[TestCase(" [ -1.1 + 1i , 2.1-1i , +3.1+1i ] ", "(-1.1, 1),(2.1, -1),(3.1, 1)")]
[TestCase(" [1.2+2.3i ,3.4+4.5i , 5.6+ 6.7i] ", "(1.2, 2.3),(3.4, 4.5),(5.6, 6.7)")]
public void CanParseComplexDenseVectorsWithInvariant(string stringToParse, string expectedToString)
{
var formatProvider = CultureInfo.InvariantCulture;
var vector = DenseVector.Parse(stringToParse, formatProvider);
@ -57,10 +66,14 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="stringToParse">String to parse.</param>
/// <param name="expectedToString">Expected result.</param>
/// <param name="culture">Culture name.</param>
[Test, Sequential]
public void CanParseComplexDenseVectorsWithCulture([Values(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", " 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", " 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ")] string stringToParse, [Values("(1.2, 1),(3.4, 1),(5.6, 1)", "(1.2, 1);(3.4, 1);(5.6, 1)", "(1,2, 1);(3,4, 1);(5,6, 1)")] string expectedToString, [Values("en-US", "de-CH", "de-DE")] string culture)
[TestCase(" 1.2 + 1i , 3.4 + 1i , 5.6 + 1i ", "(1.2, 1),(3.4, 1),(5.6, 1)", "en-US")]
[TestCase(" 1.2 + 1i ; 3.4 + 1i ; 5.6 + 1i ", "(1.2, 1);(3.4, 1);(5.6, 1)", "de-CH")]
#if !SILVERLIGHT
[TestCase(" 1,2 + 1i ; 3,4 + 1i ; 5,6 + 1i ", "(1,2, 1);(3,4, 1);(5,6, 1)", "de-DE")]
#endif
public void CanParseComplexDenseVectorsWithCulture(string stringToParse, string expectedToString, string culture)
{
var formatProvider = CultureInfo.GetCultureInfo(culture);
var formatProvider = new CultureInfo(culture);
var vector = DenseVector.Parse(stringToParse, formatProvider);
Assert.AreEqual(expectedToString, vector.ToString(formatProvider));
@ -80,8 +93,19 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Try parse a bad value with invariant returns <c>false</c>.
/// </summary>
/// <param name="str">Input string.</param>
[Test]
public void TryParseBadValueWithInvariantReturnsFalse([Values(null, "", ",", "1,", ",1", "1,2,", ",1,2,", "1,,2,,3", "1e+", "1e", "()", "[ ]")] string str)
[TestCase(null)]
[TestCase("")]
[TestCase(",")]
[TestCase("1,")]
[TestCase(",1")]
[TestCase("1,2,")]
[TestCase(",1,2,")]
[TestCase("1,,2,,3")]
[TestCase("1e+")]
[TestCase("1e")]
[TestCase("()")]
[TestCase("[ ]")]
public void TryParseBadValueWithInvariantReturnsFalse(string str)
{
DenseVector vector;
var ret = DenseVector.TryParse(str, CultureInfo.InvariantCulture, out vector);

2
src/UnitTests/LinearAlgebraTests/Complex/DenseVectorTests.cs

@ -1,4 +1,4 @@
// <copyright file="DenseVectorTests.cs" company="Math.NET">
// <copyright file="DenseVectorTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics

40
src/UnitTests/LinearAlgebraTests/Complex/DiagonalMatrixTests.cs

@ -1,4 +1,4 @@
// <copyright file="DiagonalMatrixTests.cs" company="Math.NET">
// <copyright file="DiagonalMatrixTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -33,6 +33,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
using LinearAlgebra.Complex;
using NUnit.Framework;
#if SILVERLIGHT
using Threading;
#endif
/// <summary>
/// Diagonal matrix tests.
/// </summary>
@ -46,11 +50,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{
TestData2D = new Dictionary<string, Complex[,]>
{
{ "Singular3x3", new[,] { { new Complex(1.0, 1), Complex.Zero, Complex.Zero }, { Complex.Zero, Complex.Zero, Complex.Zero }, { Complex.Zero, Complex.Zero, new Complex(3.0, 1) } } },
{ "Square3x3", new[,] { { new Complex(-1.1, 1), Complex.Zero, Complex.Zero }, { Complex.Zero, new Complex(1.1, 1), Complex.Zero }, { Complex.Zero, Complex.Zero, new Complex(6.6, 1) } } },
{ "Square4x4", new[,] { { new Complex(-1.1, 1), Complex.Zero, Complex.Zero, Complex.Zero }, { Complex.Zero, new Complex(1.1, 1), Complex.Zero, Complex.Zero }, { Complex.Zero, Complex.Zero, new Complex(6.2, 1), Complex.Zero }, { Complex.Zero, Complex.Zero, Complex.Zero, new Complex(-7.7, 1) } } },
{ "Singular4x4", new[,] { { new Complex(-1.1, 1), Complex.Zero, Complex.Zero, Complex.Zero }, { Complex.Zero, new Complex(-2.2, 1), Complex.Zero, Complex.Zero }, { Complex.Zero, Complex.Zero, Complex.Zero, Complex.Zero }, { Complex.Zero, Complex.Zero, Complex.Zero, new Complex(-4.4, 1) } } },
{ "Tall3x2", new[,] { { new Complex(-1.1, 1), Complex.Zero }, { Complex.Zero, new Complex(1.1, 1) }, { Complex.Zero, Complex.Zero } } },
{ "Singular3x3", new[,] { { new Complex(1.0, 1), Complex.Zero, Complex.Zero }, { Complex.Zero, Complex.Zero, Complex.Zero }, { Complex.Zero, Complex.Zero, new Complex(3.0, 1) } } },
{ "Square3x3", new[,] { { new Complex(-1.1, 1), Complex.Zero, Complex.Zero }, { Complex.Zero, new Complex(1.1, 1), Complex.Zero }, { Complex.Zero, Complex.Zero, new Complex(6.6, 1) } } },
{ "Square4x4", new[,] { { new Complex(-1.1, 1), Complex.Zero, Complex.Zero, Complex.Zero }, { Complex.Zero, new Complex(1.1, 1), Complex.Zero, Complex.Zero }, { Complex.Zero, Complex.Zero, new Complex(6.2, 1), Complex.Zero }, { Complex.Zero, Complex.Zero, Complex.Zero, new Complex(-7.7, 1) } } },
{ "Singular4x4", new[,] { { new Complex(-1.1, 1), Complex.Zero, Complex.Zero, Complex.Zero }, { Complex.Zero, new Complex(-2.2, 1), Complex.Zero, Complex.Zero }, { Complex.Zero, Complex.Zero, Complex.Zero, Complex.Zero }, { Complex.Zero, Complex.Zero, Complex.Zero, new Complex(-4.4, 1) } } },
{ "Tall3x2", new[,] { { new Complex(-1.1, 1), Complex.Zero }, { Complex.Zero, new Complex(1.1, 1) }, { Complex.Zero, Complex.Zero } } },
{ "Wide2x3", new[,] { { new Complex(-1.1, 1), Complex.Zero, Complex.Zero }, { Complex.Zero, new Complex(1.1, 1), Complex.Zero } } }
};
@ -111,11 +115,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{
var testData = new Dictionary<string, Matrix>
{
{ "Singular3x3", new DiagonalMatrix(3, 3, new[] { new Complex(1.0, 1), Complex.Zero, new Complex(3.0, 1) }) },
{ "Square3x3", new DiagonalMatrix(4, 4, new[] { new Complex(-1.1, 1), new Complex(1.1, 1), new Complex(6.6, 1) }) },
{ "Square4x4", new DiagonalMatrix(4, 4, new[] { new Complex(-1.1, 1), new Complex(1.1, 1), new Complex(6.2, 1), new Complex(-7.7, 1) }) },
{ "Tall3x2", new DiagonalMatrix(3, 2, new[] { new Complex(-1.1, 1), new Complex(1.1, 1) }) },
{ "Wide2x3", new DiagonalMatrix(2, 3, new[] { new Complex(-1.1, 1), new Complex(1.1, 1) }) },
{ "Singular3x3", new DiagonalMatrix(3, 3, new[] { new Complex(1.0, 1), Complex.Zero, new Complex(3.0, 1) }) },
{ "Square3x3", new DiagonalMatrix(4, 4, new[] { new Complex(-1.1, 1), new Complex(1.1, 1), new Complex(6.6, 1) }) },
{ "Square4x4", new DiagonalMatrix(4, 4, new[] { new Complex(-1.1, 1), new Complex(1.1, 1), new Complex(6.2, 1), new Complex(-7.7, 1) }) },
{ "Tall3x2", new DiagonalMatrix(3, 2, new[] { new Complex(-1.1, 1), new Complex(1.1, 1) }) },
{ "Wide2x3", new DiagonalMatrix(2, 3, new[] { new Complex(-1.1, 1), new Complex(1.1, 1) }) },
};
foreach (var name in testData.Keys)
@ -140,8 +144,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can create a matrix from two-dimensional array.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test]
public void CanCreateMatrixFrom2DArray([Values("Singular3x3", "Singular4x4", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Singular4x4")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanCreateMatrixFrom2DArray(string name)
{
var matrix = new DiagonalMatrix(TestData2D[name]);
for (var i = 0; i < TestData2D[name].GetLength(0); i++)
@ -186,8 +195,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Identity with wrong order throws <c>ArgumentOutOfRangeException</c>.
/// </summary>
/// <param name="order">The size of the square matrix</param>
[Test]
public void IdentityWithWrongOrderThrowsArgumentOutOfRangeException([Values(0, -1)] int order)
[TestCase(0)]
[TestCase(-1)]
public void IdentityWithWrongOrderThrowsArgumentOutOfRangeException(int order)
{
Assert.Throws<ArgumentOutOfRangeException>(() => DiagonalMatrix.Identity(order));
}

59
src/UnitTests/LinearAlgebraTests/Complex/Factorization/CholeskyTests.cs

@ -1,4 +1,4 @@
// <copyright file="CholeskyTests.cs" company="Math.NET">
// <copyright file="CholeskyTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -41,8 +41,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = DenseMatrix.Identity(order);
var factorC = matrixI.Cholesky().Factor;
@ -84,8 +86,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Identity determinant is one.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void IdentityDeterminantIsOne([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void IdentityDeterminantIsOne(int order)
{
var matrixI = DenseMatrix.Identity(order);
var factorC = matrixI.Cholesky();
@ -97,8 +101,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize a random square matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanFactorizeRandomMatrix(int order)
{
var matrixX = MatrixLoader.GenerateRandomPositiveDefiniteHermitianDenseMatrix(order);
var chol = matrixX.Cholesky();
@ -132,8 +141,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random vector (Ax=b).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianDenseMatrix(order);
var matrixACopy = matrixA.Clone();
@ -166,8 +180,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="col">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int row, [Values(1, 4, 8, 3, 10, 100)] int col)
[TestCase(1, 1)]
[TestCase(2, 4)]
[TestCase(5, 8)]
[TestCase(10, 3)]
[TestCase(50, 10)]
[TestCase(100, 100)]
public void CanSolveForRandomMatrix(int row, int col)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianDenseMatrix(row);
var matrixACopy = matrixA.Clone();
@ -203,8 +222,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve for a random vector into a result vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVectorWhenResultVectorGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVectorWhenResultVectorGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianDenseMatrix(order);
var matrixACopy = matrixA.Clone();
@ -245,8 +269,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="col">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomMatrixWhenResultMatrixGiven([Values(1, 2, 5, 10, 50, 100)] int row, [Values(1, 4, 8, 3, 10, 100)] int col)
[TestCase(1, 1)]
[TestCase(2, 4)]
[TestCase(5, 8)]
[TestCase(10, 3)]
[TestCase(50, 10)]
[TestCase(100, 100)]
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int row, int col)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianDenseMatrix(row);
var matrixACopy = matrixA.Clone();

35
src/UnitTests/LinearAlgebraTests/Complex/Factorization/EvdTests.cs

@ -1,4 +1,4 @@
// <copyright file="EvdTests.cs" company="Math.NET">
// <copyright file="EvdTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = DenseMatrix.Identity(order);
var factorEvd = matrixI.Evd();
@ -76,8 +78,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize a random square matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanFactorizeRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var factorEvd = matrixA.Evd();
@ -142,8 +149,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can check rank of square matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanCheckRankSquare([Values(10, 50, 100)] int order)
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanCheckRankSquare(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var factorEvd = matrixA.Evd();
@ -155,8 +164,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can check rank of square singular matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanCheckRankOfSquareSingular([Values(10, 50, 100)] int order)
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanCheckRankOfSquareSingular(int order)
{
var matrixA = new DenseMatrix(order, order);
matrixA[0, 0] = 1;
@ -179,8 +190,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Identity determinant is one.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void IdentityDeterminantIsOne([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void IdentityDeterminantIsOne(int order)
{
var matrixI = DenseMatrix.Identity(order);
var factorEvd = matrixI.Evd();

59
src/UnitTests/LinearAlgebraTests/Complex/Factorization/GramSchmidtTests.cs

@ -1,4 +1,4 @@
// <copyright file="GramSchmidtTests.cs" company="Math.NET">
// <copyright file="GramSchmidtTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -60,8 +60,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = DenseMatrix.Identity(order);
var factorGramSchmidt = matrixI.GramSchmidt();
@ -106,8 +108,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Identity determinant is one.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void IdentityDeterminantIsOne([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void IdentityDeterminantIsOne(int order)
{
var matrixI = DenseMatrix.Identity(order);
var factorGramSchmidt = matrixI.GramSchmidt();
@ -119,8 +123,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int row, [Values(1, 2, 5, 6, 48, 98)] int column)
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(5, 5)]
[TestCase(10, 6)]
[TestCase(50, 48)]
[TestCase(100, 98)]
public void CanFactorizeRandomMatrix(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(row, column);
var factorGramSchmidt = matrixA.GramSchmidt();
@ -179,8 +188,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random vector (Ax=b).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -213,8 +227,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -254,8 +273,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve for a random vector into a result vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVectorWhenResultVectorGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVectorWhenResultVectorGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -295,8 +319,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B) into a result matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrixWhenResultMatrixGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();

68
src/UnitTests/LinearAlgebraTests/Complex/Factorization/LUTests.cs

@ -1,4 +1,4 @@
// <copyright file="LUTests.cs" company="Math.NET">
// <copyright file="LUTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -41,8 +41,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = DenseMatrix.Identity(order);
var factorLU = matrixI.LU();
@ -86,8 +88,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Identity determinant is one.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void IdentityDeterminantIsOne([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void IdentityDeterminantIsOne(int order)
{
var matrixI = DenseMatrix.Identity(order);
var lu = matrixI.LU();
@ -98,8 +102,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize a random square matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanFactorizeRandomMatrix(int order)
{
var matrixX = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var factorLU = matrixX.LU();
@ -148,8 +157,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random vector (Ax=b).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -182,8 +196,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -223,8 +242,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve for a random vector into a result vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVectorWhenResultVectorGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVectorWhenResultVectorGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -264,8 +288,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B) into a result matrix.
/// </summary>
/// <param name="order">Matrix row number.</param>
[Test]
public void CanSolveForRandomMatrixWhenResultMatrixGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -317,8 +346,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can inverse a matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanInverse([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanInverse(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();

59
src/UnitTests/LinearAlgebraTests/Complex/Factorization/QRTests.cs

@ -1,4 +1,4 @@
// <copyright file="QRTests.cs" company="Math.NET">
// <copyright file="QRTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -60,8 +60,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = DenseMatrix.Identity(order);
var factorQR = matrixI.QR();
@ -90,8 +92,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Identity determinant is one.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void IdentityDeterminantIsOne([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void IdentityDeterminantIsOne(int order)
{
var matrixI = DenseMatrix.Identity(order);
var factorQR = matrixI.QR();
@ -103,8 +107,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int row, [Values(1, 2, 5, 6, 48, 98)] int column)
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(5, 5)]
[TestCase(10, 6)]
[TestCase(50, 48)]
[TestCase(100, 98)]
public void CanFactorizeRandomMatrix(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(row, column);
var factorQR = matrixA.QR();
@ -146,8 +155,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random vector (Ax=b).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -180,8 +194,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -221,8 +240,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve for a random vector into a result vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVectorWhenResultVectorGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVectorWhenResultVectorGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -262,8 +286,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B) into a result matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrixWhenResultMatrixGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixACopy = matrixA.Clone();

74
src/UnitTests/LinearAlgebraTests/Complex/Factorization/SvdTests.cs

@ -1,4 +1,4 @@
// <copyright file="SvdTests.cs" company="Math.NET">
// <copyright file="SvdTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -51,8 +51,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = DenseMatrix.Identity(order);
var factorSvd = matrixI.Svd(true);
@ -83,8 +85,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int row, [Values(1, 2, 5, 6, 48, 98)] int column)
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(5, 5)]
[TestCase(10, 6)]
[TestCase(50, 48)]
[TestCase(100, 98)]
public void CanFactorizeRandomMatrix(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(row, column);
var factorSvd = matrixA.Svd(true);
@ -120,8 +127,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanCheckRankOfNonSquare([Values(10, 48, 100)] int row, [Values(8, 52, 93)] int column)
[TestCase(10, 8)]
[TestCase(48, 52)]
[TestCase(100, 93)]
public void CanCheckRankOfNonSquare(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(row, column);
var factorSvd = matrixA.Svd(true);
@ -134,8 +143,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can check rank of a square matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanCheckRankSquare([Values(1, 2, 5, 9, 50, 90)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(9)]
[TestCase(50)]
[TestCase(90)]
public void CanCheckRankSquare(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var factorSvd = matrixA.Svd(true);
@ -154,8 +168,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can check rank of a square singular matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanCheckRankOfSquareSingular([Values(10, 50, 100)] int order)
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanCheckRankOfSquareSingular(int order)
{
var matrixA = new DenseMatrix(order, order);
matrixA[0, 0] = 1;
@ -205,8 +221,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomVector([Values(1, 2, 5, 9, 50, 90)] int row, [Values(1, 2, 5, 10, 50, 100)] int column)
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(5, 5)]
[TestCase(9, 10)]
[TestCase(50, 50)]
[TestCase(90, 100)]
public void CanSolveForRandomVector(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(row, column);
var matrixACopy = matrixA.Clone();
@ -240,8 +261,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomMatrix([Values(1, 4, 7, 10, 45, 80)] int row, [Values(1, 4, 8, 10, 50, 100)] int column)
[TestCase(1, 1)]
[TestCase(4, 4)]
[TestCase(7, 8)]
[TestCase(10, 10)]
[TestCase(45, 50)]
[TestCase(80, 100)]
public void CanSolveForRandomMatrix(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(row, column);
var matrixACopy = matrixA.Clone();
@ -282,8 +308,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomVectorWhenResultVectorGiven([Values(1, 2, 5, 9, 50, 90)] int row, [Values(1, 2, 5, 10, 50, 100)] int column)
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(5, 5)]
[TestCase(9, 10)]
[TestCase(50, 50)]
[TestCase(90, 100)]
public void CanSolveForRandomVectorWhenResultVectorGiven(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(row, column);
var matrixACopy = matrixA.Clone();
@ -322,8 +353,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomMatrixWhenResultMatrixGiven([Values(1, 4, 7, 10, 45, 80)] int row, [Values(1, 4, 8, 10, 50, 100)] int column)
[TestCase(1, 1)]
[TestCase(4, 4)]
[TestCase(7, 8)]
[TestCase(10, 10)]
[TestCase(45, 50)]
[TestCase(80, 100)]
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(row, column);
var matrixACopy = matrixA.Clone();

59
src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserCholeskyTests.cs

@ -1,4 +1,4 @@
// <copyright file="UserCholeskyTests.cs" company="Math.NET">
// <copyright file="UserCholeskyTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -40,8 +40,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = UserDefinedMatrix.Identity(order);
var factorC = matrixI.Cholesky().Factor;
@ -83,8 +85,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Identity determinant is one.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void IdentityDeterminantIsOne([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void IdentityDeterminantIsOne(int order)
{
var matrixI = UserDefinedMatrix.Identity(order);
var factorC = matrixI.Cholesky();
@ -96,8 +100,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize a random square matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanFactorizeRandomMatrix(int order)
{
var matrixX = MatrixLoader.GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(order);
var chol = matrixX.Cholesky();
@ -131,8 +140,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random vector (Ax=b).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(order);
var matrixACopy = matrixA.Clone();
@ -165,8 +179,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="col">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int row, [Values(1, 4, 8, 3, 10, 100)] int col)
[TestCase(1, 1)]
[TestCase(2, 4)]
[TestCase(5, 8)]
[TestCase(10, 3)]
[TestCase(50, 10)]
[TestCase(100, 100)]
public void CanSolveForRandomMatrix(int row, int col)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(row);
var matrixACopy = matrixA.Clone();
@ -202,8 +221,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve for a random vector into a result vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVectorWhenResultVectorGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVectorWhenResultVectorGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(order);
var matrixACopy = matrixA.Clone();
@ -244,8 +268,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="col">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomMatrixWhenResultMatrixGiven([Values(1, 2, 5, 10, 50, 100)] int row, [Values(1, 4, 8, 3, 10, 100)] int col)
[TestCase(1, 1)]
[TestCase(2, 4)]
[TestCase(5, 8)]
[TestCase(10, 3)]
[TestCase(50, 10)]
[TestCase(100, 100)]
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int row, int col)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(row);
var matrixACopy = matrixA.Clone();

80
src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserEvdTests.cs

@ -1,4 +1,4 @@
// <copyright file="UserEvdTests.cs" company="Math.NET">
// <copyright file="UserEvdTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -50,8 +50,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = UserDefinedMatrix.Identity(order);
var factorEvd = matrixI.Evd();
@ -75,8 +77,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize a random square matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanFactorizeRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var factorEvd = matrixA.Evd();
@ -106,8 +113,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize a symmetric random square matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeRandomSymmetricMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanFactorizeRandomSymmetricMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(order);
var factorEvd = matrixA.Evd();
@ -136,8 +148,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can check rank of square matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanCheckRankSquare([Values(10, 50, 100)] int order)
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanCheckRankSquare(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var factorEvd = matrixA.Evd();
@ -149,8 +163,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can check rank of square singular matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanCheckRankOfSquareSingular([Values(10, 50, 100)] int order)
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanCheckRankOfSquareSingular(int order)
{
var matrixA = new UserDefinedMatrix(order, order);
matrixA[0, 0] = 1;
@ -173,8 +189,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Identity determinant is one.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void IdentityDeterminantIsOne([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void IdentityDeterminantIsOne(int order)
{
var matrixI = UserDefinedMatrix.Identity(order);
var factorEvd = matrixI.Evd();
@ -185,8 +203,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random vector and symmetric matrix (Ax=b).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVectorAndSymmetricMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVectorAndSymmetricMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(order);
var matrixACopy = matrixA.Clone();
@ -219,8 +242,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix and symmetric matrix (AX=B).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrixAndSymmetricMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrixAndSymmetricMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(order);
var matrixACopy = matrixA.Clone();
@ -260,8 +288,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random vector and symmetric matrix (Ax=b) into a result matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVectorAndSymmetricMatrixWhenResultVectorGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVectorAndSymmetricMatrixWhenResultVectorGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(order);
var matrixACopy = matrixA.Clone();
@ -299,8 +332,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix and symmetric matrix (AX=B) into result matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrixAndSymmetricMatrixWhenResultMatrixGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrixAndSymmetricMatrixWhenResultMatrixGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(order);
var matrixACopy = matrixA.Clone();

59
src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserGramSchmidtTests.cs

@ -1,4 +1,4 @@
// <copyright file="UserGramSchmidtTests.cs" company="Math.NET">
// <copyright file="UserGramSchmidtTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -58,8 +58,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = UserDefinedMatrix.Identity(order);
var factorGramSchmidt = matrixI.GramSchmidt();
@ -104,8 +106,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Identity determinant is one.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void IdentityDeterminantIsOne([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void IdentityDeterminantIsOne(int order)
{
var matrixI = UserDefinedMatrix.Identity(order);
var factorGramSchmidt = matrixI.GramSchmidt();
@ -117,8 +121,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int row, [Values(1, 2, 5, 6, 48, 98)] int column)
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(5, 5)]
[TestCase(10, 6)]
[TestCase(50, 48)]
[TestCase(100, 98)]
public void CanFactorizeRandomMatrix(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(row, column);
var factorGramSchmidt = matrixA.GramSchmidt();
@ -177,8 +186,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random vector (Ax=b).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -211,8 +225,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -252,8 +271,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve for a random vector into a result vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVectorWhenResultVectorGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVectorWhenResultVectorGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -293,8 +317,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B) into a result matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrixWhenResultMatrixGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();

68
src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserLUTests.cs

@ -1,4 +1,4 @@
// <copyright file="UserLUTests.cs" company="Math.NET">
// <copyright file="UserLUTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -40,8 +40,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = UserDefinedMatrix.Identity(order);
var factorLU = matrixI.LU();
@ -85,8 +87,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Identity determinant is one.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void IdentityDeterminantIsOne([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void IdentityDeterminantIsOne(int order)
{
var matrixI = UserDefinedMatrix.Identity(order);
var lu = matrixI.LU();
@ -97,8 +101,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize a random square matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanFactorizeRandomMatrix(int order)
{
var matrixX = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var factorLU = matrixX.LU();
@ -147,8 +156,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random vector (Ax=b).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -181,8 +195,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -222,8 +241,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve for a random vector into a result vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVectorWhenResultVectorGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVectorWhenResultVectorGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -263,8 +287,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B) into a result matrix.
/// </summary>
/// <param name="order">Matrix row number.</param>
[Test]
public void CanSolveForRandomMatrixWhenResultMatrixGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -316,8 +345,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can inverse a matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanInverse([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanInverse(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();

59
src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserQRTests.cs

@ -1,4 +1,4 @@
// <copyright file="UserQRTests.cs" company="Math.NET">
// <copyright file="UserQRTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -59,8 +59,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = UserDefinedMatrix.Identity(order);
var factorQR = matrixI.QR();
@ -90,8 +92,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Identity determinant is one.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void IdentityDeterminantIsOne([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void IdentityDeterminantIsOne(int order)
{
var matrixI = UserDefinedMatrix.Identity(order);
var factorQR = matrixI.QR();
@ -103,8 +107,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int row, [Values(1, 2, 5, 6, 48, 98)] int column)
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(5, 5)]
[TestCase(10, 6)]
[TestCase(50, 48)]
[TestCase(100, 98)]
public void CanFactorizeRandomMatrix(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(row, column);
var factorQR = matrixA.QR();
@ -146,8 +155,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random vector (Ax=b).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -180,8 +194,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B).
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -221,8 +240,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve for a random vector into a result vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVectorWhenResultVectorGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomVectorWhenResultVectorGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();
@ -262,8 +286,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can solve a system of linear equations for a random matrix (AX=B) into a result matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrixWhenResultMatrixGiven([Values(1, 2, 5, 10, 50, 100)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var matrixACopy = matrixA.Clone();

74
src/UnitTests/LinearAlgebraTests/Complex/Factorization/UserSvdTests.cs

@ -1,4 +1,4 @@
// <copyright file="UserSvdTests.cs" company="Math.NET">
// <copyright file="UserSvdTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -50,8 +50,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can factorize identity matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanFactorizeIdentity([Values(1, 10, 100)] int order)
[TestCase(1)]
[TestCase(10)]
[TestCase(100)]
public void CanFactorizeIdentity(int order)
{
var matrixI = UserDefinedMatrix.Identity(order);
var factorSvd = matrixI.Svd(true);
@ -82,8 +84,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanFactorizeRandomMatrix([Values(1, 2, 5, 10, 50, 100)] int row, [Values(1, 2, 5, 6, 48, 98)] int column)
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(5, 5)]
[TestCase(10, 6)]
[TestCase(50, 48)]
[TestCase(100, 98)]
public void CanFactorizeRandomMatrix(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(row, column);
var factorSvd = matrixA.Svd(true);
@ -119,8 +126,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanCheckRankOfNonSquare([Values(10, 48, 100)] int row, [Values(8, 52, 93)] int column)
[TestCase(10, 8)]
[TestCase(48, 52)]
[TestCase(100, 93)]
public void CanCheckRankOfNonSquare(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(row, column);
var factorSvd = matrixA.Svd(true);
@ -133,8 +142,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can check rank of a square matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanCheckRankSquare([Values(1, 2, 5, 9, 50, 90)] int order)
[TestCase(1)]
[TestCase(2)]
[TestCase(5)]
[TestCase(9)]
[TestCase(50)]
[TestCase(90)]
public void CanCheckRankSquare(int order)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(order, order);
var factorSvd = matrixA.Svd(true);
@ -153,8 +167,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// Can check rank of a square singular matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanCheckRankOfSquareSingular([Values(10, 50, 100)] int order)
[TestCase(10)]
[TestCase(50)]
[TestCase(100)]
public void CanCheckRankOfSquareSingular(int order)
{
var matrixA = new UserDefinedMatrix(order, order);
matrixA[0, 0] = 1;
@ -204,8 +220,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomVector([Values(1, 2, 5, 9, 50, 90)] int row, [Values(1, 2, 5, 10, 50, 100)] int column)
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(5, 5)]
[TestCase(9, 10)]
[TestCase(50, 50)]
[TestCase(90, 100)]
public void CanSolveForRandomVector(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(row, column);
var matrixACopy = matrixA.Clone();
@ -239,8 +260,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomMatrix([Values(1, 4, 7, 10, 45, 80)] int row, [Values(1, 4, 8, 10, 50, 100)] int column)
[TestCase(1, 1)]
[TestCase(4, 4)]
[TestCase(7, 8)]
[TestCase(10, 10)]
[TestCase(45, 50)]
[TestCase(80, 100)]
public void CanSolveForRandomMatrix(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(row, column);
var matrixACopy = matrixA.Clone();
@ -281,8 +307,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomVectorWhenResultVectorGiven([Values(1, 2, 5, 9, 50, 90)] int row, [Values(1, 2, 5, 10, 50, 100)] int column)
[TestCase(1, 1)]
[TestCase(2, 2)]
[TestCase(5, 5)]
[TestCase(9, 10)]
[TestCase(50, 50)]
[TestCase(90, 100)]
public void CanSolveForRandomVectorWhenResultVectorGiven(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(row, column);
var matrixACopy = matrixA.Clone();
@ -321,8 +352,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Factorization
/// </summary>
/// <param name="row">Matrix row number.</param>
/// <param name="column">Matrix column number.</param>
[Test, Sequential]
public void CanSolveForRandomMatrixWhenResultMatrixGiven([Values(1, 4, 7, 10, 45, 80)] int row, [Values(1, 4, 8, 10, 50, 100)] int column)
[TestCase(1, 1)]
[TestCase(4, 4)]
[TestCase(7, 8)]
[TestCase(10, 10)]
[TestCase(45, 50)]
[TestCase(80, 100)]
public void CanSolveForRandomMatrixWhenResultMatrixGiven(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomUserDefinedMatrix(row, column);
var matrixACopy = matrixA.Clone();

6
src/UnitTests/LinearAlgebraTests/Complex/IO/DelimitedReaderTests.cs

@ -1,4 +1,4 @@
// <copyright file="DelimitedReaderTests.cs" company="Math.NET">
// <copyright file="DelimitedReaderTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -53,7 +53,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.IO
var reader = new DelimitedReader<DenseMatrix>(',')
{
HasHeaderRow = true,
HasHeaderRow = true,
CultureInfo = CultureInfo.InvariantCulture
};
@ -145,7 +145,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.IO
var reader = new DelimitedReader<DenseMatrix>('.')
{
HasHeaderRow = true,
HasHeaderRow = true,
CultureInfo = new CultureInfo("tr-TR")
};

2
src/UnitTests/LinearAlgebraTests/Complex/IO/DelimitedWriterTests.cs

@ -1,4 +1,4 @@
// <copyright file="DelimitedWriterTests.cs" company="Math.NET">
// <copyright file="DelimitedWriterTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics

2
src/UnitTests/LinearAlgebraTests/Complex/IO/MatlabReaderTests.cs

@ -1,4 +1,4 @@
// <copyright file="MatlabReaderTests.cs" company="Math.NET">
// <copyright file="MatlabReaderTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics

2
src/UnitTests/LinearAlgebraTests/Complex/IO/MatlabWriterTests.cs

@ -1,4 +1,4 @@
// <copyright file="MatlabWriterTests.cs" company="Math.NET">
// <copyright file="MatlabWriterTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics

14
src/UnitTests/LinearAlgebraTests/Complex/MatrixLoader.cs

@ -1,4 +1,4 @@
// <copyright file="MatrixLoader.cs" company="Math.NET">
// <copyright file="MatrixLoader.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -95,12 +95,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
{
TestData2D = new Dictionary<string, Complex[,]>
{
{ "Singular3x3", new[,] { { new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1) }, { new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1) }, { new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1) } } },
{ "Square3x3", new[,] { { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1) }, { Complex.Zero, new Complex(1.1, 1), new Complex(2.2, 1) }, { new Complex(-4.4, 1), new Complex(5.5, 1), new Complex(6.6, 1) } } },
{ "Square4x4", new[,] { { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1), new Complex(-4.4, 1) }, { Complex.Zero, new Complex(1.1, 1), new Complex(2.2, 1), new Complex(3.3, 1) }, { new Complex(1.0, 1), new Complex(2.1, 1), new Complex(6.2, 1), new Complex(4.3, 1) }, { new Complex(-4.4, 1), new Complex(5.5, 1), new Complex(6.6, 1), new Complex(-7.7, 1) } } },
{ "Singular4x4", new[,] { { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1), new Complex(-4.4, 1) }, { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1), new Complex(-4.4, 1) }, { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1), new Complex(-4.4, 1) }, { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1), new Complex(-4.4, 1) } } },
{ "Tall3x2", new[,] { { new Complex(-1.1, 1), new Complex(-2.2, 1) }, { Complex.Zero, new Complex(1.1, 1) }, { new Complex(-4.4, 1), new Complex(5.5, 1) } } },
{ "Wide2x3", new[,] { { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1) }, { Complex.Zero, new Complex(1.1, 1), new Complex(2.2, 1) } } },
{ "Singular3x3", new[,] { { new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1) }, { new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1) }, { new Complex(1.0, 1), new Complex(1.0, 1), new Complex(2.0, 1) } } },
{ "Square3x3", new[,] { { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1) }, { Complex.Zero, new Complex(1.1, 1), new Complex(2.2, 1) }, { new Complex(-4.4, 1), new Complex(5.5, 1), new Complex(6.6, 1) } } },
{ "Square4x4", new[,] { { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1), new Complex(-4.4, 1) }, { Complex.Zero, new Complex(1.1, 1), new Complex(2.2, 1), new Complex(3.3, 1) }, { new Complex(1.0, 1), new Complex(2.1, 1), new Complex(6.2, 1), new Complex(4.3, 1) }, { new Complex(-4.4, 1), new Complex(5.5, 1), new Complex(6.6, 1), new Complex(-7.7, 1) } } },
{ "Singular4x4", new[,] { { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1), new Complex(-4.4, 1) }, { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1), new Complex(-4.4, 1) }, { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1), new Complex(-4.4, 1) }, { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1), new Complex(-4.4, 1) } } },
{ "Tall3x2", new[,] { { new Complex(-1.1, 1), new Complex(-2.2, 1) }, { Complex.Zero, new Complex(1.1, 1) }, { new Complex(-4.4, 1), new Complex(5.5, 1) } } },
{ "Wide2x3", new[,] { { new Complex(-1.1, 1), new Complex(-2.2, 1), new Complex(-3.3, 1) }, { Complex.Zero, new Complex(1.1, 1), new Complex(2.2, 1) } } },
{ "Symmetric3x3", new[,] { { Complex.One, 2.0, 3.0 }, { 2.0, 2.0, 0.0 }, { 3.0, 0.0, 3.0 } } }
};

123
src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.Arithmetic.cs

@ -1,4 +1,4 @@
// <copyright file="MatrixTests.Arithmetic.cs" company="Math.NET">
// <copyright file="MatrixTests.Arithmetic.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -42,8 +42,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can multiply with a complex number.
/// </summary>
/// <param name="real">Complex real part value.</param>
[Test]
public void CanMultiplyWithComplex([Values(0, 1, 2.2)] double real)
[TestCase(0)]
[TestCase(1)]
[TestCase(2.2)]
public void CanMultiplyWithComplex(double real)
{
var value = new Complex(real, 1.0);
var matrix = TestMatrices["Singular3x3"];
@ -148,8 +150,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can left multiply with a complex.
/// </summary>
/// <param name="real">Complex real value.</param>
[Test, Sequential]
public void CanOperatorLeftMultiplyWithComplex([Values(0, 1, 2.2)] double real)
[TestCase(0)]
[TestCase(1)]
[TestCase(2.2)]
public void CanOperatorLeftMultiplyWithComplex(double real)
{
var value = new Complex(real, 1.0);
var matrix = TestMatrices["Singular3x3"];
@ -168,8 +172,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can right multiply with a Complex.
/// </summary>
/// <param name="real">Complex real value.</param>
[Test, Sequential]
public void CanOperatorRightMultiplyWithComplex([Values(0, 1, 2.2)] double real)
[TestCase(0)]
[TestCase(1)]
[TestCase(2.2)]
public void CanOperatorRightMultiplyWithComplex(double real)
{
var value = new Complex(real, 1.0);
var matrix = TestMatrices["Singular3x3"];
@ -188,8 +194,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can multiply with a Complex into result.
/// </summary>
/// <param name="real">Complex real value.</param>
[Test]
public void CanMultiplyWithComplexIntoResult([Values(0, 1, 2.2)] double real)
[TestCase(0)]
[TestCase(1)]
[TestCase(2.2)]
public void CanMultiplyWithComplexIntoResult(double real)
{
var value = new Complex(real, 1.0);
var matrix = TestMatrices["Singular3x3"];
@ -263,8 +271,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="mtxA">Matrix A name.</param>
/// <param name="mtxB">Matrix B name.</param>
[Test, Sequential]
public void CanAddMatrix([Values("Singular3x3", "Singular4x4")] string mtxA, [Values("Square3x3", "Square4x4")] string mtxB)
[TestCase("Singular3x3", "Square3x3")]
[TestCase("Singular4x4", "Square4x4")]
public void CanAddMatrix(string mtxA, string mtxB)
{
var matrixA = TestMatrices[mtxA];
var matrixB = TestMatrices[mtxB];
@ -318,8 +327,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="mtxA">Matrix A name.</param>
/// <param name="mtxB">Matrix B name.</param>
[Test, Sequential]
public void CanAddUsingOperator([Values("Singular3x3", "Singular4x4")] string mtxA, [Values("Square3x3", "Square4x4")] string mtxB)
[TestCase("Singular3x3", "Square3x3")]
[TestCase("Singular4x4", "Square4x4")]
public void CanAddUsingOperator(string mtxA, string mtxB)
{
var matrixA = TestMatrices[mtxA];
var matrixB = TestMatrices[mtxB];
@ -383,8 +393,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="mtxA">Matrix A name.</param>
/// <param name="mtxB">Matrix B name.</param>
[Test, Sequential]
public void CanSubtractMatrix([Values("Singular3x3", "Singular4x4")] string mtxA, [Values("Square3x3", "Square4x4")] string mtxB)
[TestCase("Singular3x3", "Square3x3")]
[TestCase("Singular4x4", "Square4x4")]
public void CanSubtractMatrix(string mtxA, string mtxB)
{
var matrixA = TestMatrices[mtxA];
var matrixB = TestMatrices[mtxB];
@ -438,8 +449,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="mtxA">Matrix A name.</param>
/// <param name="mtxB">Matrix B name.</param>
[Test, Sequential]
public void CanSubtractUsingOperator([Values("Singular3x3", "Singular4x4")] string mtxA, [Values("Square3x3", "Square4x4")] string mtxB)
[TestCase("Singular3x3", "Square3x3")]
[TestCase("Singular4x4", "Square4x4")]
public void CanSubtractUsingOperator(string mtxA, string mtxB)
{
var matrixA = TestMatrices[mtxA];
var matrixB = TestMatrices[mtxB];
@ -503,8 +515,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="nameA">Matrix A name.</param>
/// <param name="nameB">Matrix B name.</param>
[Test, Sequential]
public void CanMultiplyMatrixWithMatrix([Values("Singular3x3", "Singular4x4", "Wide2x3", "Wide2x3", "Tall3x2")] string nameA, [Values("Square3x3", "Square4x4", "Square3x3", "Tall3x2", "Wide2x3")] string nameB)
[TestCase("Singular3x3", "Square3x3")]
[TestCase("Singular4x4", "Square4x4")]
[TestCase("Wide2x3", "Square3x3")]
[TestCase("Wide2x3", "Tall3x2")]
[TestCase("Tall3x2", "Wide2x3")]
public void CanMultiplyMatrixWithMatrix(string nameA, string nameB)
{
var matrixA = TestMatrices[nameA];
var matrixB = TestMatrices[nameB];
@ -526,8 +542,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can transpose and multiply a matrix with matrix.
/// </summary>
/// <param name="nameA">Matrix name.</param>
[Test, Sequential]
public void CanTransposeAndMultiplyMatrixWithMatrix([Values("Singular3x3", "Singular4x4", "Wide2x3", "Tall3x2")] string nameA)
[TestCase("Singular3x3")]
[TestCase("Singular4x4")]
[TestCase("Wide2x3")]
[TestCase("Tall3x2")]
public void CanTransposeAndMultiplyMatrixWithMatrix(string nameA)
{
var matrixA = TestMatrices[nameA];
var matrixB = TestMatrices[nameA];
@ -605,8 +624,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can transpose and multiply a matrix with matrix into a result matrix.
/// </summary>
/// <param name="nameA">Matrix name.</param>
[Test, Sequential]
public void CanTransposeAndMultiplyMatrixWithMatrixIntoResult([Values("Singular3x3", "Singular4x4", "Wide2x3", "Tall3x2")] string nameA)
[TestCase("Singular3x3")]
[TestCase("Singular4x4")]
[TestCase("Wide2x3")]
[TestCase("Tall3x2")]
public void CanTransposeAndMultiplyMatrixWithMatrixIntoResult(string nameA)
{
var matrixA = TestMatrices[nameA];
var matrixB = TestMatrices[nameA];
@ -624,7 +646,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
}
}
}
/// <summary>
/// Multiply a matrix with incompatible size matrix throws <c>ArgumentException</c>.
/// </summary>
@ -663,8 +685,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="nameA">Matrix A name.</param>
/// <param name="nameB">Matrix B name.</param>
[Test, Sequential]
public virtual void CanMultiplyMatrixWithMatrixIntoResult([Values("Singular3x3", "Singular4x4", "Wide2x3", "Wide2x3", "Tall3x2")] string nameA, [Values("Square3x3", "Square4x4", "Square3x3", "Tall3x2", "Wide2x3")] string nameB)
[TestCase("Singular3x3", "Square3x3")]
[TestCase("Singular4x4", "Square4x4")]
[TestCase("Wide2x3", "Square3x3")]
[TestCase("Wide2x3", "Tall3x2")]
[TestCase("Tall3x2", "Wide2x3")]
public virtual void CanMultiplyMatrixWithMatrixIntoResult(string nameA, string nameB)
{
var matrixA = TestMatrices[nameA];
var matrixB = TestMatrices[nameB];
@ -772,8 +798,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can multiply transposed matrix with another matrix.
/// </summary>
/// <param name="nameA">Matrix name.</param>
[Test, Sequential]
public void CanTransposeThisAndMultiplyMatrixWithMatrix([Values("Singular3x3", "Singular4x4", "Wide2x3", "Tall3x2")] string nameA)
[TestCase("Singular3x3")]
[TestCase("Singular4x4")]
[TestCase("Wide2x3")]
[TestCase("Tall3x2")]
public void CanTransposeThisAndMultiplyMatrixWithMatrix(string nameA)
{
var matrixA = TestMatrices[nameA];
var matrixB = TestMatrices[nameA];
@ -817,8 +846,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Multiply transpose of this matrix with another matrix into a result matrix.
/// </summary>
/// <param name="nameA">Matrix name.</param>
[Test, Sequential]
public void CanTransposeThisAndMultiplyMatrixWithMatrixIntoResult([Values("Singular3x3", "Singular4x4", "Wide2x3", "Tall3x2")] string nameA)
[TestCase("Singular3x3")]
[TestCase("Singular4x4")]
[TestCase("Wide2x3")]
[TestCase("Tall3x2")]
public void CanTransposeThisAndMultiplyMatrixWithMatrixIntoResult(string nameA)
{
var matrixA = TestMatrices[nameA];
var matrixB = TestMatrices[nameA];
@ -841,8 +873,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can negate a matrix.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanNegate([Values("Singular3x3", "Singular4x4", "Wide2x3", "Wide2x3", "Tall3x2")] string name)
[TestCase("Singular3x3")]
[TestCase("Singular4x4")]
[TestCase("Wide2x3")]
[TestCase("Wide2x3")]
[TestCase("Tall3x2")]
public void CanNegate(string name)
{
var matrix = TestMatrices[name];
var copy = matrix.Clone();
@ -862,8 +898,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can negate a matrix into a result matrix.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanNegateIntoResult([Values("Singular3x3", "Singular4x4", "Wide2x3", "Wide2x3", "Tall3x2")] string name)
[TestCase("Singular3x3")]
[TestCase("Singular4x4")]
[TestCase("Wide2x3")]
[TestCase("Wide2x3")]
[TestCase("Tall3x2")]
public void CanNegateIntoResult(string name)
{
var matrix = TestMatrices[name];
var copy = matrix.Clone();
@ -965,8 +1005,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can normalize columns of a matrix.
/// </summary>
/// <param name="p">The norm under which to normalize the columns under.</param>
[Test, Sequential]
public void CanNormalizeColumns([Values(1, 2)] int p)
[TestCase(1)]
[TestCase(2)]
public void CanNormalizeColumns(int p)
{
var matrix = TestMatrices["Square4x4"];
var result = matrix.NormalizeColumns(p);
@ -990,8 +1031,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can normalize rows of a matrix.
/// </summary>
/// <param name="p">The norm under which to normalize the rows under.</param>
[Test, Sequential]
public void CanNormalizeRows([Values(1, 2)] int p)
[TestCase(1)]
[TestCase(2)]
public void CanNormalizeRows(int p)
{
var matrix = TestMatrices["Square4x4"].NormalizeRows(p);
for (var i = 0; i < matrix.RowCount; i++)
@ -1166,8 +1208,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Create random matrix with non-positive number of rows throw <c>ArgumentException</c>.
/// </summary>
/// <param name="numberOfRows">Number of rows.</param>
[Test, Sequential]
public void RandomWithNonPositiveNumberOfRowsThrowsArgumentException([Values(0, -2)] int numberOfRows)
[TestCase(0)]
[TestCase(-2)]
public void RandomWithNonPositiveNumberOfRowsThrowsArgumentException(int numberOfRows)
{
var matrix = CreateMatrix(2, 3);
Assert.Throws<ArgumentException>(() => matrix.Random(numberOfRows, 4, new ContinuousUniform()));

234
src/UnitTests/LinearAlgebraTests/Complex/MatrixTests.cs

@ -1,4 +1,4 @@
// <copyright file="MatrixTests.cs" company="Math.NET">
// <copyright file="MatrixTests.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -34,15 +34,18 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <summary>
/// Abstract class with the common set of matrix tests
/// </summary>
[TestFixture]
public abstract partial class MatrixTests : MatrixLoader
{
/// <summary>
/// Can clone a matrix.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanCloneMatrix([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanCloneMatrix(string name)
{
var matrix = CreateMatrix(TestData2D[name]);
var clone = matrix.Clone();
@ -63,8 +66,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can clone a matrix using <c>ICloneable</c> interface.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanCloneMatrixUsingICloneable([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanCloneMatrixUsingICloneable(string name)
{
var matrix = TestMatrices[name];
var clone = (Matrix<Complex>)((ICloneable)matrix).Clone();
@ -85,8 +92,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can copy a matrix to another matrix.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanCopyTo([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanCopyTo(string name)
{
var matrix = TestMatrices[name];
var copy = CreateMatrix(matrix.RowCount, matrix.ColumnCount);
@ -150,8 +161,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can equate matrices.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanEquateMatrices([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanEquateMatrices(string name)
{
var matrix1 = CreateMatrix(TestData2D[name]);
var matrix2 = CreateMatrix(TestData2D[name]);
@ -167,8 +182,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
[Test, Sequential]
public void IfSizeIsNotPositiveThrowsArgumentException([Values(0, 2, 0, -1, 1)] int rows, [Values(2, 0, 0, 1, -1)] int columns)
[TestCase(0, 2)]
[TestCase(2, 0)]
[TestCase(0, 0)]
[TestCase(-1, 1)]
[TestCase(1, -1)]
public void IfSizeIsNotPositiveThrowsArgumentException(int rows, int columns)
{
Assert.Throws<ArgumentOutOfRangeException>(() => CreateMatrix(rows, columns));
}
@ -177,8 +196,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Testing for equality with non-matrix returns <c>false</c>.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void TestingForEqualityWithNonMatrixReturnsFalse([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void TestingForEqualityWithNonMatrixReturnsFalse(string name)
{
var matrix = CreateMatrix(TestData2D[name]);
Assert.IsFalse(matrix.Equals(2));
@ -188,8 +211,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can test for equality using Object.Equals.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanTestForEqualityUsingObjectEquals([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanTestForEqualityUsingObjectEquals(string name)
{
var matrix1 = CreateMatrix(TestData2D[name]);
var matrix2 = CreateMatrix(TestData2D[name]);
@ -202,8 +229,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="i">Row index.</param>
/// <param name="j">Column index.</param>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void RangeCheckWithInvalidIndicesThrowsArgumentOutOfRangeException([Values(-1, 1, 4)] int i, [Values(1, -1, 2)] int j, [Values("Singular3x3", "Singular3x3", "Square3x3")] string name)
[TestCase(-1, 1, "Singular3x3")]
[TestCase(1, -1, "Singular3x3")]
[TestCase(4, 2, "Square3x3")]
public void RangeCheckWithInvalidIndicesThrowsArgumentOutOfRangeException(int i, int j, string name)
{
Assert.Throws<ArgumentOutOfRangeException>(() => { var x = TestMatrices[name][i, j]; });
}
@ -239,8 +268,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="rowIndex">Row index.</param>
/// <param name="name">Matrix name.</param>
[Test, Combinatorial]
public void CanGetRow([Values(0, 1, 2)] int rowIndex, [Values("Singular3x3", "Square3x3")] string name)
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetRow(int rowIndex, string name)
{
var matrix = TestMatrices[name];
var row = matrix.Row(rowIndex);
@ -277,8 +308,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="rowIndex">Row index.</param>
/// <param name="name">Matrix name.</param>
[Test, Combinatorial]
public void CanGetRowIntoResult([Values(0, 1, 2)] int rowIndex, [Values("Singular3x3", "Square3x3")] string name)
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetRowIntoResult(int rowIndex, string name)
{
var matrix = TestMatrices[name];
var row = CreateVector(matrix.ColumnCount);
@ -330,8 +363,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="start">Column start.</param>
/// <param name="length">Row length.</param>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanGetRowWithRange([Values(0, 1, 2, 2)] int rowIndex, [Values(0, 1, 0, 0)] int start, [Values(1, 2, 3, 3)] int length, [Values("Singular3x3", "Singular3x3", "Singular3x3", "Square3x3")] string name)
[TestCase(0, 0, 1, "Singular3x3")]
[TestCase(1, 1, 2, "Singular3x3")]
[TestCase(2, 0, 3, "Singular3x3")]
[TestCase(2, 0, 3, "Square3x3")]
public void CanGetRowWithRange(int rowIndex, int start, int length, string name)
{
var matrix = TestMatrices[name];
var row = matrix.Row(rowIndex, start, length);
@ -370,8 +406,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="colIndex">Row index.</param>
/// <param name="name">Matrix name.</param>
[Test, Combinatorial]
public void CanGetColumn([Values(0, 1, 2)] int colIndex, [Values("Singular3x3", "Square3x3")] string name)
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetColumn(int colIndex, string name)
{
var matrix = TestMatrices[name];
var col = matrix.Column(colIndex);
@ -408,8 +446,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="colIndex">Column index.</param>
/// <param name="name">Matrix name.</param>
[Test, Combinatorial]
public void CanGetColumnIntoResult([Values(0, 1, 2)] int colIndex, [Values("Singular3x3", "Square3x3")] string name)
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanGetColumnIntoResult(int colIndex, string name)
{
var matrix = TestMatrices[name];
var col = CreateVector(matrix.RowCount);
@ -461,8 +501,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="start">Start index.</param>
/// <param name="length">Column length.</param>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanGetColumnWithRange([Values(0, 1, 2, 2)] int colIndex, [Values(0, 1, 0, 0)] int start, [Values(1, 2, 3, 3)] int length, [Values("Singular3x3", "Singular3x3", "Singular3x3", "Square3x3")] string name)
[TestCase(0, 0, 1, "Singular3x3")]
[TestCase(1, 1, 2, "Singular3x3")]
[TestCase(2, 0, 3, "Singular3x3")]
[TestCase(2, 0, 3, "Square3x3")]
public void CanGetColumnWithRange(int colIndex, int start, int length, string name)
{
var matrix = TestMatrices[name];
var col = matrix.Column(colIndex, start, length);
@ -501,8 +544,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="rowIndex">Row index.</param>
/// <param name="name">Matrix name.</param>
[Test, Combinatorial]
public void CanSetRow([Values(0, 1, 2)] int rowIndex, [Values("Singular3x3", "Square3x3")] string name)
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanSetRow(int rowIndex, string name)
{
var matrix = TestMatrices[name].Clone();
matrix.SetRow(rowIndex, CreateVector(matrix.ColumnCount));
@ -521,8 +566,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="colIndex">Column index.</param>
/// <param name="name">Matrix name.</param>
[Test, Combinatorial]
public void CanSetColumn([Values(0, 1, 2)] int colIndex, [Values("Singular3x3", "Square3x3")] string name)
[TestCase(0, "Singular3x3")]
[TestCase(1, "Square3x3")]
[TestCase(2, "Square3x3")]
public void CanSetColumn(int colIndex, string name)
{
var matrix = TestMatrices[name].Clone();
matrix.SetColumn(colIndex, CreateVector(matrix.ColumnCount));
@ -540,8 +587,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Get an upper triangle matrix.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanUpperTriangle([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanUpperTriangle(string name)
{
var data = TestMatrices[name];
var upper = data.UpperTriangle();
@ -558,8 +609,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Get an upper triangle matrix into a result matrix.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanUpperTriangleIntoResult([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanUpperTriangleIntoResult(string name)
{
var data = TestMatrices[name];
var result = CreateMatrix(data.RowCount, data.ColumnCount);
@ -610,8 +665,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Get a lower triangle matrix.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanLowerTriangle([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanLowerTriangle(string name)
{
var data = TestMatrices[name];
var lower = data.LowerTriangle();
@ -628,8 +687,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Get a lower triangle matrix into a result matrix.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanLowerTriangleIntoResult([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanLowerTriangleIntoResult(string name)
{
var data = TestMatrices[name];
var result = CreateMatrix(data.RowCount, data.ColumnCount);
@ -824,8 +887,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can transpose a matrix.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanTransposeMatrix([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanTransposeMatrix(string name)
{
var matrix = CreateMatrix(TestData2D[name]);
var transpose = matrix.Transpose();
@ -846,8 +913,12 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can conjugate transpose a matrix.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public void CanConjugateTransposeMatrix([Values("Singular3x3", "Square3x3", "Square4x4", "Tall3x2", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Square4x4")]
[TestCase("Tall3x2")]
[TestCase("Wide2x3")]
public void CanConjugateTransposeMatrix(string name)
{
var matrix = CreateMatrix(TestData2D[name]);
var transpose = matrix.ConjugateTranspose();
@ -869,8 +940,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="name">Matrix name.</param>
/// <param name="real">Column real values array.</param>
[Test, Sequential]
public virtual void CanSetColumnWithArray([Values("Singular3x3", "Square3x3", "Tall3x2", "Wide2x3")] string name, [Values(new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new double[] { 1, 2 })] double[] real)
[TestCase("Singular3x3", new double[] { 1, 2, 3 })]
[TestCase("Square3x3", new double[] { 1, 2, 3 })]
[TestCase("Tall3x2", new double[] { 1, 2, 3 })]
[TestCase("Wide2x3", new double[] { 1, 2 })]
public virtual void CanSetColumnWithArray(string name, double[] real)
{
var column = new Complex[real.Length];
for (var i = 0; i < real.Length; i++)
@ -926,8 +1000,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="name">Matrix name.</param>
/// <param name="real">Column real values.</param>
[Test, Sequential]
public virtual void CanSetColumnWithVector([Values("Singular3x3", "Square3x3", "Tall3x2", "Wide2x3")] string name, [Values(new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new double[] { 1, 2 })] double[] real)
[TestCase("Singular3x3", new double[] { 1, 2, 3 })]
[TestCase("Square3x3", new double[] { 1, 2, 3 })]
[TestCase("Tall3x2", new double[] { 1, 2, 3 })]
[TestCase("Wide2x3", new double[] { 1, 2 })]
public virtual void CanSetColumnWithVector(string name, double[] real)
{
var column = new Complex[real.Length];
for (var i = 0; i < real.Length; i++)
@ -1046,8 +1123,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="name">Matrix name.</param>
/// <param name="real">Row index.</param>
[Test, Sequential]
public virtual void CanSetRowWithArray([Values("Singular3x3", "Square3x3", "Tall3x2", "Wide2x3")] string name, [Values(new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new double[] { 1, 2 }, new double[] { 1, 2, 3 })] double[] real)
[TestCase("Singular3x3", new double[] { 1, 2, 3 })]
[TestCase("Square3x3", new double[] { 1, 2, 3 })]
[TestCase("Tall3x2", new double[] { 1, 2 })]
[TestCase("Wide2x3", new double[] { 1, 2, 3 })]
public virtual void CanSetRowWithArray(string name, double[] real)
{
var row = new Complex[real.Length];
for (var i = 0; i < real.Length; i++)
@ -1093,8 +1173,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="name">Matrix name.</param>
/// <param name="real">Row real values.</param>
[Test, Sequential]
public virtual void CanSetRowWithVector([Values("Singular3x3", "Square3x3", "Tall3x2", "Wide2x3")] string name, [Values(new double[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new double[] { 1, 2 }, new double[] { 1, 2, 3 })] double[] real)
[TestCase("Singular3x3", new double[] { 1, 2, 3 })]
[TestCase("Square3x3", new double[] { 1, 2, 3 })]
[TestCase("Tall3x2", new double[] { 1, 2 })]
[TestCase("Wide2x3", new double[] { 1, 2, 3 })]
public virtual void CanSetRowWithVector(string name, double[] real)
{
var row = new Complex[real.Length];
for (var i = 0; i < real.Length; i++)
@ -1154,8 +1237,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="rowLength">The number of rows to copy.</param>
/// <param name="colStart">The column to start copying to.</param>
/// <param name="colLength">The number of columns to copy.</param>
[Test, Sequential]
public virtual void CanSetSubMatrix([Values(0, 1)] int rowStart, [Values(2, 1)] int rowLength, [Values(0, 1)] int colStart, [Values(2, 1)] int colLength)
[TestCase(0, 2, 0, 2)]
[TestCase(1, 1, 1, 1)]
public virtual void CanSetSubMatrix(int rowStart, int rowLength, int colStart, int colLength)
{
foreach (var matrix in TestMatrices.Values)
{
@ -1183,8 +1267,13 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="rowLength">The number of rows to copy.</param>
/// <param name="colStart">The column to start copying to.</param>
/// <param name="colLength">The number of columns to copy.</param>
[Test, Sequential]
public virtual void SetSubMatrixWithInvalidRangesThrowsArgumentOutOfRangeException([Values(0, 0, 4, 0, -1, 0)] int rowStart, [Values(4, 2, 2, 2, 2, 2)] int rowLength, [Values(0, 0, 0, 4, 0, -1)] int colStart, [Values(2, 4, 2, 2, 2, 2)] int colLength)
[TestCase(0, 4, 0, 2)]
[TestCase(0, 2, 0, 4)]
[TestCase(4, 2, 0, 2)]
[TestCase(0, 2, 4, 2)]
[TestCase(-1, 2, 0, 2)]
[TestCase(0, 2, -1, 2)]
public virtual void SetSubMatrixWithInvalidRangesThrowsArgumentOutOfRangeException(int rowStart, int rowLength, int colStart, int colLength)
{
var subMatrix = TestMatrices["Square3x3"].SubMatrix(0, 2, 0, 2);
subMatrix[0, 0] = 10.0;
@ -1201,8 +1290,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// <param name="rowLength">The number of rows to copy.</param>
/// <param name="colStart">The column to start copying to.</param>
/// <param name="colLength">The number of columns to copy.</param>
[Test, Sequential]
public virtual void SetSubMatrixWithInvalidLengthsThrowsArgumentException([Values(0, 0)] int rowStart, [Values(-1, 2)] int rowLength, [Values(0, 0)] int colStart, [Values(2, -1)] int colLength)
[TestCase(0, -1, 0, 2)]
[TestCase(0, 2, 0, -1)]
public virtual void SetSubMatrixWithInvalidLengthsThrowsArgumentException(int rowStart, int rowLength, int colStart, int colLength)
{
var subMatrix = TestMatrices["Square3x3"].SubMatrix(0, 2, 0, 2);
subMatrix[0, 0] = 10.0;
@ -1227,8 +1317,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="name">Matrix name.</param>
/// <param name="real">Diagonal real values.</param>
[Test, Sequential]
public void CanSetDiagonalVector([Values("Square3x3", "Wide2x3", "Tall3x2")] string name, [Values(new double[] { 1, 2, 3 }, new double[] { 1, 2 }, new double[] { 1, 2 })] double[] real)
[TestCase("Square3x3", new double[] { 1, 2, 3 })]
[TestCase("Wide2x3", new double[] { 1, 2 })]
[TestCase("Tall3x2", new double[] { 1, 2 })]
public void CanSetDiagonalVector(string name, double[] real)
{
var diagonal = new Complex[real.Length];
for (var i = 0; i < real.Length; i++)
@ -1274,8 +1366,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// </summary>
/// <param name="name">Matrix name.</param>
/// <param name="real">Diagonal real values.</param>
[Test, Sequential]
public void CanSetDiagonalArray([Values("Square3x3", "Wide2x3", "Tall3x2")] string name, [Values(new double[] { 1, 2, 3 }, new double[] { 1, 2 }, new double[] { 1, 2 })] double[] real)
[TestCase("Square3x3", new double[] { 1, 2, 3 })]
[TestCase("Wide2x3", new double[] { 1, 2 })]
[TestCase("Tall3x2", new double[] { 1, 2 })]
public void CanSetDiagonalArray(string name, double[] real)
{
var diagonal = new Complex[real.Length];
for (var i = 0; i < real.Length; i++)
@ -1443,8 +1537,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can permute matrix rows.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public virtual void CanPermuteMatrixRows([Values("Singular3x3", "Square3x3", "Tall3x2")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Tall3x2")]
public virtual void CanPermuteMatrixRows(string name)
{
var matrix = CreateMatrix(TestData2D[name]);
var matrixp = CreateMatrix(TestData2D[name]);
@ -1468,8 +1564,10 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
/// Can permute matrix columns.
/// </summary>
/// <param name="name">Matrix name.</param>
[Test, Sequential]
public virtual void CanPermuteMatrixColumns([Values("Singular3x3", "Square3x3", "Wide2x3")] string name)
[TestCase("Singular3x3")]
[TestCase("Square3x3")]
[TestCase("Wide2x3")]
public virtual void CanPermuteMatrixColumns(string name)
{
var matrix = CreateMatrix(TestData2D[name]);
var matrixp = CreateMatrix(TestData2D[name]);

39
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/BiCgStabTest.cs

@ -92,9 +92,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
var solver = new BiCgStab(monitor);
@ -137,9 +137,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
var solver = new BiCgStab(monitor);
@ -215,9 +215,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
var solver = new BiCgStab(monitor);
@ -246,16 +246,18 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
/// Can solve for a random vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(4, 8, 10)] int order)
[TestCase(4)]
[TestCase(8)]
[TestCase(10)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var vectorb = MatrixLoader.GenerateRandomDenseVector(order);
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
});
var solver = new BiCgStab(monitor);
@ -276,16 +278,18 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
/// Can solve for random matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrix([Values(4, 8, 10)] int order)
[TestCase(4)]
[TestCase(8)]
[TestCase(10)]
public void CanSolveForRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
});
var solver = new BiCgStab(monitor);
var matrixX = solver.Solve(matrixA, matrixB);
@ -297,6 +301,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
Assert.AreEqual(matrixB.ColumnCount, matrixX.ColumnCount);
var matrixBReconstruct = matrixA * matrixX;
// Check the reconstruction.
for (var i = 0; i < matrixB.RowCount; i++)
{

39
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/GpBiCgTest.cs

@ -91,9 +91,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
var solver = new GpBiCg(monitor);
@ -136,9 +136,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
@ -215,9 +215,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
@ -247,16 +247,18 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
/// Can solve for a random vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(4, 8, 10)] int order)
[TestCase(4)]
[TestCase(8)]
[TestCase(10)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var vectorb = MatrixLoader.GenerateRandomDenseVector(order);
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
});
var solver = new GpBiCg(monitor);
@ -277,16 +279,18 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
/// Can solve for random matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrix([Values(4, 8, 10)] int order)
[TestCase(4)]
[TestCase(8)]
[TestCase(10)]
public void CanSolveForRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
});
var solver = new GpBiCg(monitor);
var matrixX = solver.Solve(matrixA, matrixB);
@ -298,6 +302,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
Assert.AreEqual(matrixB.ColumnCount, matrixX.ColumnCount);
var matrixBReconstruct = matrixA * matrixX;
// Check the reconstruction.
for (var i = 0; i < matrixB.RowCount; i++)
{

38
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/MlkBiCgStabTest.cs

@ -90,9 +90,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
@ -136,9 +136,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
var solver = new MlkBiCgStab(monitor);
@ -214,9 +214,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
var solver = new MlkBiCgStab(monitor);
@ -245,16 +245,18 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
/// Can solve for a random vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(4, 8, 10)] int order)
[TestCase(4)]
[TestCase(8)]
[TestCase(10)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var vectorb = MatrixLoader.GenerateRandomDenseVector(order);
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
});
var solver = new MlkBiCgStab(monitor);
@ -275,16 +277,18 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
/// Can solve for random matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrix([Values(4, 8, 10)] int order)
[TestCase(4)]
[TestCase(8)]
[TestCase(10)]
public void CanSolveForRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
});
var solver = new MlkBiCgStab(monitor);
var matrixX = solver.Solve(matrixA, matrixB);

38
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Iterative/TFQMRTest.cs

@ -90,9 +90,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
@ -136,9 +136,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
var solver = new TFQMR(monitor);
@ -214,9 +214,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(MaximumIterations),
new ResidualStopCriterium(ConvergenceBoundary),
new DivergenceStopCriterium(),
new FailureStopCriterium()
});
var solver = new TFQMR(monitor);
@ -245,16 +245,18 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
/// Can solve for a random vector.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomVector([Values(4, 8, 10)] int order)
[TestCase(4)]
[TestCase(8)]
[TestCase(10)]
public void CanSolveForRandomVector(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var vectorb = MatrixLoader.GenerateRandomDenseVector(order);
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
});
var solver = new TFQMR(monitor);
@ -275,16 +277,18 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Iterativ
/// Can solve for random matrix.
/// </summary>
/// <param name="order">Matrix order.</param>
[Test]
public void CanSolveForRandomMatrix([Values(4, 8, 10)] int order)
[TestCase(4)]
[TestCase(8)]
[TestCase(10)]
public void CanSolveForRandomMatrix(int order)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var matrixB = MatrixLoader.GenerateRandomDenseMatrix(order, order);
var monitor = new Iterator(new IIterationStopCriterium[]
{
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
new IterationCountStopCriterium(1000),
new ResidualStopCriterium(1e-10),
});
var solver = new TFQMR(monitor);
var matrixX = solver.Solve(matrixA, matrixB);

121
src/UnitTests/LinearAlgebraTests/Complex/Solvers/IteratorTest.cs

@ -1,4 +1,4 @@
// <copyright file="IteratorTest.cs" company="Math.NET">
// <copyright file="IteratorTest.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
@ -81,7 +81,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
Assert.Throws<ArgumentException>(() => new Iterator(new IIterationStopCriterium[]
{
new FailureStopCriterium(),
new FailureStopCriterium(),
new FailureStopCriterium()
}));
}
@ -94,9 +94,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new ResidualStopCriterium()
};
var iterator = new Iterator(criteria);
@ -143,9 +143,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new ResidualStopCriterium()
};
var iterator = new Iterator();
@ -175,9 +175,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new ResidualStopCriterium()
};
var iterator = new Iterator(criteria);
@ -194,9 +194,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
};
var iterator = new Iterator(criteria);
Assert.AreEqual(criteria.Count, iterator.NumberOfCriteria, "Incorrect criterium count");
@ -213,9 +213,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new ResidualStopCriterium()
};
var iterator = new Iterator(criteria);
@ -236,9 +236,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var iterator = new Iterator();
Assert.Throws<ArgumentException>(() => iterator.DetermineStatus(
0,
new DenseVector(3, 4),
new DenseVector(3, 5),
0,
new DenseVector(3, 4),
new DenseVector(3, 5),
new DenseVector(3, 6)));
}
@ -250,17 +250,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new ResidualStopCriterium()
};
var iterator = new Iterator(criteria);
Assert.Throws<ArgumentOutOfRangeException>(() => iterator.DetermineStatus(
-1,
new DenseVector(3, 4),
new DenseVector(3, 5),
-1,
new DenseVector(3, 4),
new DenseVector(3, 5),
new DenseVector(3, 6)));
}
@ -272,17 +272,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new ResidualStopCriterium()
};
var iterator = new Iterator(criteria);
Assert.Throws<ArgumentNullException>(() => iterator.DetermineStatus(
1,
null,
new DenseVector(3, 5),
1,
null,
new DenseVector(3, 5),
new DenseVector(3, 6)));
}
@ -294,17 +294,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new ResidualStopCriterium()
};
var iterator = new Iterator(criteria);
Assert.Throws<ArgumentNullException>(() => iterator.DetermineStatus(
1,
new DenseVector(3, 5),
null,
1,
new DenseVector(3, 5),
null,
new DenseVector(3, 6)));
}
@ -316,17 +316,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new ResidualStopCriterium()
};
var iterator = new Iterator(criteria);
Assert.Throws<ArgumentNullException>(() => iterator.DetermineStatus(
1,
new DenseVector(3, 4),
new DenseVector(3, 5),
1,
new DenseVector(3, 4),
new DenseVector(3, 5),
null));
}
@ -338,8 +338,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(1)
};
@ -347,17 +347,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
// First step, nothing should happen.
iterator.DetermineStatus(
0,
new DenseVector(3, 4),
new DenseVector(3, 4),
0,
new DenseVector(3, 4),
new DenseVector(3, 4),
new DenseVector(3, 4));
Assert.IsInstanceOf(typeof(CalculationRunning), iterator.Status, "Incorrect status");
// Second step, should run out of iterations.
iterator.DetermineStatus(
1,
new DenseVector(3, 4),
new DenseVector(3, 4),
1,
new DenseVector(3, 4),
new DenseVector(3, 4),
new DenseVector(3, 4));
Assert.IsInstanceOf(typeof(CalculationStoppedWithoutConvergence), iterator.Status, "Incorrect status");
}
@ -370,8 +370,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(1)
};
@ -379,9 +379,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
// First step, nothing should happen.
iterator.DetermineStatus(
0,
new DenseVector(3, 4),
new DenseVector(3, 4),
0,
new DenseVector(3, 4),
new DenseVector(3, 4),
new DenseVector(3, 4));
Assert.IsInstanceOf(typeof(CalculationRunning), iterator.Status, "Incorrect status");
@ -400,9 +400,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
{
var criteria = new List<IIterationStopCriterium>
{
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new FailureStopCriterium(),
new DivergenceStopCriterium(),
new IterationCountStopCriterium(),
new ResidualStopCriterium()
};
@ -416,6 +416,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers
// ReSharper disable PossibleNullReferenceException
Assert.AreEqual(iterator.NumberOfCriteria, clone.NumberOfCriteria, "Incorrect criterium count");
// ReSharper restore PossibleNullReferenceException
var enumerator = clone.StoredStopCriteria;
while (enumerator.MoveNext())

26
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IlutpTest.cs

@ -74,11 +74,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
{
var type = ilutp.GetType();
var methodInfo = type.GetMethod(
methodName,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static,
null,
CallingConventions.Standard,
new Type[0],
methodName,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static,
null,
CallingConventions.Standard,
new Type[0],
null);
var obj = methodInfo.Invoke(ilutp, null);
return (T)obj;
@ -138,8 +138,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
{
var result = new Ilutp
{
DropTolerance = _dropTolerance,
FillLevel = _fillLevel,
DropTolerance = _dropTolerance,
FillLevel = _fillLevel,
PivotTolerance = _pivotTolerance
};
return result;
@ -240,8 +240,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
sparseMatrix[2, 2] = 9;
var ilu = new Ilutp
{
PivotTolerance = 0.0,
DropTolerance = 0,
PivotTolerance = 0.0,
DropTolerance = 0,
FillLevel = 10
};
ilu.Initialize(sparseMatrix);
@ -296,8 +296,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
sparseMatrix[2, 2] = 9;
var ilu = new Ilutp
{
PivotTolerance = 1.0,
DropTolerance = 0,
PivotTolerance = 1.0,
DropTolerance = 0,
FillLevel = 10
};
ilu.Initialize(sparseMatrix);
@ -333,8 +333,8 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
var vector = CreateStandardBcVector(Size);
var preconditioner = new Ilutp
{
PivotTolerance = 1.0,
DropTolerance = 0,
PivotTolerance = 1.0,
DropTolerance = 0,
FillLevel = 10
};
preconditioner.Initialize(newMatrix);

10
src/UnitTests/LinearAlgebraTests/Complex/Solvers/Preconditioners/IncompleteLUTest.cs

@ -48,11 +48,11 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.Precondi
{
var type = ilu.GetType();
var methodInfo = type.GetMethod(
methodName,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static,
null,
CallingConventions.Standard,
new Type[0],
methodName,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static,
null,
CallingConventions.Standard,
new Type[0],
null);
var obj = methodInfo.Invoke(ilu, null);
return (T)obj;

55
src/UnitTests/LinearAlgebraTests/Complex/Solvers/StopCriterium/DivergenceStopCriteriumTest.cs

@ -108,9 +108,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.StopCrit
{
var criterium = new DivergenceStopCriterium(0.5, 15);
Assert.Throws<ArgumentOutOfRangeException>(() => criterium.DetermineStatus(
-1,
new DenseVector(3, 4),
new DenseVector(3, 5),
-1,
new DenseVector(3, 4),
new DenseVector(3, 5),
new DenseVector(3, 6)));
}
@ -122,9 +122,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.StopCrit
{
var criterium = new DivergenceStopCriterium(0.5, 15);
Assert.Throws<ArgumentNullException>(() => criterium.DetermineStatus(
1,
new DenseVector(3, 4),
new DenseVector(3, 5),
1,
new DenseVector(3, 4),
new DenseVector(3, 5),
null));
}
@ -143,9 +143,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.StopCrit
for (var i = 0; i < Iterations - 1; i++)
{
criterium.DetermineStatus(
i,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
i,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex((i + 1) * (Increase + 0.1), 0) }));
Assert.IsInstanceOf(typeof(CalculationRunning), criterium.Status, "Status check fail.");
@ -167,9 +167,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.StopCrit
for (var i = 0; i < Iterations * 2; i++)
{
criterium.DetermineStatus(
i,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
i,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex((i + 1) * (Increase - 0.01), 0) }));
Assert.IsInstanceOf(typeof(CalculationRunning), criterium.Status, "Status check fail.");
@ -191,9 +191,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.StopCrit
for (var i = 0; i < Iterations - 5; i++)
{
criterium.DetermineStatus(
i,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
i,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex((i + 1) * (Increase - 0.01), 0) }));
Assert.IsInstanceOf(typeof(CalculationRunning), criterium.Status, "Status check fail.");
@ -201,9 +201,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.StopCrit
// Now make it fail by throwing in a NaN
criterium.DetermineStatus(
Iterations,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
Iterations,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(double.NaN, 0) }));
Assert.IsInstanceOf(typeof(CalculationDiverged), criterium.Status, "Status check fail.");
@ -226,9 +226,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.StopCrit
{
previous *= 1 + Increase + 0.01;
criterium.DetermineStatus(
i,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
i,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(previous, 0) }));
Assert.IsInstanceOf(typeof(CalculationRunning), criterium.Status, "Status check fail.");
@ -237,9 +237,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.StopCrit
// Add the final residual. Now we should have divergence
previous *= 1 + Increase + 0.01;
criterium.DetermineStatus(
Iterations - 1,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
Iterations - 1,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(previous, 0) }));
Assert.IsInstanceOf(typeof(CalculationDiverged), criterium.Status, "Status check fail.");
@ -258,9 +258,9 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.StopCrit
// Add residuals. Blow it up instantly
criterium.DetermineStatus(
1,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
1,
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(1.0, 0) }),
new DenseVector(new[] { new Complex(double.NaN, 0) }));
Assert.IsInstanceOf(typeof(CalculationDiverged), criterium.Status, "Status check fail.");
@ -294,6 +294,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex.Solvers.StopCrit
// ReSharper disable PossibleNullReferenceException
Assert.AreEqual(criterium.MaximumRelativeIncrease, clonedCriterium.MaximumRelativeIncrease, "Incorrect maximum");
Assert.AreEqual(criterium.MinimumNumberOfIterations, clonedCriterium.MinimumNumberOfIterations, "Incorrect iteration count");
// ReSharper restore PossibleNullReferenceException
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save