| Tim Windelschmidt | 6d33a43 | 2025-02-04 14:34:25 +0100 | [diff] [blame^] | 1 | // Copyright The Monogon Project Authors. |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| Serge Bazanski | de09794 | 2023-06-27 13:55:10 +0200 | [diff] [blame] | 4 | package cartesian |
| 5 | |
| 6 | import ( |
| 7 | "fmt" |
| 8 | "testing" |
| 9 | |
| 10 | "github.com/google/go-cmp/cmp" |
| 11 | ) |
| 12 | |
| 13 | func 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 | } |