Go tests are failing
maljub01 opened this issue · comments
With #29 patched or checked in, running the go tests using:
GOPATH=`pwd` go test -v go/objecthash/objecthash.go go/objecthash/objecthash_test.go
Results in the following output:
=== RUN TestGolden
--- PASS: TestGolden (0.00s)
=== RUN ExampleCommonJSONHash_Common
--- PASS: ExampleCommonJSONHash_Common (0.00s)
=== RUN ExampleCommonJSONHash_FloatAndInt
--- PASS: ExampleCommonJSONHash_FloatAndInt (0.00s)
=== RUN ExampleCommonJSONHash_KeyChange
--- PASS: ExampleCommonJSONHash_KeyChange (0.00s)
=== RUN ExampleCommonJSONHash_KeyOrderIndependence
--- PASS: ExampleCommonJSONHash_KeyOrderIndependence (0.00s)
=== RUN ExampleObjectHash_JSON
--- PASS: ExampleObjectHash_JSON (0.00s)
=== RUN ExampleObjectHash_JSON2
--- FAIL: ExampleObjectHash_JSON2 (0.00s)
got:
783a423b094307bcb28d005bc2f026ff44204442ef3513585e7e73b66e3c2213
783a423b094307bcb28d005bc2f026ff44204442ef3513585e7e73b66e3c2213
want:
726e7ae9e3fadf8a2228bf33e505a63df8db1638fa4f21429673d387dbd1c52a
783a423b094307bcb28d005bc2f026ff44204442ef3513585e7e73b66e3c2213
=== RUN ExampleObjectHash_Set
--- FAIL: ExampleObjectHash_Set (0.00s)
got:
573b37091d5e1642f8a33517147a9e2e60b01689d7d3c688e001d288ba3a5228
want:
618cf0582d2e716a70e99c2f3079d74892fec335e3982eb926835967cb0c246c
=== RUN ExampleObjectHash_ComplexSet
--- FAIL: ExampleObjectHash_ComplexSet (0.00s)
got:
d60f36a67688b9137b5463adee3f4d15339eb8f3e1f02f81eccf8b113408d0fd
want:
3773b0a5283f91243a304d2bb0adb653564573bc5301aa8bb63156266ea5d398
=== RUN ExampleObjectHash_ComplexSetRepeated
--- FAIL: ExampleObjectHash_ComplexSetRepeated (0.00s)
got:
55885cc37fea864170a2d8874a537fdd2a0be932f2f23df0bedf72642fe3bd78
want:
3773b0a5283f91243a304d2bb0adb653564573bc5301aa8bb63156266ea5d398
FAIL
exit status 1
FAIL command-line-arguments 0.026s
After looking more into this, it turns out that the root cause here is that Go differentiates between integer and floating-point values but JSON does not.
The expected values in the tests seem to have been based on using the internal objectHash
which treats integers differently and changing the tests to use objectHash
instead of ObjectHash
would make them pass (See #21). However, I don't like this solution because objectHash
is not exported by the package and the tests should exercise public methods not internal ones.
I prefer to instead update the expected values to the ones returned by the failing test because those are the correct values.
There's still the question of whether hashInt
should be removed since it should never run given that everything goes through JSON here. Also, the case int
in objecthash
can either be removed or switched to use hashFloat(float64(v))
instead.
This was fixed in 381137c.