ElementsMatch asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match. assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2])
(t TestingT, listA, listB interface{}, msgAndArgs ...interface{})
| 1137 | // |
| 1138 | // assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2]) |
| 1139 | func ElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interface{}) (ok bool) { |
| 1140 | if h, ok := t.(tHelper); ok { |
| 1141 | h.Helper() |
| 1142 | } |
| 1143 | if isEmpty(listA) && isEmpty(listB) { |
| 1144 | return true |
| 1145 | } |
| 1146 | |
| 1147 | if !isList(t, listA, msgAndArgs...) || !isList(t, listB, msgAndArgs...) { |
| 1148 | return false |
| 1149 | } |
| 1150 | |
| 1151 | extraA, extraB := diffLists(listA, listB) |
| 1152 | |
| 1153 | if len(extraA) == 0 && len(extraB) == 0 { |
| 1154 | return true |
| 1155 | } |
| 1156 | |
| 1157 | return Fail(t, formatListDiff(listA, listB, extraA, extraB), msgAndArgs...) |
| 1158 | } |
| 1159 | |
| 1160 | // isList checks that the provided value is array or slice. |
| 1161 | func isList(t TestingT, list interface{}, msgAndArgs ...interface{}) (ok bool) { |