testes

package module
v0.1.0-1647270585084054 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: MIT Imports: 12 Imported by: 2

README

testes

Tricky and fun utilities for Go programs.


GitHub Workflow Status Codecov

Contributor Covenant

Twitter Follow GitHub followers


Getting Started

Prerequisites

Developed with $( go version; ). Go is extremely backwards compatible and semver stable. Nearly any v1.x should work fine.


Installation

To use this repo as a template for your own project:

gh repo create -y --public --template "https://github.com/skeptycal/testes"

Clone this repo to test and contribute:

# add repo to $GOPATH (xxxxxx is your computer login username)
go get github.com/xxxxxx/testes

cd ${GOPATH}/src/github.com/xxxxxx/testes

# test results and coverage info
./go.test.sh

# install as a utility package
go install

Use the Issues and PR templates on the GitHub repo page to contribute.


Basic Usage

This is a copy of the example script available in the cmd/example/testes folder:

package main

import "github.com/skeptycal/testes"

func main() {
    testes.Example()
}

To try it out:

# change to the sample folder
cd cmd/example/testes

# run the main.go program
go run ./main.go

# to compile as an executable
go build

Code of Conduct and Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us. Please read the Code of Conduct for details before submitting anything.


Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.


Contributors and Inspiration

  • Michael Treanor (GitHub / Twitter) - Initial work, updates, maintainer
  • Francesc Campoy - Inspiration and great YouTube videos!

See also the list of contributors who participated in this project.


License

Licensed under the MIT https://opensource.org/licenses/MIT - see the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	UPPER    = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	LOWER    = "abcdefghijklmnopqrstuvwxyz"
	DIGITS   = "0123456789"
	ALPHA    = LOWER + UPPER
	ALPHANUM = ALPHA + DIGITS
)
View Source
const ReplacementChar rune = '\uFFFD'

ReplacementChar is the recognized unicode replacement character for malformed unicode or errors in encoding.

It is also found in unicode.ReplacementChar

Variables

View Source
var (
	ValueOf = types.ValueOf
	Log     = types.Log
)
View Source
var (
	LimitResult            bool
	DefaultTestResultLimit = 15
)
View Source
var Log = types.Log
View Source
var NewAnyValue = types.NewAnyValue

NoValue is the zero value of reflect.Value, which is an invalid result. It specifically means that the test result has not yet been determined.

View Source
var TBloop = func(fn Any, in []TBvalues) ([]TBvalues, error) {
	defer func() {
		if r := recover(); r != nil {
			log.Errorf("TestBench: recovered from panic: %v (%v)", r, fn)
		}
	}()

	a := make([]TBvalues, 0, len(in))

	for i := 0; i < len(in); i++ {
		a = append(a, v.Call(in[i]))
	}
	return a, nil
}

TBloop returns the output output values from a call to the function fn using argList as a series of inputs. ArgList is a slice of inputs; fn is called once for each argument in argList and is results are returned in a similar slice of return values.

Functions

func AssertDeepEqual

func AssertDeepEqual(t *testing.T, name string, got, want Any) bool

func AssertEqual

func AssertEqual(t *testing.T, name string, got, want Any) bool

func AssertKindEqual

func AssertKindEqual(t *testing.T, name string, got, want Any) bool

func AssertNotEqual

func AssertNotEqual(t *testing.T, name string, got, want Any) bool

func AssertSameFunc

func AssertSameFunc(t *testing.T, name string, got, want Any, args ...reflect.Value) bool

AssertSameFunc returns true if got and want are both functions that return the same value when called with args... as input.

func AssertSameKind

func AssertSameKind(t *testing.T, name string, got, want Any) bool

func AssertSameType

func AssertSameType(t *testing.T, name string, got, want Any) bool

func Conj

func Conj(c complex128) complex128

func Contains

func Contains(needle Any, haystack []Any) bool

Contains returns true if the underlying iterable sequence (haystack) contains the search term (needle) in at least one position.

func Example

func Example()

func GetEncodedString

func GetEncodedString(n int) string

func GetFuncResult

func GetFuncResult(t *testing.T, name string, fn Any, args ...reflect.Value) ([]reflect.Value, error)

func IsKindEqual

func IsKindEqual(got, want Any) bool

