Table of Contents

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

value double
forward Func<double, double>
inverse Func<double, double>
tolerance double

Returns

bool

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

value double
expected double
tolerance double

Returns

bool

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

value float
expected float
tolerance float

Returns

bool

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

value double
expected double
ulpDistance long

Returns

bool

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

value float
expected float
ulpDistance int

Returns

bool

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

value double

Returns

bool

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

value double

Returns

bool

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

value double

Returns

bool

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)

Parameters

value double
expected double
relativeTolerance double
absoluteTolerance double

Returns

bool