blob: 9834483568835797f5fbaddef5ab2d1379514b42 [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
2// SPDX-License-Identifier: Apache-2.0
3
Serge Bazanskide097942023-06-27 13:55:10 +02004package cartesian
5
6import (
7 "fmt"
8 "testing"
9
10 "github.com/google/go-cmp/cmp"
11)
12
13func TestProduct(t *testing.T) {
14 for i, te := range []struct {
15 data [][]string
16 want [][]string
17 }{
18 {
19 data: [][]string{
20 {"a", "b"},
21 {"c", "d"},
22 },
23 want: [][]string{
24 {"a", "c"},
25 {"a", "d"},
26 {"b", "c"},
27 {"b", "d"},
28 },
29 },
30 {
31 data: [][]string{
32 {"a", "b"},
33 },
34 want: [][]string{
35 {"a"},
36 {"b"},
37 },
38 },
39 {
40 data: [][]string{},
41 want: nil,
42 },
43 } {
44 t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
45 got := Product(te.data...)
46 if diff := cmp.Diff(te.want, got); diff != "" {
47 t.Fatalf("Diff:\n%s", diff)
48 }
49 })
50 }
51}