[geos-devel] Using static values in Unit Tests
Mateusz Łoskot
mateusz at loskot.net
Mon Apr 3 18:33:19 EDT 2006
Hi,
Simply question, do you think it is safe to use static values for
results comparison in Unit Tests.
In example, I want to test length/area calculations, so I need to
compare result with some well known value.
The simplest solution is to use:
// ...
const double length = 14.142135623730951;
line.getLength() == length
Is this safe regarding double prec. numbers representation
on different architectures?
Another option is to to check the closure of expected result.
A little descriptive example of this concept:
// value of result returned by getLength or getArea
double result = 14.13873095113561;
// well-known and expected result for some test case
const double expected = 14.142135623730951;
// Check equality with accuracy of 0.001
double ab = fabs(result - expected);
if (ab > 0.001)
cout << "EQUAL\n";
else
cout << "NOT EQUAL\n";
or something similar.
What approach would you recommend?
Cheers
--
Mateusz Łoskot
http://mateusz.loskot.net
More information about the geos-devel
mailing list