JUnit has the equivalent of: assert:equals:range:
It could then be:

self assert: 11.11 equals: 11.11 range: 0.0001

Alexandre


> On Sep 2, 2016, at 7:21 PM, Yuriy Tymchuk <yuriy.tymc...@me.com> wrote:
> 
> how about having assert:closeTo: ?
> 
>> On 02 Sep 2016, at 21:09, Henrik Nergaard <henrik.nerga...@uia.no> wrote:
>> 
>> You could implement a custom assert in ConverterTest  to do the comparison, 
>> something like
>> 
>> assert: aNumber withPrecision: precision equals: otherNumber
>> 
>>      self 
>>      assert: (aNumber round: precision) 
>>      equals: otherNumber
>> 
>> assert: aNumber closeTo: otherNumber
>> 
>>      assert: aNumber withPrecision: self defaultPrecision equals: otherNumber
>> 
>> defaultPrecision
>>      ^ 2
>> 
>> 
>> Best regards,
>> Henrik
>> 
>> -----Original Message-----
>> From: Pharo-users [mailto:pharo-users-boun...@lists.pharo.org] On Behalf Of 
>> stepharo
>> Sent: Friday, September 2, 2016 8:41 PM
>> To: Any question about pharo is welcome <pharo-users@lists.pharo.org>
>> Subject: [Pharo-users] Comparing floats
>> 
>> 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
>> 
>> 
>> 
> 
> 

-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




Reply via email to