Skip to content

Commit

Permalink
write doc for AddEqual (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyab authored Jul 14, 2024
1 parent 5b45adc commit e33a031
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ teq is a Go library designed to enhance your testing experience by providing a f
## Features

- 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.
- Equals: Register a "equals" function that defines equality. For example, you can allow specific absolute error for float64.
- 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.

## Installation
Expand Down Expand Up @@ -35,6 +36,12 @@ tq.AddTransform(func(d time.Time) time.Time {
tq.AddFormat(func(d time.Time) string {
return d.Format(time.RFC3339)
})

// Absolute error up to 1e-3 is allowed.
tq.AddEqual(func(a, b float64) bool {
const epsilon = 1e-3
return math.Abs(a-b) < epsilon
})
```

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

0 comments on commit e33a031

Please sign in to comment.