serde-rs/test

serde_test floats close values are not possible to test for.

meltinglava opened this issue · 1 comments

I want to check that a serialization an f64 that is stored in radians to degrees. When i convert into and from radians, there is a minor expected difference in the value.
Example: panicked at 'expected Token::F64(59.949999999999996) but serialized as F64(59.95)
Could not figure out how to fix this.

I think you would need to put the computation in the test to match the computation that you expect the Serialize impl(s) to perform, i.e. instead of Token::F64(/* float literal */) you would specify Token::F64(/* the arithmetic computation */). This way the float will match exactly if the Serialize impl is performing the computation that you expect.