-
Book Overview & Buying
-
Table Of Contents
Test-Driven Development with C++
By :
At the most basic level, confirms work by comparing an expected value with an actual value and throwing an exception if they are different. This works for all the integral types such as int and long, bool types, and even strings. The values either match or don’t match.
This is where things get difficult for the float and double floating point types – because it’s not always possible to accurately compare two floating-point values.
Even in the decimal system that we are used to from grade school, we understand there are some fractional values that can’t be accurately represented. A value such as 1/3 is easy to represent as a fraction. But writing it in a floating-point decimal format looks like 0.33333 with the digit 3 continuing forever. We can get close to the true value of 1/3, but at some point, we have to stop when writing 0.333333333... And no matter how many 3s we include, there are always more.
In C++, floating...