josephburnett / jd

JSON diff and patch
MIT License
826 stars 38 forks source link

Object equality determined by hash which breaks precision #66

Closed josephburnett closed 6 months ago

josephburnett commented 6 months ago

This merge request adds a test which requires object equality to respect precision. It does not because equality uses hash codes which don't work with precision.

josephburnett commented 6 months ago

@adatoo here is an interesting problem that precision creates. What to do with object equality? Currently it's based on hash codes but that doesn't work with precision.

--- FAIL: TestObjectEqual (0.00s)
    common_test.go:2[9](https://github.com/josephburnett/jd/actions/runs/7866317375/job/21460441538?pr=66#step:4:10): map[a:1.0].Equals(map[a:1.1]) == false. Want true.
    common_test.go:32: map[a:1.0].Equals(map[a:1.1]) == false. Want true.
FAIL
FAIL    github.com/josephburnett/jd/lib 0.062s
FAIL

(Also, the workflow should fail if a unit test fails! I'll have to fix that)

josephburnett commented 6 months ago

Or at least I think that's what's going on, I'll have to go back and check. Anyway, that object test should pass.

josephburnett commented 6 months ago

Oh, I made a mistake. I was writing those numbers as strings. Looks like object equality works fine.

But set equality definitely doesn't work with precision because sets (and multisets) use hash codes to find equal values.