MarvinJWendt/testza

Add `AssertSubset` and `AssertNotSubset`

MarvinJWendt opened this issue · 5 comments

Add `AssertSubset` and `AssertNotSubset`

Should we use Equal or EqualValues here?

Hi @janisz, AssertSubset should check if a subset is in a slice.

For example:

sub1 := []string{"Hello",  "World", "How", "Are", "You", "?"}
testza.AssertSubset(t, []string{"How", "Are"}, sub1) // -> Pass
testza.AssertSubset(t, []string{"Hello", "How"}, sub1) // -> Pass
testza.AssertSubset(t, []string{"Hello", "ABCDEF"}, sub1) // -> fail

The method should accept every slice/array.
You can get inspired by testifys assert package: https://github.com/stretchr/testify/blob/ab6dc3262822ed562480c19876b0257ace761e3e/assert/assertions.go#L810

Got it. My question was rather what equality should we use there? Should we compare equality or values?

sub1 := []*A{{a: "A"}, {a: "B"}, {a: "C"}}
testza.AssertSubset(t, []*A{{a: "A"}, {a: "B"}}, sub1) 
sub1 := []*A{{a: "A"}, {a: "B"}, {a: "C"}}
testza.AssertSubset(t, []*A{{a: "A"}, {a: "B"}}, sub1) 

Hi @janisz, that should fail the test :)
In general, with the assertions, you can compare the functionality with testify. To make migration easier, and to fragment the ecosystem less, we try to have similar assertion functionality, if possible.