testutils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertContains

func AssertContains(t *testing.T, s, substr, msg string)

AssertContains checks if a string contains a substring.

func AssertEqual

func AssertEqual[T comparable](t *testing.T, expected, actual T, msg string)

AssertEqual checks if two values are equal.

func AssertError

func AssertError(t *testing.T, err error, msg string)

AssertError checks if an error is not nil.

func AssertFalse

func AssertFalse(t *testing.T, condition bool, msg string)

AssertFalse checks if a boolean is false.

func AssertFloat32SliceApproxEqual

func AssertFloat32SliceApproxEqual(t *testing.T, expected, actual []float32, tolerance float32, msg string)

AssertFloat32SliceApproxEqual checks if two float32 slices are approximately equal element-wise.

func AssertFloat64SliceApproxEqual

func AssertFloat64SliceApproxEqual(t *testing.T, expected, actual []float64, tolerance float64, msg string)

AssertFloat64SliceApproxEqual checks if two float64 slices are approximately equal element-wise.

func AssertFloatEqual

func AssertFloatEqual[T float32 | float64](t *testing.T, expected, actual, tolerance T, msg string)

AssertFloatEqual checks if two float values are approximately equal.

func AssertNil

func AssertNil(t *testing.T, value interface{}, msg string)

AssertNil checks if a value is nil.

func AssertNoError

func AssertNoError(t *testing.T, err error, msg string)

AssertNoError checks if an error is nil.

func AssertNotNil

func AssertNotNil(t *testing.T, value interface{}, msg string)

AssertNotNil checks if a value is not nil.

func AssertPanics

func AssertPanics(t *testing.T, f func(), msg string)

AssertPanics checks if a function panics.

func AssertTrue

func AssertTrue(t *testing.T, condition bool, msg string)

AssertTrue checks if a boolean is true.

func CompareTensorsApprox

func CompareTensorsApprox[T tensor.Addable](t *testing.T, actual, expected *tensor.TensorNumeric[T], epsilon T) bool

CompareTensorsApprox checks if two tensors are approximately equal element-wise.

func ElementsMatch

func ElementsMatch(a, b []string) bool

ElementsMatch checks if two string slices contain the same elements, regardless of order.

func Int64SliceEqual

func Int64SliceEqual(a, b []int64) bool

Int64SliceEqual checks if two int64 slices are equal.

func IntSliceEqual

func IntSliceEqual(a, b []int) bool

IntSliceEqual checks if two int slices are equal.

func RunTests

func RunTests(t *testing.T, tests []TestCase)

RunTests executes a slice of test cases.

Types

type FailingInitializer

type FailingInitializer[T tensor.Numeric] struct{}

FailingInitializer is a test initializer that always returns an error.

func (*FailingInitializer[T]) Initialize

func (f *FailingInitializer[T]) Initialize(_, _ int) ([]T, error)

Initialize always returns an error for testing error paths.

type MockEngine

type MockEngine[T tensor.Numeric] struct {
	compute.Engine[T]
	Err error
}

MockEngine is a mock implementation of the compute.Engine interface.

func NewMockEngine

func NewMockEngine[T tensor.Numeric]() *MockEngine[T]

NewMockEngine creates a new mock engine for testing.

func NewMockEngineWithError

func NewMockEngineWithError[T tensor.Numeric](err error) *MockEngine[T]

NewMockEngineWithError creates a new mock engine that returns the specified error.

func (*MockEngine[T]) Add

