MathAssertions.TUnit 0.0.1

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package MathAssertions.TUnit --version 0.0.1
                    
NuGet\Install-Package MathAssertions.TUnit -Version 0.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MathAssertions.TUnit" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MathAssertions.TUnit" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MathAssertions.TUnit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MathAssertions.TUnit --version 0.0.1
                    
#r "nuget: MathAssertions.TUnit, 0.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MathAssertions.TUnit@0.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MathAssertions.TUnit&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=MathAssertions.TUnit&version=0.0.1
                    
Install as a Cake Tool

MathAssertions.TUnit

NuGet Downloads License: MIT .NET

Scope: Test projects only. Not intended for production code.

TUnit-native fluent math-assertion DSL for System.Numerics compound types and BCL floating-point primitives. NaN-aware, infinity-aware, AOT-compatible, no runtime reflection in the assertion path.

Full documentation, "Why component-wise rather than Euclidean", cookbook, design notes, and roadmap: github.com/JohnVerheij/MathAssertions.TUnit

Status: v0.0.1 (initial preview)

This first release is a deliberately narrow skeleton. v0.0.1 ships a single fluent entry point: Vector3.IsApproximatelyEqualTo(expected, tolerance). The wider System.Numerics catalog plus statistics, linear-algebra invariants, number theory, and 3D-geometry surface land at v0.1.0.

Install

dotnet add package MathAssertions.TUnit

MathAssertions (the framework-agnostic core) comes transitively. Requirements: TUnit 1.43.11 or later, .NET 10.

The source-generated entry point (IsApproximatelyEqualTo on Vector3) auto-imports via TUnit.Assertions.Extensions. The only additional using you typically need is System.Numerics for the value type itself. If you call MathTolerance.IsApproximatelyEqual directly from a [GenerateAssertion] extension on a private domain type, add MathAssertions to your GlobalUsings.cs:

global using MathAssertions;

Quick start

using System.Numerics;

[Test]
public async Task ComputedPositionIsApproximatelyAtTarget(CancellationToken ct)
{
    Vector3 target = new(0.300f, 0.150f, 0.450f);
    Vector3 actual = SolveTrajectory(input);

    await Assert.That(actual).IsApproximatelyEqualTo(target, tolerance: 1e-3);
}

Entry points (v0.0.1)

Method Purpose
IsApproximatelyEqualTo(Vector3 expected, double tolerance) Component-wise tolerance check; components widen to double for precision; NaN-aware, infinity-aware (matches TUnit's primitive IsCloseTo semantics).

The wider catalog (Vector2/4, Quaternion + rotational equivalence, Matrix4x4, Plane + geometric equivalence, Complex, double[]/float[], spans) lands at v0.1.0 alongside additional method families (statistics, linear-algebra invariants, number theory, 3D geometry).

Extending to your own types

Add tolerance assertions for your own domain types via a one-line [GenerateAssertion] extension calling MathTolerance.IsApproximatelyEqual on each component. The package never sees your private types.

using MathAssertions;
using TUnit.Assertions.Attributes;

file static class PositionAssertions
{
    [GenerateAssertion(
        ExpectationMessage = "to be approximately equal to {expected} within tolerance {tolerance}",
        InlineMethodBody = true)]
    public static bool IsApproximatelyEqualTo(this MyPosition value, MyPosition expected, double tolerance)
        => MathTolerance.IsApproximatelyEqual(value.AsVector3(), expected.AsVector3(), tolerance);
}

Failure diagnostics

On a failed assertion, the exception message renders the actual Vector3 against the expected and the supplied tolerance:

Expected:
  to be approximately equal to <1, 2, 99> component-wise within tolerance 0.001

Actual:
  <1, 2, 3>

Full failure-diagnostics examples, design notes, stability intent, and roadmap on GitHub.

Family

Part of an assertion family for TUnit:

License

MIT. Copyright (c) 2026 John Verheij.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.0 544 6/14/2026
0.4.3 1,456 6/12/2026
0.4.2 161 6/5/2026
0.4.1 255 6/3/2026
0.4.0 153 6/2/2026
0.3.0 265 5/14/2026
0.2.0 276 5/12/2026
0.1.0 181 5/9/2026
0.0.1 156 5/8/2026

See CHANGELOG.md