Skip to content

Commit 5631839

Browse files
authored
feat(numbers): added InEpsilonSymmetric (#109)
This variant of InEpsilon (also available as a generic assertion), uses a modified relative error, so that both operands play a symmetric role. This is useful when the "expected" value doesn't play a particular role when asserting that 2 numbers are close. Mirrors python's math.isclose. Refers to: stretchr#1839 Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent 938b8ea commit 5631839

24 files changed

Lines changed: 1119 additions & 25 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Godeps
44
.idea
55
*.out
66
.mcp.json
7+
go.work.sum

assert/assert_assertions.go

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_assertions_test.go

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_examples_test.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_format.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_format_test.go

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_forward.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assert/assert_forward_test.go

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/doc-site/api/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Each domain contains assertions regrouped by their use case (e.g. http, json, er
4040
- [File](./file.md) - Asserting OS Files (6)
4141
- [Http](./http.md) - Asserting HTTP Response And Body (7)
4242
- [Json](./json.md) - Asserting JSON Documents (5)
43-
- [Number](./number.md) - Asserting Numbers (7)
43+
- [Number](./number.md) - Asserting Numbers (9)
4444
- [Ordering](./ordering.md) - Asserting How Collections Are Ordered (10)
4545
- [Panic](./panic.md) - Asserting A Panic Behavior (4)
4646
- [Safety](./safety.md) - Checks Against Leaked Resources (Goroutines, File Descriptors) (2)

docs/doc-site/api/metrics.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Counts for core functionality, and generated variants (formatted, forward, forwa
1515

1616
| Kind | Count | Note |
1717
| ------------------------- | ----------------- | ---- |
18-
| All core functions | 135 | Maintained core |
19-
| All core assertions | 131 | Usage with `*testing.T` |
20-
| Generic assertions | 50 | Type-safe assertions ("T" suffix) |
18+
| All core functions | 137 | Maintained core |
19+
| All core assertions | 133 | Usage with `*testing.T` |
20+
| Generic assertions | 51 | Type-safe assertions ("T" suffix) |
2121
| Helpers (not assertions) | 4 | General-purpose utilities, not assertions |
2222
| Others | 0 | |
23-
| assert/require variants | 424 | Generated variants |
24-
| Total assertions variants | 848 | Available assertions API |
25-
| Total API surface | 858 | |
23+
| assert/require variants | 430 | Generated variants |
24+
| Total assertions variants | 860 | Available assertions API |
25+
| Total API surface | 870 | |
2626

2727
## Quick index
2828

@@ -71,6 +71,8 @@ Table of core assertions, excluding variants. Each function is side by side with
7171
| [InDeltaT[Number Measurable]](number/#indeltatnumber-measurable) {{% icon icon="star" color=orange %}} | | number | |
7272
| [InEpsilon](number/#inepsilon) | | number | |
7373
| [InEpsilonSlice](number/#inepsilonslice) | | number | |
74+
| [InEpsilonSymmetric](number/#inepsilonsymmetric) | | number | |
75+
| [InEpsilonSymmetricT[Number Measurable]](number/#inepsilonsymmetrictnumber-measurable) {{% icon icon="star" color=orange %}} | | number | |
7476
| [InEpsilonT[Number Measurable]](number/#inepsilontnumber-measurable) {{% icon icon="star" color=orange %}} | | number | |
7577
| [IsDecreasing](ordering/#isdecreasing) | [IsNonDecreasing](ordering/#isnondecreasing) | ordering | |
7678
| [IsDecreasingT[OrderedSlice ~[]E, E Ordered]](ordering/#isdecreasingtorderedslice-e-e-ordered) {{% icon icon="star" color=orange %}} | [IsNonDecreasingT](ordering/#isnondecreasingtorderedslice-e-e-ordered) | ordering | |

0 commit comments

Comments
 (0)