| 1 |
/* |
| 2 |
Copyright 2019 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package generator |
| 18 |
|
| 19 |
import ( |
| 20 |
"reflect" |
| 21 |
"testing" |
| 22 |
) |
| 23 |
|
| 24 |
func TestTransitiveClosure(t *testing.T) { |
| 25 |
cases := []struct { |
| 26 |
name string |
| 27 |
in map[string][]string |
| 28 |
expected map[string][]string |
| 29 |
}{ |
| 30 |
{ |
| 31 |
name: "no transition", |
| 32 |
in: map[string][]string{ |
| 33 |
"a": {"b"}, |
| 34 |
"c": {"d"}, |
| 35 |
}, |
| 36 |
expected: map[string][]string{ |
| 37 |
"a": {"b"}, |
| 38 |
"c": {"d"}, |
| 39 |
}, |
| 40 |
}, |
| 41 |
{ |
| 42 |
name: "simple", |
| 43 |
in: map[string][]string{ |
| 44 |
"a": {"b"}, |
| 45 |
"b": {"c"}, |
| 46 |
"c": {"d"}, |
| 47 |
}, |
| 48 |
expected: map[string][]string{ |
| 49 |
"a": {"b", "c", "d"}, |
| 50 |
"b": {"c", "d"}, |
| 51 |
"c": {"d"}, |
| 52 |
}, |
| 53 |
}, |
| 54 |
} |
| 55 |
|
| 56 |
for _, c := range cases { |
| 57 |
t.Run(c.name, func(t *testing.T) { |
| 58 |
out := transitiveClosure(c.in) |
| 59 |
if !reflect.DeepEqual(c.expected, out) { |
| 60 |
t.Errorf("expected: %#v, got %#v", c.expected, out) |
| 61 |
} |
| 62 |
}) |
| 63 |
} |
| 64 |
} |