Add `AssertSameElements` / `AssertElementsMatch` (irrelevant order)
MarvinJWendt opened this issue · 4 comments
MarvinJWendt commented
Add `AssertSameElements` / `AssertElementsMatch` (irrelevant order)
github-actions commented
janisz commented
Did I understand this correctly?
// AssertSameElements asserts that two slices contains same elements (including pointers).
// The order is irrelevant.
//
// Example:
// testza.AssertSameElements(t, []string{"Hello", "World"}, []string{"Hello", "World"})
// testza.AssertSameElements(t, []int{1,2}, []int{1,2, 3}) // FAILS: 3 appears only in one slice
// testza.AssertSameElements(t, []int{1,2}, []int{2,1})
// testza.AssertSameElements(t, []int{1,2}, []int{2,1})
//
// type A struct {
// a string
// }
// testza.AssertSameElements(t, []*A{{a: "A"}, {a: "B"}, {a: "C"}}, []*A{{a: "A"}, {a: "B"}, {a: "C"}}) // FAILS: Pointers are different
func AssertSameElements(t testRunner, expected interface{}, actual interface{}, msg ...interface{}) {
}
// AssertElementsMatch asserts that two slices contains same values.
// The order is irrelevant.
//
// Example:
// testza.AssertElementsMatch(t, []string{"Hello", "World"}, []string{"Hello", "World"})
// testza.AssertElementsMatch(t, []int{1,2}, []int{1,2, 3}) // FAILS: 3 appears only in one slice
// testza.AssertElementsMatch(t, []int{1,2}, []int{2,1})
//
// type A struct {
// a string
// }
// testza.AssertSameElements(t, []*A{{a: "A"}, {a: "B"}, {a: "C"}}, []*A{{a: "B"}, {a: "C"}, {a: "A"}})
func AssertElementsMatch(t testRunner, expected interface{}, actual interface{}, msg ...interface{}) {
}
MarvinJWendt commented
Hi @janisz, sorry for the miscommunication. I was not sure about the naming, it should be one method.
Other libraries, as testify, named their method ElementsMatch
, but I don't really like the name and think that SameElements
describes the functionality better. We could have the same name for a better developer experience, or create a similar function with a different name. What do you think would be the better choice?
MarvinJWendt commented
Published in v0.2.13! 🚀