2020-02-18 02:11:16 +08:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-05-19 00:53:42 +08:00
|
|
|
func TestCartesianProduct(t *testing.T) {
|
2020-02-18 02:11:16 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
input := map[string][]interface{}{
|
2020-02-26 08:58:26 +08:00
|
|
|
"foo": {1, 2, 3, 4},
|
|
|
|
"bar": {"a", "b", "c"},
|
|
|
|
"baz": {false, true},
|
2020-02-18 02:11:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
output := CartesianProduct(input)
|
|
|
|
assert.Len(output, 24)
|
|
|
|
|
|
|
|
for _, v := range output {
|
|
|
|
assert.Len(v, 3)
|
|
|
|
|
|
|
|
assert.Contains(v, "foo")
|
|
|
|
assert.Contains(v, "bar")
|
|
|
|
assert.Contains(v, "baz")
|
|
|
|
}
|
|
|
|
|
2021-02-18 03:47:59 +08:00
|
|
|
input = map[string][]interface{}{
|
2021-01-24 06:55:54 +08:00
|
|
|
"foo": {1, 2, 3, 4},
|
|
|
|
"bar": {},
|
|
|
|
"baz": {false, true},
|
2021-02-18 03:47:59 +08:00
|
|
|
}
|
|
|
|
output = CartesianProduct(input)
|
|
|
|
assert.Len(output, 0)
|
2021-01-24 06:55:54 +08:00
|
|
|
|
2021-02-18 03:47:59 +08:00
|
|
|
input = map[string][]interface{}{}
|
|
|
|
output = CartesianProduct(input)
|
|
|
|
assert.Len(output, 0)
|
2020-02-18 02:11:16 +08:00
|
|
|
}
|