Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

NotEqual doesnot work for pointer value in map #296

Closed
rtxu opened this issue Apr 15, 2016 · 4 comments
Closed

NotEqual doesnot work for pointer value in map #296

rtxu opened this issue Apr 15, 2016 · 4 comments

Comments

@rtxu
Copy link

rtxu commented Apr 15, 2016

complete example:https://gist.github.com/xrtgavin/c63bc51914f40fe20fae1ca7dee13b40

func (suite *UtilUT) TestNotEqual() {
    m := make(map[string]*int)
    i := 0
    m["0"] = &i
    n := make(map[string]*int)
    j := 0
    n["0"] = &j

    fmt.Println("m0 = ", m["0"])
    fmt.Println("n0 = ", n["0"])
    suite.NotEqual(m["0"], n["0"])
}

Output:

$go test -v
=== RUN TestUtilUT
=== RUN TestNotEqual
m0 =  0xc20802b3d8
n0 =  0xc20802b3f0
--- FAIL: TestNotEqual (0.00s)
        Error Trace:    not_equal_test.go:33
        Error:          Should not be: (*int)(0xc20802b3f0)

--- FAIL: TestUtilUT (0.00s)
FAIL
exit status 1
FAIL    play    0.032s
@rtxu
Copy link
Author

rtxu commented Apr 15, 2016

testify commit:67106a5111a06241c8d84952c33214675f51a34a

@rtxu rtxu changed the title NotEqual doesnot work NotEqual doesnot work for pointer value in map Apr 18, 2016
@rstrong-pica9
Copy link

Is this specific to pointers in maps or applicable to all pointer comparison? I ran into a similar issue comparing pointers without maps:

func TestPointers(t *testing.T) {
    i := 0
    m := &i
    j := 0
    n := &j

    assert.NotEqual(t, m, n)
}
--- FAIL: TestPointers (0.00s)
        Error Trace:    queue_test.go:40
        Error:      Should not be: (*int)(0xc82000b8a8)

Seems like an obvious use case so I wasn't sure if I was misunderstanding how this was expected to work.

@ernesto-jimenez
Copy link
Member

Hi Rob,

It should be applicable to all pointers.

NotEqual is comparing the values the pointers point to, rather than the
pointer addresses.

We must make that clear in the docs.

On Wed, May 18, 2016 at 11:11 PM, Rob Strong notifications@github.com
wrote:

Is this specific to pointers in maps or applicable to all pointer
comparison? I ran into a similar issue comparing pointers without maps:

func TestPointers(t *testing.T) {
i := 0
m := &i
j := 0
n := &j

assert.NotEqual(t, m, n)

}

--- FAIL: TestPointers (0.00s)
Error Trace: queue_test.go:40
Error: Should not be: (*int)(0xc82000b8a8)

Seems like an obvious use case so I wasn't sure if I was misunderstanding
how this was expected to work.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#296 (comment)

Ernesto Jiménez
http://twitter.com/ernesto_jimenez
http://www.linkedin.com/in/ernestojimenez
http://ernesto-jimenez.com

@ernesto-jimenez
Copy link
Member

I've created an issue to make docs more clear: #358

Closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants