This repository was archived by the owner on Oct 9, 2019. It is now read-only.
This repository was archived by the owner on Oct 9, 2019. It is now read-only.
Should Expect.equal
fail on floats? #230
Open
Description
We have Expect.within
for comparing floats, but people don't necessarily know it's there. They may use Expect.equal
on floats, not realizing that they should use Expect.within
instead.
It occurs to me that we could have Expect.equal
fail the test when given two floats, with an error message pointing the caller to Expect.within
instead.
Here's how we could implement it:
- Have
Expect.equal
start by callingtoString
on both arguments - Convert them both to floats using
String.toFloat
- If that worked,
truncate
both floats and compare them with==
. If the truncation changed either of them, they were non-integers and should have been compared withExpect.within
.
Thoughts?