tests

package
v0.0.0-...-40a4379 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package tests implements auxiliary tools for testing package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EquateFloat64

func EquateFloat64(relchg float64) cmp.Option

EquateFloat64 compares two float64 numbers and reports them equal if their relative change is less than or equal to relchg. See: https://en.wikipedia.org/wiki/Relative_change

Example (Fail)
package main

import (
	"fmt"

	"github.com/google/go-cmp/cmp"
	"github.com/skhal/lab/go/tests"
)

func main() {
	diff := cmp.Diff(3.4, 3.1, tests.EquateFloat64(0.01))
	if diff != "" {
		fmt.Print("3.4 !~= 3.1")
		return
	}
	fmt.Print("3.4 ~= 3.1")
}
Output:
3.4 !~= 3.1
Example (Pass)
package main

import (
	"fmt"

	"github.com/google/go-cmp/cmp"
	"github.com/skhal/lab/go/tests"
)

func main() {
	diff := cmp.Diff(3.4, 3.1, tests.EquateFloat64(0.1))
	if diff != "" {
		fmt.Print("3.4 !~= 3.1")
		return
	}
	fmt.Print("3.4 ~= 3.1")
}
Output:
3.4 ~= 3.1

Types

type GoldenFile

type GoldenFile string

GoldenFile holds baseline data for regression tests.

func (GoldenFile) Diff

func (f GoldenFile) Diff(t *testing.T, buf string) string

Diff generates a difference between buf and contents of the golden file. It fails the test if it can't read the file.

func (GoldenFile) Write

func (f GoldenFile) Write(t *testing.T, data string)

Write updates contents of the golden file with data. It fails the test if it fails to write data.

Jump to

Keyboard shortcuts

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