assert

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package assert provides numpy.testing-style assertions for numgo arrays, for use in downstream tests.

numpy.testing mapping:

assert_equal              Equal
assert_not_equal          NotEqual
assert_array_equal        ArrayEqual            (NaN == NaN)
assert_array_not_equal    ArrayNotEqual
assert_array_almost_equal ArrayAlmostEqual      (|a-b| < 0.5·10^-decimal)
assert_allclose           AllClose / AllCloseNan
assert_array_less         ArrayLess / ArrayLessEqual
assert_raises             Raises
(inline shape checks)     Shape
assert_array_max_ulp      not implemented

All assertion functions accept testing.TB, so a *testing.T (or *testing.B) is passed directly; the TB interface also enables failure-message tests with a mock recorder. Failure paths report via t.Errorf (formatted numpy style) and return, never Fatal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllClose

func AllClose[T numgo.Number](t testing.TB, got, want *numgo.Array[T], rtol, atol float64)

AllClose asserts |got-want| <= atol + rtol*|want| for every element (numpy assert_allclose). Note rtol scales with want — the DESIRED argument, matching numpy's |b|. Same-sign infinities are equal; any NaN mismatches (use AllCloseNan for equal_nan=true).

func AllCloseNan

func AllCloseNan[T numgo.Number](t testing.TB, got, want *numgo.Array[T], rtol, atol float64, equalNaN bool)

AllCloseNan is AllClose with explicit NaN handling: when equalNaN is true, NaN == NaN at the same position (numpy allclose equal_nan=True).

func ArrayAlmostEqual

func ArrayAlmostEqual[T numgo.Number](t testing.TB, got, want *numgo.Array[T], decimal int)

ArrayAlmostEqual asserts every |got-want| < 0.5·10^-decimal (numpy assert_array_almost_equal semantics). NaN anywhere mismatches (unlike ArrayEqual; pass NaN positions only via ArrayEqual or AllCloseNan).

func ArrayEqual

func ArrayEqual[T numgo.Number](t testing.TB, got, want *numgo.Array[T])

ArrayEqual asserts got and want have the same shape and equal elements elementwise, with NaN == NaN (numpy assert_array_equal / equal_nan=True). Failure reports shape, mismatch count, max abs/rel differences and the first mismatching values.

func ArrayLess

func ArrayLess[T numgo.Number](t testing.TB, got, want *numgo.Array[T])

ArrayLess asserts got < want strictly at every position; NaN mismatches (numpy assert_array_less). Complex element types are not ordered and panic.

func ArrayLessEqual

func ArrayLessEqual[T numgo.Number](t testing.TB, got, want *numgo.Array[T])

ArrayLessEqual asserts got <= want at every position (no direct numpy analog; assert_array_less with strict=False). NaN mismatches.

func ArrayNotEqual

func ArrayNotEqual[T numgo.Number](t testing.TB, got, want *numgo.Array[T])

ArrayNotEqual asserts the arrays differ (numpy assert_array_not_equal): pass when shapes differ or any element differs (NaN != NaN except under ArrayEqual's special case, i.e. NaN vs NaN counts as equal here).

func Equal

func Equal(t testing.TB, a, b any)

Equal asserts deep equality of scalars or slices via reflect.DeepEqual, with the special case NaN == NaN (IEEE says false; numpy's assert_equal also treats NaNs as equal). Different types are never equal.

func NotEqual

func NotEqual(t testing.TB, a, b any)

NotEqual is the negation of Equal (same NaN == NaN semantics).

func Raises

func Raises(t testing.TB, substr string, fn func())

Raises asserts fn panics with a message containing substr (numpy assert_raises analog for this package's panic-based errors).

func Shape

func Shape[T numgo.Number](t testing.TB, a *numgo.Array[T], want ...int)

Shape asserts the array's shape equals want.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL