package route import ( "testing" "github.com/stretchr/testify/assert" ) func TestPathsDiff(t *testing.T) { tests := []struct { name string any []*Path a []int b []int expected []*Path }{ { name: "Equal", any: []*Path{ { Type: 10, }, { Type: 20, }, }, a: []int{ 0, 1, }, b: []int{ 0, 1, }, expected: []*Path{}, }, { name: "Left empty", any: []*Path{ { Type: 10, }, { Type: 20, }, }, a: []int{}, b: []int{ 0, 1, }, expected: []*Path{}, }, { name: "Right empty", any: []*Path{ { Type: 10, }, { Type: 20, }, }, a: []int{0, 1}, b: []int{}, expected: []*Path{ { Type: 10, }, { Type: 20, }, }, }, { name: "Disjunct", any: []*Path{ { Type: 10, }, { Type: 20, }, { Type: 30, }, { Type: 40, }, }, a: []int{0, 1}, b: []int{2, 3}, expected: []*Path{{ Type: 10, }, { Type: 20, }}, }, } for _, test := range tests { listA := make([]*Path, 0) for _, i := range test.a { listA = append(listA, test.any[i]) } listB := make([]*Path, 0) for _, i := range test.b { listB = append(listB, test.any[i]) } res := PathsDiff(listA, listB) assert.Equal(t, test.expected, res) } } func TestPathsContains(t *testing.T) { tests := []struct { name string needle int haystack []*Path expected bool }{ { name: "Existent", needle: 0, haystack: []*Path{ { Type: 100, }, { Type: 200, }, }, expected: true, }, { name: "Non existent", needle: -1, haystack: []*Path{ { Type: 100, }, { Type: 200, }, }, expected: false, }, } for _, test := range tests { var needle *Path if test.needle >= 0 { needle = test.haystack[test.needle] } else { needle = &Path{} } res := pathsContains(needle, test.haystack) if res != test.expected { t.Errorf("Unexpected result for test %q: %v", test.name, res) } } }