2020-02-17 10:11:16 -08:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-05-18 12:53:42 -04:00
|
|
|
func TestCartesianProduct(t *testing.T) {
|
2020-02-17 10:11:16 -08:00
|
|
|
assert := assert.New(t)
|
|
|
|
input := map[string][]interface{}{
|
2020-02-25 16:58:26 -08:00
|
|
|
"foo": {1, 2, 3, 4},
|
|
|
|
"bar": {"a", "b", "c"},
|
|
|
|
"baz": {false, true},
|
2020-02-17 10: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 04:47:59 +09:00
|
|
|
input = map[string][]interface{}{
|
2021-01-23 17:55:54 -05:00
|
|
|
"foo": {1, 2, 3, 4},
|
|
|
|
"bar": {},
|
|
|
|
"baz": {false, true},
|
2021-02-18 04:47:59 +09:00
|
|
|
}
|
|
|
|
output = CartesianProduct(input)
|
|
|
|
assert.Len(output, 0)
|
2021-01-23 17:55:54 -05:00
|
|
|
|
2021-02-18 04:47:59 +09:00
|
|
|
input = map[string][]interface{}{}
|
|
|
|
output = CartesianProduct(input)
|
|
|
|
assert.Len(output, 0)
|
2020-02-17 10:11:16 -08:00
|
|
|
}
|