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 ¶
- func AllClose[T numgo.Number](t testing.TB, got, want *numgo.Array[T], rtol, atol float64)
- func AllCloseNan[T numgo.Number](t testing.TB, got, want *numgo.Array[T], rtol, atol float64, equalNaN bool)
- func ArrayAlmostEqual[T numgo.Number](t testing.TB, got, want *numgo.Array[T], decimal int)
- func ArrayEqual[T numgo.Number](t testing.TB, got, want *numgo.Array[T])
- func ArrayLess[T numgo.Number](t testing.TB, got, want *numgo.Array[T])
- func ArrayLessEqual[T numgo.Number](t testing.TB, got, want *numgo.Array[T])
- func ArrayNotEqual[T numgo.Number](t testing.TB, got, want *numgo.Array[T])
- func Equal(t testing.TB, a, b any)
- func NotEqual(t testing.TB, a, b any)
- func Raises(t testing.TB, substr string, fn func())
- func Shape[T numgo.Number](t testing.TB, a *numgo.Array[T], want ...int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllClose ¶
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 ¶
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 ¶
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 ¶
ArrayLess asserts got < want strictly at every position; NaN mismatches (numpy assert_array_less). Complex element types are not ordered and panic.
func ArrayLessEqual ¶
ArrayLessEqual asserts got <= want at every position (no direct numpy analog; assert_array_less with strict=False). NaN mismatches.
func ArrayNotEqual ¶
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 ¶
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.
Types ¶
This section is empty.