MCPcopy
hub / github.com/stretchr/testify / ElementsMatch

Function ElementsMatch

assert/assertions.go:1139–1158  ·  view source on GitHub ↗

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{})

Source from the content-addressed store, hash-verified

1137//
1138// assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2])
1139func 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.
1161func isList(t TestingT, list interface{}, msgAndArgs ...interface{}) (ok bool) {

Callers 4

ElementsMatchFunction · 0.92
ElementsMatchfFunction · 0.70
TestElementsMatchFunction · 0.70
ElementsMatchMethod · 0.70

Calls 6

isEmptyFunction · 0.85
isListFunction · 0.85
diffListsFunction · 0.85
formatListDiffFunction · 0.85
FailFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestElementsMatchFunction · 0.56