MCPcopy Create free account
hub / github.com/stretchr/testify / ElementsMatch

Function ElementsMatch

assert/assertions.go:1087–1106  ·  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

1085//
1086// assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2])
1087func ElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interface{}) (ok bool) {
1088 if h, ok := t.(tHelper); ok {
1089 h.Helper()
1090 }
1091 if isEmpty(listA) && isEmpty(listB) {
1092 return true
1093 }
1094
1095 if !isList(t, listA, msgAndArgs...) || !isList(t, listB, msgAndArgs...) {
1096 return false
1097 }
1098
1099 extraA, extraB := diffLists(listA, listB)
1100
1101 if len(extraA) == 0 && len(extraB) == 0 {
1102 return true
1103 }
1104
1105 return Fail(t, formatListDiff(listA, listB, extraA, extraB), msgAndArgs...)
1106}
1107
1108// isList checks that the provided value is array or slice.
1109func 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