Unit Testing a Floating Point Result

Sep 27th, 2006No Comments

I’m mucking around with CppUnit again and kept getting caught with testing a floating point result. After scratching my head some, I figured out that duh I had a ton of precision from function, and there was no way that I could enter that exact number in.  So instead of this:

CPPUNIT_ASSERT(distance>121.815123542);

I just did:

CPPUNIT_ASSERT(distance>121.815 && distance<121.816);

Leave a Reply

You must be logged in to post a comment.