matryer / matryer/is

Issue equating zero `big.{Int,Float}`'s

Open
#56 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2k
Forks
67
PR merge metrics
No merged PRs in 30d

Description

When comparing std `big.Int`'s or `big.Float`'s there is an edge case for the value zero where `is` reports the error `0 != 0`. The reason for this is the `big.{Int,Float}` attribute `neg bool` which can be both `true` and `false` for the value zero.

## Example

```go
package main

import (
"math/big"
"testing"

"github.com/matryer/is"
)

func TestBig(t *testing.T) {
is := is.NewRelaxed(t)
big0 := new(big.Int).Add(big.NewInt(-1), big.NewInt(1))
is.Equal(new(big.Int), big0) // big.Int
is.Equal(new(big.Float), big.NewFloat(0)) // big.Float
}
```

This will result in:
```
is_test.go:13: 0 != 0 // big.Int
is_test.go:14: 0 != 0 // big.Float
--- FAIL: TestBig (0.00s)
FAIL
```

It's not really a bug since the structs are different after all. However, since this are std types it would be nice if they would be compared by their `Cmp` function.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the is.Equal entry point and reproduce the issue with the TestBig example shown in the report. Inspect how big.Int and big.Float values are compared; done means equivalent zero values compare equal through their Cmp behavior and the example passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.