add unittest for ErrorStats class
This commit is contained in:
@ -15,6 +15,11 @@ else()
|
|||||||
target_link_libraries(style_tests PUBLIC mpi_stubs)
|
target_link_libraries(style_tests PUBLIC mpi_stubs)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# unit test for error stats class
|
||||||
|
add_executable(test_error_stats test_error_stats.cpp)
|
||||||
|
target_link_libraries(test_error_stats PRIVATE GTest::GTestMain GTest::GTest)
|
||||||
|
add_test(NAME ErrorStats COMMAND test_error_stats)
|
||||||
|
|
||||||
# pair style tester
|
# pair style tester
|
||||||
add_executable(pair_style pair_style.cpp)
|
add_executable(pair_style pair_style.cpp)
|
||||||
target_link_libraries(pair_style PRIVATE lammps style_tests)
|
target_link_libraries(pair_style PRIVATE lammps style_tests)
|
||||||
|
|||||||
41
unittest/force-styles/test_error_stats.cpp
Normal file
41
unittest/force-styles/test_error_stats.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// include the implementation since ErrorStats is a standalone class
|
||||||
|
// this way we don't have to link against the style_tests and lammps libs
|
||||||
|
|
||||||
|
#include "error_stats.cpp"
|
||||||
|
|
||||||
|
TEST(ErrorStats, test)
|
||||||
|
{
|
||||||
|
ErrorStats stats;
|
||||||
|
|
||||||
|
stats.add(0.5);
|
||||||
|
stats.add(0.1);
|
||||||
|
stats.add(2.0);
|
||||||
|
stats.add(0.3);
|
||||||
|
stats.add(0);
|
||||||
|
|
||||||
|
ASSERT_DOUBLE_EQ(stats.avg(), 0.58);
|
||||||
|
ASSERT_DOUBLE_EQ(stats.dev(), 0.73047929470998685);
|
||||||
|
ASSERT_DOUBLE_EQ(stats.max(), 2.0);
|
||||||
|
ASSERT_EQ(stats.idx(), 3);
|
||||||
|
|
||||||
|
std::stringstream out;
|
||||||
|
out << stats;
|
||||||
|
ASSERT_EQ(out.str(), " Average: 5.800e-01 StdDev: 7.305e-01 MaxErr: 2.000e+00 @ item: 3");
|
||||||
|
|
||||||
|
stats.reset();
|
||||||
|
ASSERT_DOUBLE_EQ(stats.avg(), 0.0);
|
||||||
|
ASSERT_DOUBLE_EQ(stats.dev(), 0.0);
|
||||||
|
ASSERT_DOUBLE_EQ(stats.max(), 0.0);
|
||||||
|
ASSERT_EQ(stats.idx(), -1);
|
||||||
|
|
||||||
|
stats.add(1.0);
|
||||||
|
ASSERT_DOUBLE_EQ(stats.avg(), 1.0);
|
||||||
|
ASSERT_DOUBLE_EQ(stats.dev(), 0.0);
|
||||||
|
ASSERT_DOUBLE_EQ(stats.max(), 1.0);
|
||||||
|
ASSERT_EQ(stats.idx(), 1);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user