Commit 5fbbc3f7 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

add real numeric test

parent 5356e239
Pipeline #14243 failed with stage
in 5 minutes and 59 seconds
# provisional tests
# test whether demo programs run
add_test(NAME countterms COMMAND kww_countterms 10 10)
add_test(NAME runkww COMMAND runkww 0 c a .5 .5)
# test whether numeric results agree with our reference
add_executable(kwwtest kwwtest.c)
target_include_directories(kwwtest PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_link_libraries(kwwtest ${kww_LIBRARY})
add_test(NAME kwwtest COMMAND kwwtest)
/* runkww.c
*
* Copyright (C) 2009-2019 Joachim Wuttke
*
* Licence: GNU General Public License, version 3 or later
*
* Author:
* Joachim Wuttke, Forschungszentrum Jülich, Germany <j.wuttke@fz-juelich.de>
*
* Purpose:
* Test whether numeric results agree with those established under Linux/gcc.
*/
#include "kww.h"
#include <stdio.h>
#include <math.h>
#include <assert.h>
/******************************************************************************/
/* Auxiliary routines */
/******************************************************************************/
// compute relative error |b-a|/|a|, handling case of NaN and Inf,
static double relerr(double a, double b) {
assert(a!=0);
assert(b!=0);
return fabs((b-a) / a);
}
void test_one(int* fail, double limit, double a, double b)
{
static int num = 0;
double re = relerr(a,b);
int ok = re<=limit;
printf(ok ? " " : "ERR");
printf(" test case %i: found=%g, expected=%g, relerr=%g", num, a, b, re);
++num;
if (!ok)
++(*fail);
}
/******************************************************************************/
/* Main: test sequence */
/******************************************************************************/
int main(void) {
int fail = 0;
test_one(&fail, 1e-14, kwwc(1e-6, 1.), 0.9999999999990000221);
test_one(&fail, 1e-14, kwwc(1e-3, 1.), 0.9999990000009999491);
test_one(&fail, 1e-14, kwwc(1 , 1.), .5);
test_one(&fail, 1e-14, kwwc(1e3 , 1.), 9.999990000010000613e-07);
test_one(&fail, 1e-14, kwwc(1e6 , 1.), 9.999999999989999315e-13);
test_one(&fail, 1e-14, kwwc(1e-8, .623), 1.435159133351523009);
test_one(&fail, 1e-14, kwwc(1e-6, .623), 1.435159133336882054);
test_one(&fail, 1e-14, kwwc(1e-4, .623), 1.435158986927334901);
test_one(&fail, 1e-14, kwwc(1e-2, .623), 1.433698427082435778); // mode=1
test_one(&fail, 1e-14, kwwc(1e-1, .623), 1.314878935071708499); // mode=1
test_one(&fail, 1e-14, kwwc(1 , .623), 0.3308323687099594124); // mode=3
test_one(&fail, 1e-14, kwwc(1e2 , .623), 0.0004053330090102800066);
test_one(&fail, 1e-14, kwwc(1e4 , .623), 2.390040041093056597e-07);
test_one(&fail, 1e-14, kwwc(2e-5, .314), 7.602900889248060956); // mode=1
test_one(&fail, 1e-14, kwwc(2e-4, .314), 7.594626504743104078); // mode=2
test_one(&fail, 1e-14, kwwc(2e-3, .314), 7.148958376075823296); // mode=2
test_one(&fail, 1e-14, kwwc(2e-2, .314), 3.922292835319648674); // mode=3
test_one(&fail, 1e-14, kwwc(2e-1, .314), 0.8172678260275950679);
test_one(&fail, 1e-14, kwwc(2e0 , .314), 0.0837197392901634224);
printf("#####################################\n");
if (fail) {
printf("IN TOTAL, FAILURE IN %i TESTS\n", fail);
return 1;
} else {
printf("OVERALL SUCCESS\n");
return 0;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment