Added equality checks
This commit is contained in:
47
Equal.go
Normal file
47
Equal.go
Normal file
@ -0,0 +1,47 @@
|
||||
package assert
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Equal asserts that the two parameters are equal.
|
||||
func Equal[T comparable](t testing.TB, a T, b T) {
|
||||
if a == b {
|
||||
return
|
||||
}
|
||||
|
||||
t.Errorf(`Equal:
|
||||
file: %s
|
||||
assert: Equal
|
||||
value: %v
|
||||
expected: %v`, file(t), a, b)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
// NotEqual asserts that the two parameters are not equal.
|
||||
func NotEqual[T comparable](t testing.TB, a T, b T) {
|
||||
if a != b {
|
||||
return
|
||||
}
|
||||
|
||||
t.Errorf(`NotEqual:
|
||||
file: %s
|
||||
assert: NotEqual
|
||||
value: %v`, file(t), a)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
// DeepEqual asserts that the two parameters are deeply equal.
|
||||
func DeepEqual[T comparable](t testing.TB, a T, b T) {
|
||||
if reflect.DeepEqual(a, b) {
|
||||
return
|
||||
}
|
||||
|
||||
t.Errorf(`
|
||||
file: %s
|
||||
assert: DeepEqual
|
||||
value: %v
|
||||
expected: %v`, file(t), a, b)
|
||||
t.FailNow()
|
||||
}
|
Reference in New Issue
Block a user