github.com/candidpartners/terraform@v0.9.5-0.20171005231213-29f5f88820f6/dag/set_test.go (about) 1 package dag 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 func TestSetDifference(t *testing.T) { 9 cases := []struct { 10 Name string 11 A, B []interface{} 12 Expected []interface{} 13 }{ 14 { 15 "same", 16 []interface{}{1, 2, 3}, 17 []interface{}{3, 1, 2}, 18 []interface{}{}, 19 }, 20 21 { 22 "A has extra elements", 23 []interface{}{1, 2, 3}, 24 []interface{}{3, 2}, 25 []interface{}{1}, 26 }, 27 28 { 29 "B has extra elements", 30 []interface{}{1, 2, 3}, 31 []interface{}{3, 2, 1, 4}, 32 []interface{}{}, 33 }, 34 } 35 36 for i, tc := range cases { 37 t.Run(fmt.Sprintf("%d-%s", i, tc.Name), func(t *testing.T) { 38 var one, two, expected Set 39 for _, v := range tc.A { 40 one.Add(v) 41 } 42 for _, v := range tc.B { 43 two.Add(v) 44 } 45 for _, v := range tc.Expected { 46 expected.Add(v) 47 } 48 49 actual := one.Difference(&two) 50 match := actual.Intersection(&expected) 51 if match.Len() != expected.Len() { 52 t.Fatalf("bad: %#v", actual.List()) 53 } 54 }) 55 } 56 }