func Less

func Less(i, j int) bool

func Mean

func Mean(list []int) float64

func RandomKind

func RandomKind(useInvalid bool) reflect.Kind

func RandomString

func RandomString(n int) string

func StDev

func StDev(list []int) float64

func TBbN

func TBbN(b *testing.B)

func TError

func TError(t *testing.T, name string, got, want Any)

func TErrorf

func TErrorf(t *testing.T, formatString, name string, got, want Any)

func TName

func TName(testname, funcname, argname Any) string

func TRun

func TRun(t *testing.T, name string, got, want Any)

func TRunTest

func TRunTest(t *testing.T, tt *test)

func TTypeError

func TTypeError(t *testing.T, name string, got, want Any)

func TTypeRun

func TTypeRun(t *testing.T, name string, got, want Any, wantErr bool)

Types

type Any

type Any = types.Any

func RandomData

func RandomData(knd int, useInvalid bool) Any

type AnyValue

type AnyValue = types.AnyValue

type Assert

type Assert interface {
	Tester
	Result() bool
}

Assert implements the Tester interface. It is used for boolean only challenges. In addition to working seamlessly with the standard library testing package, it can return the bool result for use in alternate data collection or CI software. Result() automatically calls Run()

type Custom

type Custom interface {
	Tester
	Hook(name string, got, want Any, wantErr bool)
}

Custom implements Tester and can be used to hook into existing software by passing in the various test arguments with Hook(). Calling Hook() also calls Run() automaticaly.

type DataPoint

type DataPoint interface {
	Start()
	Stop()
	Collect()
}

func GetData

func GetData() DataPoint

type GetSetter

type GetSetter interface {
	Get(key Any) (Any, error)
	Set(key Any, value Any) error
}

type KindMap

type KindMap map[string]int

func (KindMap) Keys

func (m KindMap) Keys() []string

func (KindMap) Max

func (m KindMap) Max() int

func (KindMap) Mean

func (m KindMap) Mean() float64

func (KindMap) Min

func (m KindMap) Min() int

func (KindMap) StDev

func (m KindMap) StDev() float64

func (KindMap) String

func (m KindMap) String() string

func (KindMap) Values

func (m KindMap) Values() []int

type Random

type Random interface {
	Tester
	Regenerate()
}

Random implements Tester and creates a random test that can be used to generate many varied tests automatically. After each use, Regenerate() can be called to generate a new test. Regenerate() automatically calls Run().

type StatMap

type StatMap interface {
	Keys() []string
	Values() []int
	Min() int
	Max() int
	Mean() float64
	StDev() float64

	String() string
}

type TBvalues

type TBvalues = []reflect.Value
var NoValues TBvalues = []reflect.Value{reflect.Value{}}

NoTestResult is a slice containing only one value, the zero value of reflect.Value, which is an invalid result.

func TBmakeArgList

func TBmakeArgList(tests ...Test) []TBvalues

func TBwrapInputValues

func TBwrapInputValues(args ...interface{}) TBvalues

type Test

type Test interface {

	// Name returns the name of the test.
	Name() string

	// Args returns the function input arguments.
	Args() TBvalues

	// Want returns the expected return value.
	Want() TBvalues

	// WantErr returns true if an error is expected
	// from an AssertTrue test (got == want).
	WantErr() bool

	// Got returns the cached function result. If the
	// function has not yet been called, it is called
	// and the value is cached and returned.
	Got() TBvalues

	// Run calls the the function (jit) if it has not
	// been called before and caches the result.
	Run()

	// Call specifically calls the function and returns
	// the result of the call whether the result is cached
	// or not.
	Call(in TBvalues) TBvalues
}

func NewTest

func NewTest(t *testing.T, name string, fn anyFunc, args, want []Any, wantErr bool) (Test, error)

type TestSet

type TestSet interface {
}

type Tester

type Tester interface {
	Run()
}

Tester implements the Run method of an automated test suite. It may be implemented by traditional tests, asserts, random inputs, custom code, or sets of tests.

func NewTest

func NewTest(t *testing.T, name string, in, got, want Any, wantErr bool) Tester

func NewTestSet

func NewTestSet(t *testing.T, name string, list []Tester) Tester

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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