geomtest

package
v0.0.0-...-9c88ebf Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package geomtest provides helpers for testing the geom packages.

Index

Constants

View Source
const (
	// Small is the value that will be passed into AssertEqualizer
	Small cmpr.Tolerance = 1e-10
)

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(expected, actual interface{}, delta cmpr.Tolerance) error

AssertEqual can compare anything that implements geomtest.AssertEqualizer. There is also logic to handle comparing float64 values Any two slices whose elements can be compared with Equal can be compared. The provided delta value will be passed to anything that implements AssertEqualizer. If the equality check fails, an error is returned.

func Equal

func Equal(t assert.TestingT, expected, actual interface{}, msg ...interface{}) bool

Equal calls AssertEqual with the default value of Small. If there is an error it is passed into t.Error. The return bool will be true if the values were equal.

func EqualInDelta

func EqualInDelta(t assert.TestingT, expected, actual interface{}, delta cmpr.Tolerance, msg ...interface{}) bool

EqualInDelta calls AssertEqual. If there is an error it is passed into t.Error. The return bool will be true if the values were equal.

func Message

func Message(msg ...interface{}) string

Message takes in args to form a message. If there are more than 1 arg and the first is a string, it will use that as a format string.

Types

type AssertEqualizer

type AssertEqualizer interface {
	AssertEqual(to interface{}, t cmpr.Tolerance) error
}

AssertEqualizer allows a type to define an equality test.

Note that when fulfilling an interface Go will coerce a pointer type to it's base type, but not the other way. So if AssertEqual is on the base type is on the base type and a pointer to that type is passed into geomtest.Equal it will be cast to the base type.

type GeomAssert

type GeomAssert struct {
	*assert.Assertions
	assert.TestingT
}

GeomAssert wraps an instance of assert.Assertions but will replace calls to Equal with geomtest when the type is float64 or fulfills AssertEqual. This allows calls to be made without passing in testing.T each time.

func New

func New(t assert.TestingT) *GeomAssert

New creates an instance of GeomAssert.

func (*GeomAssert) Equal

func (g *GeomAssert) Equal(expected, actual interface{}, msg ...interface{}) bool

Equal will call geomtest.EqualInDelta if expected is a float64 or if it fulfills AssertEqualizer.

Jump to

Keyboard shortcuts

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