Skip to content

Commit

Permalink
add failure logic for delta +Inf
Browse files Browse the repository at this point in the history
  • Loading branch information
selborsolrac committed May 3, 2023
1 parent 600d8e0 commit e13d9a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions number.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@ func (n *Number) InDeltaRelative(value, delta float64) *Number {
return n
}

if math.IsInf(delta, 0) {
opChain.fail(AssertionFailure{
Type: AssertUsage,
Errors: []error{
errors.New("unexpected Inf delta argument"),
},
})
return n
}

if delta < 0 {
opChain.fail(AssertionFailure{
Type: AssertUsage,
Expand Down Expand Up @@ -402,6 +412,16 @@ func (n *Number) NotInDeltaRelative(value, delta float64) *Number {
return n
}

if math.IsInf(delta, 0) {
opChain.fail(AssertionFailure{
Type: AssertUsage,
Errors: []error{
errors.New("unexpected Inf delta argument"),
},
})
return n
}

if delta < 0 {
opChain.fail(AssertionFailure{
Type: AssertUsage,
Expand Down
4 changes: 2 additions & 2 deletions number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,11 @@ func TestNumber_InDeltaRelative(t *testing.T) {
wantNotInDelta: failure,
},
{
name: "+Inf delta in range",
name: "delta is +Inf",
number: 1234.5,
value: 1234.0,
delta: math.Inf(1),
wantInDelta: success,
wantInDelta: failure,
wantNotInDelta: failure,
},
{
Expand Down

0 comments on commit e13d9a5

Please sign in to comment.