combinator

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2020 License: MIT Imports: 1 Imported by: 0

README

combinator

Latest Release GoDoc Build Status Coverage Status Go ReportCard

combinator generates a slice of all possible value combinations for any given struct and a set of its potential member values. This can be used to generate extensive test matrixes among other things.

Installation

go get github.com/muesli/combinator

Example

type User struct {
	Name  string
	Age   uint
	Admin bool
}

type UserTests struct {
	Name  []string
	Age   []uint
	Admin []bool
}

// define potential values
testData := UserTests{
	Name:  []string{"Alice", "Bob"},
	Age:   []uint{23, 42, 99},
	Admin: []bool{false, true},
}

c := combinator.Generate(User{}, testData)
for i, v := range c {
	u := v.(User)
	fmt.Printf("Combination %2d - Name: %-6s Age: %2d, Admin: %v\n", i, u.Name, u.Age, u.Admin)
}
Combination  0 - Name: Alice  Age: 23, Admin: false
Combination  1 - Name: Bob    Age: 23, Admin: false
Combination  2 - Name: Alice  Age: 42, Admin: false
Combination  3 - Name: Bob    Age: 42, Admin: false
Combination  4 - Name: Alice  Age: 99, Admin: false
Combination  5 - Name: Bob    Age: 99, Admin: false
Combination  6 - Name: Alice  Age: 23, Admin: true
Combination  7 - Name: Bob    Age: 23, Admin: true
Combination  8 - Name: Alice  Age: 42, Admin: true
Combination  9 - Name: Bob    Age: 42, Admin: true
Combination 10 - Name: Alice  Age: 99, Admin: true
Combination 11 - Name: Bob    Age: 99, Admin: true

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(v interface{}, ov interface{}) []interface{}

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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