48 lines
769 B
Go
Raw Permalink Normal View History

2023-07-05 11:14:37 +00:00
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
}
2023-07-05 11:37:11 +00:00
t.Errorf(`
2023-07-05 11:14:37 +00:00
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
}
2023-07-05 11:37:11 +00:00
t.Errorf(`
2023-07-05 11:14:37 +00:00
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
}
2023-07-05 11:37:11 +00:00
2023-07-05 11:14:37 +00:00
t.Errorf(`
file: %s
assert: DeepEqual
value: %v
expected: %v`, file(t), a, b)
t.FailNow()
}