create and use helper for deep equality

This commit is contained in:
2024-01-23 16:30:20 +05:30
parent 9f6e503379
commit 309aa09114
2 changed files with 14 additions and 9 deletions

View File

@@ -1,15 +1,24 @@
package assert
import "testing"
import (
"testing"
"reflect"
)
func Equal[T comparable](t *testing.T, got, want T) {
if (got != want) {
t.Errorf("not equal %v and %v", got, want)
t.Errorf("not equal: %v and %v", got, want)
}
}
func NotEqual[T comparable](t *testing.T, got, want T) {
if (got == want) {
t.Errorf("unexpected equal %v and %v", got, want)
t.Errorf("unexpected equal: %v and %v", got, want)
}
}
func DeepEqual(t *testing.T, got, want interface{}){
if !(reflect.DeepEqual(got,want)) {
t.Errorf("unequal deep structure: wanted %v; but got %v", want, got)
}
}