Testing: Increase coverage

This commit is contained in:
Shahram Najm 2023-12-16 12:53:34 +00:00
parent 3029fef852
commit c72a1721fa
2 changed files with 9 additions and 7 deletions

View File

@ -9,6 +9,7 @@
*/ */
#include "grib_api_internal.h" #include "grib_api_internal.h"
#include "eccodes.h"
#define EPSILON 1e-12 #define EPSILON 1e-12
#define DBL_EQUAL(a, b) (fabs((a) - (b)) <= (EPSILON)*fabs((a))) #define DBL_EQUAL(a, b) (fabs((a) - (b)) <= (EPSILON)*fabs((a)))
@ -34,10 +35,10 @@ static void TestDateTime(const long year, const long month, const long day, cons
long jdlong1, jdlong2, date; long jdlong1, jdlong2, date;
/* Convert the input values to a double */ /* Convert the input values to a double */
grib_datetime_to_julian(year, month, day, hour, min, sec, &jd); codes_datetime_to_julian(year, month, day, hour, min, sec, &jd);
/* Convert the double back to the input values and compare */ /* Convert the double back to the input values and compare */
grib_julian_to_datetime(jd, &year1, &month1, &day1, &hour1, &min1, &sec1); codes_julian_to_datetime(jd, &year1, &month1, &day1, &hour1, &min1, &sec1);
if (!Check(year, month, day, hour, min, sec, year1, month1, day1, hour1, min1, sec1)) { if (!Check(year, month, day, hour, min, sec, year1, month1, day1, hour1, min1, sec1)) {
fprintf(stderr, fprintf(stderr,
@ -73,7 +74,7 @@ static void Test0()
min = 26; min = 26;
sec = 24; sec = 24;
grib_datetime_to_julian(year, month, day, hour, min, sec, &jd); codes_datetime_to_julian(year, month, day, hour, min, sec, &jd);
Assert(DBL_EQUAL(jd, 2378891.268333)); Assert(DBL_EQUAL(jd, 2378891.268333));
printf("%ld %ld %ld %ld:%ld:%ld -> %f\n", year, month, day, hour, min, sec, jd); printf("%ld %ld %ld %ld:%ld:%ld -> %f\n", year, month, day, hour, min, sec, jd);
@ -153,9 +154,9 @@ static void Test2()
} }
jdl = (long)(jd + 0.5); jdl = (long)(jd + 0.5);
date = grib_julian_to_date(jdl); date = codes_julian_to_date(jdl);
printf("+ %ld -> %ld\n", date, jdl); printf("+ %ld -> %ld\n", date, jdl);
jdl = grib_date_to_julian(date); jdl = codes_date_to_julian(date);
printf("- %ld -> %ld\n", date, jdl); printf("- %ld -> %ld\n", date, jdl);
printf("\n"); printf("\n");
} }

View File

@ -9,6 +9,7 @@
*/ */
#include "grib_api_internal.h" #include "grib_api_internal.h"
#include "eccodes.h"
#define NUMBER(x) (sizeof(x) / sizeof(x[0])) #define NUMBER(x) (sizeof(x) / sizeof(x[0]))
@ -91,7 +92,7 @@ static void test_gaussian_latitudes(int order)
double lat1 = 0, lat2 = 0; double lat1 = 0, lat2 = 0;
double* lats = (double*)malloc(sizeof(double) * num); double* lats = (double*)malloc(sizeof(double) * num);
ret = grib_get_gaussian_latitudes(order, lats); ret = codes_get_gaussian_latitudes(order, lats);
Assert(ret == GRIB_SUCCESS); Assert(ret == GRIB_SUCCESS);
lat1 = lats[0]; lat1 = lats[0];
@ -112,7 +113,7 @@ static void test_gaussian_latitude_640()
int ret = 0; int ret = 0;
const double tolerance = 1e-6; const double tolerance = 1e-6;
double* lats = (double*)malloc(sizeof(double) * num); double* lats = (double*)malloc(sizeof(double) * num);
ret = grib_get_gaussian_latitudes(order, lats); ret = codes_get_gaussian_latitudes(order, lats);
Assert(ret == GRIB_SUCCESS); Assert(ret == GRIB_SUCCESS);
compare_doubles(lats[0], 89.892396, tolerance); compare_doubles(lats[0], 89.892396, tolerance);