[TestUnit pack] Unequal equality

F

felix.leg

I've got such that output during testing my program:
[terminal_output]
Loaded suite ./niep_test
Started
.....F.
Finished in 0.009922 seconds.

1) Failure:
test_sanity(SFTester)
[./niep_test.rb:12:in `sanity'
./niep_test.rb:19:in `test_sanity']:
<7.8e-11> expected but was
<7.8e-11>.

6 tests, 9 assertions, 1 failures, 0 errors
[/terminal_output]

A you can see the assert_equal function reports that something equal is
not equal. WTF? Is it some bug in TestUnit package, or my program just
looks to work fine?
 
J

Joel VanderWerf

I've got such that output during testing my program:
[terminal_output]
Loaded suite ./niep_test
Started
....F.
Finished in 0.009922 seconds.

1) Failure:
test_sanity(SFTester)
[./niep_test.rb:12:in `sanity'
./niep_test.rb:19:in `test_sanity']:
<7.8e-11> expected but was
<7.8e-11>.

6 tests, 9 assertions, 1 failures, 0 errors
[/terminal_output]

A you can see the assert_equal function reports that something equal is
not equal. WTF? Is it some bug in TestUnit package, or my program just
looks to work fine?

Probably it's due to IEEE floating point inaccuracy. Try using
assert_in_delta instead of assert_equal whenever you compare floats in a
test.
 
R

Ryan Davis

A you can see the assert_equal function reports that something equal =
is not equal. WTF? Is it some bug in TestUnit package, or my program =
just looks to work fine?

Welcome to floating point math. Equality is a no-no with floats. What =
you want is assert_in_delta.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top