Debian Codegraph @

README.md

raw symbols SCIP
1 # combinator
2
3 [![Latest Release](https://img.shields.io/github/release/muesli/combinator.svg)](https://github.com/muesli/combinator/releases)
4 [![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://godoc.org/github.com/muesli/combinator)
5 [![Build Status](https://github.com/muesli/combinator/workflows/build/badge.svg)](https://github.com/muesli/combinator/actions)
6 [![Coverage Status](https://coveralls.io/repos/github/muesli/combinator/badge.svg?branch=master)](https://coveralls.io/github/muesli/combinator?branch=master)
7 [![Go ReportCard](http://goreportcard.com/badge/muesli/combinator)](http://goreportcard.com/report/muesli/combinator)
8
9 `combinator` generates a slice of all possible value combinations for any given
10 struct and a set of its potential member values. This can be used to generate
11 extensive test matrixes among other things.
12
13 ## Installation
14
15 ```bash
16 go get github.com/muesli/combinator
17 ```
18
19 ## Example
20
21 ```go
22 type User struct {
23 Name string
24 Age uint
25 Admin bool
26 }
27
28 /*
29 Define potential test values. Make sure the struct's fields share the name and
30 type of the structs you want to generate.
31 */
32 testData := struct {
33 Name []string
34 Age []uint
35 Admin []bool
36 }{
37 Name: []string{"Alice", "Bob"},
38 Age: []uint{23, 42, 99},
39 Admin: []bool{false, true},
40 }
41
42 // Generate all possible combinations
43 var users []User
44 combinator.Generate(&users, testData)
45
46 for i, u := range users {
47 fmt.Printf("Combination %2d | Name: %-5s | Age: %d | Admin: %v\n", i, u.Name, u.Age, u.Admin)
48 }
49 ```
50
51 ```
52 Combination 0 | Name: Alice | Age: 23 | Admin: false
53 Combination 1 | Name: Bob | Age: 23 | Admin: false
54 Combination 2 | Name: Alice | Age: 42 | Admin: false
55 Combination 3 | Name: Bob | Age: 42 | Admin: false
56 Combination 4 | Name: Alice | Age: 99 | Admin: false
57 Combination 5 | Name: Bob | Age: 99 | Admin: false
58 Combination 6 | Name: Alice | Age: 23 | Admin: true
59 Combination 7 | Name: Bob | Age: 23 | Admin: true
60 Combination 8 | Name: Alice | Age: 42 | Admin: true
61 Combination 9 | Name: Bob | Age: 42 | Admin: true
62 Combination 10 | Name: Alice | Age: 99 | Admin: true
63 Combination 11 | Name: Bob | Age: 99 | Admin: true
64 ```
65
66 ## License
67
68 [MIT](https://github.com/muesli/combinator/raw/master/LICENSE)