misc: fix strtod_nol_err tests

A better way of implementing the string to double
conversion and a better way of testing it.

Signed-off-by: Craig Small <csmall@enc.com.au>
This commit is contained in:
Dr. Werner Fink
2016-07-13 20:08:51 +10:00
committed by Craig Small
parent 100afbc149
commit 4ed44ab58e
4 changed files with 20 additions and 18 deletions

View File

@ -1,4 +1,5 @@
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "strutils.h"
@ -33,8 +34,8 @@ int main(int argc, char *argv[])
double val;
for(i=0; tests[i].string != NULL; i++) {
if(strtod_nol_or_err(tests[i].string, "Cannot parse number") !=
tests[i].result) {
val = strtod_nol_or_err(tests[i].string, "Cannot parse number");
if(fabs(tests[i].result - val) > DBL_EPSILON) {
fprintf(stderr, "FAIL: strtod_nol_or_err(\"%s\") != %f\n",
tests[i].string, tests[i].result);
return EXIT_FAILURE;