Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

assert two NaN values #624

Open
ghost opened this issue Jun 28, 2018 · 5 comments
Open

assert two NaN values #624

ghost opened this issue Jun 28, 2018 · 5 comments
Labels
enhancement pkg-assert Change related to package testify/assert wontfix

Comments

@ghost
Copy link

ghost commented Jun 28, 2018

when i try to assert two NaN values the assert result was

$ go test
--- FAIL: TestNaN (0.00s)
	main_test.go:10: 
			Error Trace:	main_test.go:10
			Error:      	Not equal: 
			            	expected: NaN
			            	actual  : NaN
			Test:       	TestNaN
FAIL
FAIL	command-line-arguments	0.230s

the code that genrate this error is

package test

import (
        "github.com/stretchr/testify/assert"
        "math"
        "testing"
)

func TestNaN(t *testing.T) {
        assert.Equal(t, math.NaN(), math.NaN())
}

because the assert.Equal is based on reflerct.DeepEqual in it documentations written that two floats a,b will be equal if a == b is true.
the golang the act according IEEE 754 is defined NaN == NaN as false.
so this may need discussion about adding assert checking for NaN values.

@mlkr
Copy link

mlkr commented Aug 24, 2018

#632 (comment)

@devdinu
Copy link
Contributor

devdinu commented Aug 26, 2018

@yahelmanor2 NaN its not a number, so you can't compare those 2 values. math.NaN() == math.NaN() its false, so the assert Equal output you've got is as per expectations.

@ghost
Copy link
Author

ghost commented Sep 13, 2018

thanks @devdinu,but there is any way I can test that value equal to NaN within the assert package. I know that assert.True(t,math.IsNaN(i)) will work but I think that it will be better if a solution will be exist within the assert package(i can open PR if needed).

@bkielbasa
Copy link

@yahelmanor2 I think that you should do that :)

@andremarianiello
Copy link

This NaN comparison logic, though not necessarily this function, would be useful to have when comparing deeply nested structs and slices. For example, if I expected to get a slice [0.0, NaN, 8.0] there is nothing I can do (that I know of) except loop through elements.

@dolmen dolmen added rejected/invalid Not a bug but a misunderstanding by the requester enhancement wontfix pkg-assert Change related to package testify/assert and removed rejected/invalid Not a bug but a misunderstanding by the requester labels Mar 6, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement pkg-assert Change related to package testify/assert wontfix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants