https://github.com/muesli/combinator
Generates a slice of all possible value combinations for any given struct and a set of its potential member values
https://github.com/muesli/combinator
hacktoberfest
Last synced: about 1 month ago
JSON representation
Generates a slice of all possible value combinations for any given struct and a set of its potential member values
- Host: GitHub
- URL: https://github.com/muesli/combinator
- Owner: muesli
- License: mit
- Created: 2020-05-01T04:25:10.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-19T04:47:15.000Z (about 4 years ago)
- Last Synced: 2025-02-25T07:41:31.407Z (3 months ago)
- Topics: hacktoberfest
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 49
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# combinator
[](https://github.com/muesli/combinator/releases)
[](https://godoc.org/github.com/muesli/combinator)
[](https://github.com/muesli/combinator/actions)
[](https://coveralls.io/github/muesli/combinator?branch=master)
[](https://goreportcard.com/report/muesli/combinator)`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
```bash
go get github.com/muesli/combinator
```## Example
```go
type User struct {
Name string
Age uint
Admin bool
}/*
Define potential test values. Make sure the struct's fields share the name and
type of the structs you want to generate.
*/
testData := struct {
Name []string
Age []uint
Admin []bool
}{
Name: []string{"Alice", "Bob"},
Age: []uint{23, 42, 99},
Admin: []bool{false, true},
}// Generate all possible combinations
var users []User
combinator.Generate(&users, testData)for i, u := range users {
fmt.Printf("Combination %2d | Name: %-5s | Age: %d | 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](https://github.com/muesli/combinator/raw/master/LICENSE)