table-ify TestElementsMatch

pull/963/merge
Ivo van der Wijk 2020-05-27 19:52:46 +02:00 committed by Boyan Soubachov
parent 52b38ca424
commit 4bbffeac6c
1 changed files with 28 additions and 43 deletions

View File

@ -631,6 +631,7 @@ func TestSubsetNotSubset(t *testing.T) {
message string message string
} }
// MTestCase adds a custom message to the case
cases := []MTestCase{ cases := []MTestCase{
// cases that are expected to contain // cases that are expected to contain
{TestCase{[]int{1, 2, 3}, nil, true}, "given subset is nil"}, {TestCase{[]int{1, 2, 3}, nil, true}, "given subset is nil"},
@ -738,51 +739,35 @@ func Test_includeElement(t *testing.T) {
func TestElementsMatch(t *testing.T) { func TestElementsMatch(t *testing.T) {
mockT := new(testing.T) mockT := new(testing.T)
if !ElementsMatch(mockT, nil, nil) { cases := []TestCase{
t.Error("ElementsMatch should return true") // matching
} {nil, nil, true},
if !ElementsMatch(mockT, []int{}, []int{}) {
t.Error("ElementsMatch should return true") {nil, nil, true},
} {[]int{}, []int{}, true},
if !ElementsMatch(mockT, []int{1}, []int{1}) { {[]int{1}, []int{1}, true},
t.Error("ElementsMatch should return true") {[]int{1, 1}, []int{1, 1}, true},
} {[]int{1, 2}, []int{1, 2}, true},
if !ElementsMatch(mockT, []int{1, 1}, []int{1, 1}) { {[]int{1, 2}, []int{2, 1}, true},
t.Error("ElementsMatch should return true") {[2]int{1, 2}, [2]int{2, 1}, true},
} {[]string{"hello", "world"}, []string{"world", "hello"}, true},
if !ElementsMatch(mockT, []int{1, 2}, []int{1, 2}) { {[]string{"hello", "hello"}, []string{"hello", "hello"}, true},
t.Error("ElementsMatch should return true") {[]string{"hello", "hello", "world"}, []string{"hello", "world", "hello"}, true},
} {[3]string{"hello", "hello", "world"}, [3]string{"hello", "world", "hello"}, true},
if !ElementsMatch(mockT, []int{1, 2}, []int{2, 1}) { {[]int{}, nil, true},
t.Error("ElementsMatch should return true")
} // not matching
if !ElementsMatch(mockT, [2]int{1, 2}, [2]int{2, 1}) { {[]int{1}, []int{1, 1}, false},
t.Error("ElementsMatch should return true") {[]int{1, 2}, []int{2, 2}, false},
} {[]string{"hello", "hello"}, []string{"hello"}, false},
if !ElementsMatch(mockT, []string{"hello", "world"}, []string{"world", "hello"}) {
t.Error("ElementsMatch should return true")
}
if !ElementsMatch(mockT, []string{"hello", "hello"}, []string{"hello", "hello"}) {
t.Error("ElementsMatch should return true")
}
if !ElementsMatch(mockT, []string{"hello", "hello", "world"}, []string{"hello", "world", "hello"}) {
t.Error("ElementsMatch should return true")
}
if !ElementsMatch(mockT, [3]string{"hello", "hello", "world"}, [3]string{"hello", "world", "hello"}) {
t.Error("ElementsMatch should return true")
}
if !ElementsMatch(mockT, []int{}, nil) {
t.Error("ElementsMatch should return true")
} }
if ElementsMatch(mockT, []int{1}, []int{1, 1}) { for _, c := range cases {
t.Error("ElementsMatch should return false") res := ElementsMatch(mockT, c.actual, c.expected)
}
if ElementsMatch(mockT, []int{1, 2}, []int{2, 2}) { if res != c.result {
t.Error("ElementsMatch should return false") t.Errorf("ElementsMatch(%#v, %#v) should return %v", c.actual, c.expected, c.result)
} }
if ElementsMatch(mockT, []string{"hello", "hello"}, []string{"hello"}) {
t.Error("ElementsMatch should return false")
} }
} }