Class ScalarAssertions
- Namespace
- MathAssertions.TUnit
- Assembly
- MathAssertions.TUnit.dll
Fluent scalar (double / float) assertions delegating to
MathTolerance. The wrappers exist so consumers can write
await Assert.That(value).IsApproximatelyEqualTo(expected, tolerance) rather than
await Assert.That(MathTolerance.IsApproximatelyEqual(value, expected, tolerance)).IsTrue().
public static class ScalarAssertions
- Inheritance
-
ScalarAssertions
- Inherited Members
Methods
HasRoundtripIdentity(double, Func<double, double>, Func<double, double>, double)
Asserts the roundtrip inverse(forward(value)) recovers value
within tolerance.
[GenerateAssertion(ExpectationMessage = "to roundtrip through forward/inverse within tolerance {tolerance}", InlineMethodBody = true)]
public static bool HasRoundtripIdentity(this double value, Func<double, double> forward, Func<double, double> inverse, double tolerance)
Parameters
Returns
IsApproximatelyEqualTo(double, double, double)
NaN- and infinity-aware tolerance comparison for double.
[GenerateAssertion(ExpectationMessage = "to be approximately equal to {expected} within tolerance {tolerance}", InlineMethodBody = true)]
public static bool IsApproximatelyEqualTo(this double value, double expected, double tolerance)
Parameters
Returns
IsApproximatelyEqualTo(float, float, float)
NaN- and infinity-aware tolerance comparison for float.
[GenerateAssertion(ExpectationMessage = "to be approximately equal to {expected} within tolerance {tolerance}", InlineMethodBody = true)]
public static bool IsApproximatelyEqualTo(this float value, float expected, float tolerance)
Parameters
Returns
IsCloseInUlpsTo(double, double, long)
ULP-distance equality for double.
[GenerateAssertion(ExpectationMessage = "to be within {ulpDistance} ULPs of {expected}", InlineMethodBody = true)]
public static bool IsCloseInUlpsTo(this double value, double expected, long ulpDistance)
Parameters
Returns
IsCloseInUlpsTo(float, float, int)
ULP-distance equality for float.
[GenerateAssertion(ExpectationMessage = "to be within {ulpDistance} ULPs of {expected}", InlineMethodBody = true)]
public static bool IsCloseInUlpsTo(this float value, float expected, int ulpDistance)
Parameters
Returns
IsNonNegativeFinite(double)
Asserts the value is finite and non-negative.
[GenerateAssertion(ExpectationMessage = "to be a finite non-negative value", InlineMethodBody = true)]
public static bool IsNonNegativeFinite(this double value)
Parameters
valuedouble
Returns
IsPercentage(double)
Asserts the value is finite and in the closed interval [0, 100].
[GenerateAssertion(ExpectationMessage = "to be a percentage (finite, in [0, 100])", InlineMethodBody = true)]
public static bool IsPercentage(this double value)
Parameters
valuedouble
Returns
IsProbability(double)
Asserts the value is finite and in the closed interval [0, 1].
[GenerateAssertion(ExpectationMessage = "to be a probability (finite, in [0, 1])", InlineMethodBody = true)]
public static bool IsProbability(this double value)
Parameters
valuedouble
Returns
IsRelativelyAndAbsolutelyCloseTo(double, double, double, double)
Combined relative + absolute tolerance equality for double.
[GenerateAssertion(ExpectationMessage = "to be within relative tolerance {relativeTolerance} or absolute tolerance {absoluteTolerance} of {expected}", InlineMethodBody = true)]
public static bool IsRelativelyAndAbsolutelyCloseTo(this double value, double expected, double relativeTolerance, double absoluteTolerance)