From 788def65f64efcb11531287f85059557fc259fab Mon Sep 17 00:00:00 2001 From: Christian Rauch Date: Mon, 6 May 2024 22:41:33 +0200 Subject: [PATCH] [WIP] fix float comparison in test --- test/test_detection.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/test_detection.c b/test/test_detection.c index 63d49e12..d6d1b9ea 100644 --- a/test/test_detection.c +++ b/test/test_detection.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "getline.h" @@ -100,8 +101,30 @@ main(int argc, char *argv[]) printf("Got: %s\n", det_fmt); printf("Expected: %s\n", line); + // parse reference detections + int ref_i; + int ref_id; + double ref_p[4][2]; + const char ref_fmt[] = "%i, %i, (%lf %lf), (%lf %lf), (%lf %lf), (%lf %lf)"; + const int nparsed = sscanf(line, ref_fmt, + &ref_i, &ref_id, + &ref_p[0][0], &ref_p[0][1], &ref_p[1][0], &ref_p[1][1], + &ref_p[2][0], &ref_p[2][1], &ref_p[3][0], &ref_p[3][1]); + // compare strings without the newline character (\n) - if (strncmp(det_fmt, line, nread-1) != 0) { + // if (strncmp(det_fmt, line, nread-1) != 0) { + // fprintf(stderr, "Mismatch.\nGot:\n %s\nExpected:\n %s\n", det_fmt, line); + // ok = false; + // } + + bool equ = true; + for(int e = 0; e<4; e++) { + for(int c = 0; c<2; c++) { + equ &= fabs(det->p[e][c] - ref_p[e][c]) < 1e-3; + } + } + + if(nparsed != 10 || !equ || det->id != ref_id || i != ref_i) { fprintf(stderr, "Mismatch.\nGot:\n %s\nExpected:\n %s\n", det_fmt, line); ok = false; }