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