Why not use "equalsTo:"?

Floats are tricky, you either round your result before comparing or
change the comparison method.

0.333333333333333333 equalsTo: (1/3) "true"

Regards!
Esteban A. Maringolo


2016-09-02 15:41 GMT-03:00 stepharo <steph...@free.fr>:
> Hi
>
> I'm writing a simple converter between Celcius and Farhenheit as an example
> to start programming.
>
>
> Converter >> convertFarhenheit: anInteger
>     ^ ((anInteger - 32) / 1.8)
>
> ConverterTest >> testFToC
>
>     | converter |
>     converter := TemperatureConverter new.
>     self assert: ((converter convertFarhenheit: 86) = 30.0).
>     self assert: ((converter convertFarhenheit: 50) = 10).
>     self assert: ((converter convertFarhenheit: 52) = 11.11111111111111)
>
>
> My problem is with ((converter convertFarhenheit: 52) = 11.11111111111111)
>
> I do not want to have such ugly test.
>
> I tried either to control the output
>
> Converter >> convertFarhenheit: anInteger
>     ^ ((anInteger - 32) / 1.8) roundDownTo: 0.1
>
> Not a good idea
>
> Or to compare with closeTo:
>
>     self assert: ((converter convertFarhenheit: 52) closeTo: 11.11)
>
> does not work because we cannot set the precision.
>
> So at ESUG I briefly discuss that with Nicolas Cellier and I need help.
>
> Should I introduce in pharo closeTo:interval:
>
> Any suggestions that a newby can understand is welcome.
>
>
> Stef
>
>
>

Reply via email to