mirror of
https://github.com/triqs/dft_tools
synced 2024-11-06 22:23:52 +01:00
Added a simple C-test of the ATM library
The tests are build to be executed by CMake test functionality.
This commit is contained in:
parent
911f127789
commit
88dc1eeb78
24
c++/plovasp/atm/test/CMakeLists.txt
Normal file
24
c++/plovasp/atm/test/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
find_package(TriqsTest)
|
||||
enable_testing()
|
||||
|
||||
# Linking and include info
|
||||
#add_library(atm_c dos_tetra3d.hpp dos_tetra3d.cpp argsort.h argsort.c)
|
||||
#set_target_properties(atm_c PROPERTIES LINKER_LANGUAGE CXX)
|
||||
#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/c++/plovasp/atm ${TRIQS_INCLUDE_ALL})
|
||||
|
||||
FILE(GLOB TestList RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
|
||||
FOREACH( TestName1 ${TestList} )
|
||||
STRING(REPLACE ".cpp" "" TestName ${TestName1})
|
||||
add_executable( ${TestName} ${CMAKE_CURRENT_SOURCE_DIR}/${TestName}.cpp )
|
||||
target_link_libraries( ${TestName} atm_c ${TRIQS_LIBRARY_ALL} )
|
||||
triqs_set_rpath_for_target( ${TestName} )
|
||||
triqs_add_cpp_test( ${TestName} )
|
||||
# if (TESTS_C_WITH_VALGRIND)
|
||||
# add_test ( ${TestName}_valgrind valgrind --error-exitcode=1 ${CMAKE_CURRENT_BINARY_DIR}/${TestName})
|
||||
# endif()
|
||||
ENDFOREACH( TestName1 ${TestList} )
|
||||
|
||||
#add_executable(test_atm test2py.cpp)
|
||||
#target_link_libraries(test_atm atm_c)
|
||||
|
||||
#add_subdirectory(test)
|
23
c++/plovasp/atm/test/reorder_flag.cpp
Normal file
23
c++/plovasp/atm/test/reorder_flag.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
#include "testing.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
double e[4], en;
|
||||
int inds[4];
|
||||
int flag, flag_should;
|
||||
|
||||
e[0] = -1.5;
|
||||
e[1] = -1.309017;
|
||||
e[2] = -1.0;
|
||||
e[3] = -0.5;
|
||||
|
||||
en = -0.55;
|
||||
printf("\n Test case 1\n\n");
|
||||
|
||||
flag = dos_reorder(en, e, inds);
|
||||
flag_should = 3;
|
||||
|
||||
if(check_reorder_flag(flag, flag_should)) return 1;
|
||||
}
|
||||
|
27
c++/plovasp/atm/test/reorder_inds.cpp
Normal file
27
c++/plovasp/atm/test/reorder_inds.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
#include "testing.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
double e[4], en;
|
||||
int inds[4], inds_should[4];
|
||||
int flag;
|
||||
|
||||
e[0] = -1.5;
|
||||
e[1] = -1.0;
|
||||
e[2] = -1.309017;
|
||||
e[3] = -0.5;
|
||||
|
||||
en = -0.55;
|
||||
printf("\n Test case 2\n\n");
|
||||
|
||||
flag = dos_reorder(en, e, inds);
|
||||
|
||||
inds_should[0] = 0;
|
||||
inds_should[1] = 2;
|
||||
inds_should[2] = 1;
|
||||
inds_should[3] = 3;
|
||||
|
||||
if(check_reorder_inds(inds, inds_should)) return 1;
|
||||
}
|
||||
|
91
c++/plovasp/atm/test/testing.hpp
Normal file
91
c++/plovasp/atm/test/testing.hpp
Normal file
@ -0,0 +1,91 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
|
||||
#define ASSERT(cond, message) if(!(cond)) { \
|
||||
printf("*** Fail: %s\n", message); return 1;}
|
||||
|
||||
//
|
||||
// Functions defined in 'atm_c' library
|
||||
//
|
||||
extern int dos_corner_weights(double en, double *eigs, int *inds,
|
||||
double *ci);
|
||||
extern int dos_tet_weights(double en, double *eigs, int *inds,
|
||||
double *ct);
|
||||
extern int dos_reorder(double en, double *e, int *inds);
|
||||
|
||||
|
||||
int check_reorder_flag(int flag, int flag_should);
|
||||
int check_reorder_inds(int *inds, int *inds_should);
|
||||
int check_weights_result(double *res, double *r_should);
|
||||
|
||||
//
|
||||
// Test templates
|
||||
//
|
||||
int check_reorder_flag(int flag, int flag_should)
|
||||
{
|
||||
char mess[128];
|
||||
sprintf(mess, "Reorder flag should be %d and not %d", flag_should, flag);
|
||||
ASSERT(flag == flag_should, mess);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int check_reorder_inds(int *inds, int *inds_should)
|
||||
{
|
||||
char mess[128], tmp[128], numb[128];
|
||||
int i, flag;
|
||||
|
||||
strcpy(mess, "Inds should be ");
|
||||
numb[0] = '\0';
|
||||
flag = 1;
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
if(inds_should[i] != inds[i]) flag = 0;
|
||||
sprintf(tmp, " %d", inds_should[i]);
|
||||
strcat(numb, tmp);
|
||||
}
|
||||
strcat(mess, numb);
|
||||
strcat(mess, " and not");
|
||||
numb[0] = '\0';
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
sprintf(tmp, " %d", inds[i]);
|
||||
strcat(numb, tmp);
|
||||
}
|
||||
strcat(mess, numb);
|
||||
|
||||
ASSERT(flag, mess);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int check_weights_result(double *res, double *r_should)
|
||||
{
|
||||
const double tol = 1e-14;
|
||||
int i, flag;
|
||||
char mess[128], tmp[128];
|
||||
|
||||
flag = 1;
|
||||
for(i = 0; i < 4; i++)
|
||||
{
|
||||
if(fabs(r_should[i] - res[i]) > tol)
|
||||
{
|
||||
flag = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
strcpy(mess, "Success");
|
||||
if(!flag)
|
||||
{
|
||||
sprintf(mess, "res[%d] should be %20.15lf", i, r_should[i]);
|
||||
sprintf(tmp, " and not %20.15lf", res[i]);
|
||||
strcat(mess, tmp);
|
||||
}
|
||||
|
||||
ASSERT(flag, mess);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
35
c++/plovasp/atm/test/tet_weights.cpp
Normal file
35
c++/plovasp/atm/test/tet_weights.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
#include "testing.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
double e[4], en, ci_sum, ct, res[4];
|
||||
int inds[4], inds_should[4];
|
||||
int i, flag;
|
||||
char mess[128];
|
||||
|
||||
e[0] = -1.5;
|
||||
e[1] = -1.309017;
|
||||
e[2] = -1.0;
|
||||
e[3] = -0.5;
|
||||
|
||||
en = -0.55;
|
||||
printf("\n Test case 2\n\n");
|
||||
|
||||
flag = dos_reorder(en, e, inds);
|
||||
|
||||
dos_corner_weights(en, e, inds, res);
|
||||
dos_tet_weights(en, e, inds, &ct);
|
||||
|
||||
for(i = 0, ci_sum = 0.0; i < 4; i++)
|
||||
{
|
||||
printf(" res[%d] = %20.15lf\n", i, res[i]);
|
||||
ci_sum += res[i];
|
||||
}
|
||||
|
||||
printf(" Difference: %le\n", fabs(ci_sum - ct));
|
||||
|
||||
sprintf(mess, "Difference between 'ci_sum' and 'ct' is too large");
|
||||
ASSERT(fabs(ci_sum - ct) < 1e-12, mess);
|
||||
}
|
||||
|
27
c++/plovasp/atm/test/weights1.cpp
Normal file
27
c++/plovasp/atm/test/weights1.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
#include "testing.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
double e[4], en, res[4], r_should[4];
|
||||
int inds[4];
|
||||
int flag;
|
||||
|
||||
e[0] = -1.5;
|
||||
e[1] = -1.309017;
|
||||
e[2] = -1.0;
|
||||
e[3] = -0.5;
|
||||
|
||||
en = -0.55;
|
||||
printf("\n Test case 4\n\n");
|
||||
|
||||
dos_corner_weights(en, e, inds, res);
|
||||
|
||||
r_should[0] = 0.000309016992226;
|
||||
r_should[1] = 0.000381966005939;
|
||||
r_should[2] = 0.000618033984453;
|
||||
r_should[3] = 0.017232002550965;
|
||||
|
||||
if(check_weights_result(res, r_should)) return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user