Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-11

FPCUnit checking Single values

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ik

Hello,

I'm trying to check Single value.

I'm doing the following:

a := 1.1;
b := 1.1;
CheckEquals(a, b, Format('val %f does not equal %f', [a, b]));

It reports an error, one of them are 1.1 and the other is 1,10 . I know about the possible drifts of floating points, but how can I create a test for such type of values ?

Thanks,
Ido

Reply by email

Unknown author
to ik
ik wrote 13 lines
Hello, I'm trying to check Single value. I'm doing the following: a := 1.1; b := 1.1; CheckEquals(a, b, Format('val %f does not equal %f', [a, b])); It reports an error, one of them are 1.1 and the other is 1,10 . I know about the possible drifts of floating points, but how can I create a test for such type of values ?

Use the delta:

class procedure AssertEquals(const AMessage: string; Expected, Actual, Delta: double); overload;

or, if you insist on using the Delphi compatibility layer:

class procedure CheckNotEquals(expected: extended; actual: extended; delta: extended = 0; msg: string = ''); overload; virtual;

Michael.

Reply by email

ik
to Unknown author
Show quoted text 28 lines
On Fri, 2 Nov 2012, ik wrote: > Hello, > > I'm trying to check Single value. > > I'm doing the following: > > a := 1.1; > b := 1.1; > CheckEquals(a, b, Format('val %f does not equal %f', [a, b])); > > It reports an error, one of them are 1.1 and the other is 1,10 . > I know about the possible drifts of floating points, but how can I > create a test for such type of values ? Use the delta: class procedure AssertEquals(const AMessage: string; Expected, Actual, Delta: double); overload; or, if you insist on using the Delphi compatibility layer: class procedure CheckNotEquals(expected: extended; actual: extended; delta: extended = 0; msg: string = ''); overload; virtual;

Thanks, and It helped me also find that the current drift was a bug in my own code as well :)

Show quoted text 5 lines
Michael. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email