Skip to content

Commit e33a031

Browse files
authored
write doc for AddEqual (#12)
1 parent 5b45adc commit e33a031

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ teq is a Go library designed to enhance your testing experience by providing a f
77
## Features
88

99
- Transforms: Register a "transform" function that can modify objects before comparison. This allows you to control how equality is determined. For example, by transforming time.Time objects to UTC, you can make your equality checks timezone-insensitive.
10+
- Equals: Register a "equals" function that defines equality. For example, you can allow specific absolute error for float64.
1011
- Formats: Register a "format" function that defines how objects are displayed when they are not equal. This is useful for types like time.Time and decimal.Decimal that may not be human-readable in their default format. By registering your own format, you can make the output of your tests more understandable.
1112

1213
## Installation
@@ -35,6 +36,12 @@ tq.AddTransform(func(d time.Time) time.Time {
3536
tq.AddFormat(func(d time.Time) string {
3637
return d.Format(time.RFC3339)
3738
})
39+
40+
// Absolute error up to 1e-3 is allowed.
41+
tq.AddEqual(func(a, b float64) bool {
42+
const epsilon = 1e-3
43+
return math.Abs(a-b) < epsilon
44+
})
3845
```
3946

4047
Finally, you can use teq to perform deep equality checks in your tests:

0 commit comments

Comments
 (0)