Skip to content

Commit

Permalink
Add scattering analysis unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
rc83 committed Feb 6, 2020
1 parent d9fda29 commit dbdd5a1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ set(tsts
${CMAKE_SOURCE_DIR}/src/molecule_test.h
${CMAKE_SOURCE_DIR}/src/particle_test.h
${CMAKE_SOURCE_DIR}/src/potentials_test.h
${CMAKE_SOURCE_DIR}/src/scatter_test.h
${CMAKE_SOURCE_DIR}/src/space_test.h
${CMAKE_SOURCE_DIR}/src/tensor_test.h
)
Expand Down
41 changes: 41 additions & 0 deletions src/scatter_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "analysis.h"
#include "io.h"

namespace Faunus {
namespace Scatter {

using doctest::Approx;

double box = 80;
const std::vector<Point> positions = {
{10, 20, 30}, {-32, 19, 1}, {34, -2, 23}, {0, 0, 1}, {25, 0, -12},
{-6, -4, -29}, {-12, 23, -3}, {3, 1, -4}, {-31, 29, -20}}; // random position vector

TEST_CASE_TEMPLATE("[Faunus] StructureFactorPBC", T, StructureFactorPBC<float>) {
size_t cnt = 0;
std::vector<float> result = {0.0785, 1.48621, 0.1111, 0.567279, 0.136, 1.39515,
0.1571, 0.730579, 0.2221, 0.701547, 0.2721, 0.692064};
T scatter(2);
scatter.sample(positions, box);
for (auto [q, S] : scatter.getSampling()) {
CHECK(q == Approx(result[cnt++]));
CHECK(S == Approx(result[cnt++]));
}
CHECK(cnt == result.size());
}

TEST_CASE("[Faunus] StructureFactorIPBC") {
size_t cnt = 0;
std::vector<double> result = {0.0785, 0.384363, 0.1111, 1.51652, 0.136, 1.18027,
0.1571, 1.40662, 0.2221, 2.06042, 0.2721, 1.53482};
StructureFactorIPBC scatter(2);
scatter.sample(positions, box);
for (auto [q, S] : scatter.getSampling()) {
CHECK(q == Approx(result[cnt++]));
CHECK(S == Approx(result[cnt++]));
}
CHECK(cnt == result.size());
}

} // namespace Scatter
} // namespace Faunus
1 change: 1 addition & 0 deletions src/unittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "space_test.h"
#include "tensor_test.h"
#include "externalpotential_test.h"
#include "scatter_test.h"

#include "mpicontroller.h"
#include "auxiliary.h"
Expand Down

0 comments on commit dbdd5a1

Please sign in to comment.