func (e *MockEngine[T]) Add(_ context.Context, _, _ *tensor.TensorNumeric[T], _ ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Add performs element-wise addition of two tensors.

func (*MockEngine[T]) Allocator

func (e *MockEngine[T]) Allocator() device.Allocator

Allocator returns the memory allocator for the engine.

func (*MockEngine[T]) Close

func (e *MockEngine[T]) Close() error

Close closes the engine and releases resources.

func (*MockEngine[T]) Context

func (e *MockEngine[T]) Context() context.Context

Context returns the context associated with the engine.

func (*MockEngine[T]) Copy

func (e *MockEngine[T]) Copy(_ context.Context, _, _ *tensor.TensorNumeric[T]) error

Copy copies data from source tensor to destination tensor.

func (*MockEngine[T]) Device

func (e *MockEngine[T]) Device() device.Device

Device returns the device associated with the engine.

func (*MockEngine[T]) Div

func (e *MockEngine[T]) Div(_ context.Context, _, _ *tensor.TensorNumeric[T], _ ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Div performs element-wise division of two tensors.

func (*MockEngine[T]) Exp

Exp computes the exponential of tensor elements.

func (*MockEngine[T]) Log

Log computes the natural logarithm of tensor elements.

func (*MockEngine[T]) MatMul

func (e *MockEngine[T]) MatMul(_ context.Context, _, _ *tensor.TensorNumeric[T], _ ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

MatMul performs matrix multiplication of two tensors.

func (*MockEngine[T]) Mul

func (e *MockEngine[T]) Mul(_ context.Context, _, _ *tensor.TensorNumeric[T], _ ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Mul performs element-wise multiplication of two tensors.

func (*MockEngine[T]) Name

func (e *MockEngine[T]) Name() string

Name returns the name of the engine.

func (*MockEngine[T]) Pow

func (e *MockEngine[T]) Pow(_ context.Context, _, _ *tensor.TensorNumeric[T], _ ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Pow computes the power of base tensor raised to exponent tensor.

func (*MockEngine[T]) String

func (e *MockEngine[T]) String() string

func (*MockEngine[T]) Sub

func (e *MockEngine[T]) Sub(_ context.Context, _, _ *tensor.TensorNumeric[T], _ ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Sub performs element-wise subtraction of two tensors.

func (*MockEngine[T]) Sum

func (e *MockEngine[T]) Sum(_ context.Context, _ *tensor.TensorNumeric[T], _ int, _ bool, _ ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Sum computes the sum of tensor elements along the specified axis.

func (*MockEngine[T]) Transpose

func (e *MockEngine[T]) Transpose(_ context.Context, _ *tensor.TensorNumeric[T], _ []int, _ ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Transpose transposes a tensor along the specified axes.

func (*MockEngine[T]) UnaryOp

func (e *MockEngine[T]) UnaryOp(_ context.Context, _ *tensor.TensorNumeric[T], _ func(T) T, _ ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

UnaryOp performs a unary operation on a tensor.

func (*MockEngine[T]) Wait

func (e *MockEngine[T]) Wait() error

Wait waits for all pending operations to complete.

func (*MockEngine[T]) WithAllocator

func (e *MockEngine[T]) WithAllocator(_ device.Allocator) compute.Engine[T]

WithAllocator returns a new engine with the specified allocator.

func (*MockEngine[T]) WithContext

func (e *MockEngine[T]) WithContext(_ context.Context) compute.Engine[T]

WithContext returns a new engine with the specified context.

func (*MockEngine[T]) WithDevice

func (e *MockEngine[T]) WithDevice(_ device.Device) compute.Engine[T]

WithDevice returns a new engine with the specified device.

func (*MockEngine[T]) WithError

func (e *MockEngine[T]) WithError(err error) *MockEngine[T]

WithError returns a mock engine that will return the specified error.

func (*MockEngine[T]) WithName

func (e *MockEngine[T]) WithName(_ string) compute.Engine[T]

WithName returns a new engine with the specified name.

func (*MockEngine[T]) Zero

func (e *MockEngine[T]) Zero(_ context.Context, _ *tensor.TensorNumeric[T]) error

Zero sets all elements of the tensor to zero.

type TestCase

type TestCase struct {
	Name string
	Func func(t *testing.T)
}

TestCase represents a single test case with a name and a function to execute.

type TestInitializer

type TestInitializer[T tensor.Numeric] struct {
	Value T
}

TestInitializer is a test initializer that sets all values to a specific value.

func (*TestInitializer[T]) Initialize

func (t *TestInitializer[T]) Initialize(inputSize, outputSize int) ([]T, error)

Initialize sets all values to the specified value.

Jump to

Keyboard shortcuts

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