Skip to content
This repository has been archived by the owner on Mar 20, 2020. It is now read-only.

Commit

Permalink
Do unit test and regression test #4 (#35)
Browse files Browse the repository at this point in the history
* 🎨 make new regression test separated from unit test

* 🔧 change name of regression test case to cube

* 🎨 regression test with input

* 📎 merging to develop
  • Loading branch information
ezrayst authored and kks32 committed Oct 12, 2017
1 parent f4689bd commit 71b1ea2
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 7 deletions.
24 changes: 17 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,27 @@ SET(mpm_point_gen_src
add_executable(mpm_point_generator ${mpm_point_gen_src})

# Unit test
SET(test_src
${PROJECT_SOURCE_DIR}/tests/test.cc
SET(unit_test_src
${PROJECT_SOURCE_DIR}/tests/unit_test.cc
${PROJECT_SOURCE_DIR}/tests/point_test.cc
${PROJECT_SOURCE_DIR}/tests/material_properties_test.cc
)
add_executable(mpm_point_generator_test ${test_src})
add_executable(mpm_point_generator_unit_test ${unit_test_src})

# Regression test
SET(regression_test_src
${PROJECT_SOURCE_DIR}/tests/regression_test.cc
${PROJECT_SOURCE_DIR}/tests/gmsh_test.cc
)
add_executable(mpm_point_generator_regression_test ${regression_test_src})

option(EIGEN3_HEADER_PATH "path to eigen3 header files, command line option" "")


add_test(NAME mpm_point_generator_test COMMAND $<TARGET_FILE:mpm_point_generator_test>)
add_test(NAME mpm_point_generator_unit_test COMMAND $<TARGET_FILE:mpm_point_generator_unit_test>)
include(CTest)

add_test(NAME mpm_point_generator_regression_test COMMAND $<TARGET_FILE:mpm_point_generator_regression_test>)
include(CTest)

find_program( MEMORYCHECK_COMMAND valgrind )
Expand All @@ -67,7 +77,7 @@ set( MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1" )
# Coverage
find_package(codecov)
add_coverage(mpm_point_generator)
add_coverage(mpm_point_generator_test)

add_coverage(mpm_point_generator_unit_test)
add_coverage(mpm_point_generator_regression_test)

install(TARGETS mpm_point_generator mpm_point_generator_test RUNTIME DESTINATION bin)
install(TARGETS mpm_point_generator mpm_point_generator_unit_test mpm_point_generator_regression_test RUNTIME DESTINATION bin)
75 changes: 75 additions & 0 deletions bin/cube_test.msh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
$MeshFormat
2.2 0 8
$EndMeshFormat
$Nodes
18
1 0 0 0
2 1 0 0
3 0 1 0
4 1 1 0
5 0 0 1
6 1 0 1
7 1 1 1
8 0 1 1
9 0.5 0 0
10 0.5 1 0
11 0.5 0 1
12 0.5 1 1
13 0 0 0.5
14 1 0 0.5
15 1 1 0.5
16 0 1 0.5
17 0.5 0 0.5
18 0.5 1 0.5
$EndNodes
$Elements
48
1 15 2 0 1 1
2 15 2 0 2 2
3 15 2 0 3 3
4 15 2 0 4 4
5 15 2 0 5 5
6 15 2 0 6 6
7 15 2 0 10 7
8 15 2 0 14 8
9 1 2 0 1 1 9
10 1 2 0 1 9 2
11 1 2 0 2 3 10
12 1 2 0 2 10 4
13 1 2 0 3 1 3
14 1 2 0 4 2 4
15 1 2 0 7 5 11
16 1 2 0 7 11 6
17 1 2 0 8 6 7
18 1 2 0 9 7 12
19 1 2 0 9 12 8
20 1 2 0 10 8 5
21 1 2 0 12 1 13
22 1 2 0 12 13 5
23 1 2 0 13 2 14
24 1 2 0 13 14 6
25 1 2 0 17 4 15
26 1 2 0 17 15 7
27 1 2 0 21 3 16
28 1 2 0 21 16 8
29 3 2 0 5 1 9 10 3
30 3 2 0 5 9 2 4 10
31 3 2 0 14 1 9 17 13
32 3 2 0 14 13 17 11 5
33 3 2 0 14 9 2 14 17
34 3 2 0 14 17 14 6 11
35 3 2 0 18 2 4 15 14
36 3 2 0 18 14 15 7 6
37 3 2 0 22 3 16 18 10
38 3 2 0 22 16 8 12 18
39 3 2 0 22 10 18 15 4
40 3 2 0 22 18 12 7 15
41 3 2 0 26 1 13 16 3
42 3 2 0 26 13 5 8 16
43 3 2 0 27 5 11 12 8
44 3 2 0 27 11 6 7 12
45 5 2 0 1 1 9 10 3 13 17 18 16
46 5 2 0 1 13 17 18 16 5 11 12 8
47 5 2 0 1 9 2 4 10 17 14 15 18
48 5 2 0 1 17 14 15 18 11 6 7 12
$EndElements
88 changes: 88 additions & 0 deletions tests/gmsh_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// GMSH test
#include <array>
#include <limits>

#include <eigen3/Eigen/Dense>

#include "catch.hpp"
#include "material_points.h"
#include "gmsh.h"
#include "regression_global.h"


//! Alias for JSON
#include "json.hpp"
using json = nlohmann::json;

//! \brief Check that IO will store right values
TEST_CASE("GMSH is checked in 3D", "[GMSH][3D]") {

//! 3D Test of IO Class
const unsigned DIM = 3;
const double tolerance = 1.E-12;

//! Make json object with material in it
json material_json= {
{"density", 2000},
{"k0", 0.5}
};

//! Make pointers to mesh and MaterialProperties
auto mesh = std::unique_ptr<Mesh<3, 8>> (new GMSH<3, 8>());
auto material = std::shared_ptr<MaterialProperties> (new MaterialProperties(material_json));

mesh->read_mesh(filename);
mesh->compute_material_points(1);
mesh->assign_material_properties(material);
mesh->compute_stresses();

//! Check number of vertices
REQUIRE(mesh->nvertices() == 18);

//! Get coordinates and stress
std::vector<Eigen::VectorXd> coordinates = mesh->coordinates();
std::vector<Eigen::VectorXd> stresses = mesh->stress();

//! Check size
REQUIRE(mesh->coordinates().size() == 4);

//! Check coordinates
REQUIRE(coordinates.at(0)[0] == Approx(0.25).epsilon(tolerance));
REQUIRE(coordinates.at(0)[1] == Approx(0.50).epsilon(tolerance));
REQUIRE(coordinates.at(0)[2] == Approx(0.25).epsilon(tolerance));
REQUIRE(coordinates.at(1)[0] == Approx(0.25).epsilon(tolerance));
REQUIRE(coordinates.at(1)[1] == Approx(0.50).epsilon(tolerance));
REQUIRE(coordinates.at(1)[2] == Approx(0.75).epsilon(tolerance));
REQUIRE(coordinates.at(2)[0] == Approx(0.75).epsilon(tolerance));
REQUIRE(coordinates.at(2)[1] == Approx(0.50).epsilon(tolerance));
REQUIRE(coordinates.at(2)[2] == Approx(0.25).epsilon(tolerance));
REQUIRE(coordinates.at(3)[0] == Approx(0.75).epsilon(tolerance));
REQUIRE(coordinates.at(3)[1] == Approx(0.50).epsilon(tolerance));
REQUIRE(coordinates.at(3)[2] == Approx(0.75).epsilon(tolerance));

//! Check stress
REQUIRE(stresses.at(0)[0] == Approx(-4905).epsilon(tolerance));
REQUIRE(stresses.at(0)[1] == Approx(-4905).epsilon(tolerance));
REQUIRE(stresses.at(0)[2] == Approx(-9810).epsilon(tolerance));
REQUIRE(stresses.at(0)[3] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(0)[4] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(0)[5] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(1)[0] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(1)[1] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(1)[2] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(1)[3] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(1)[4] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(1)[5] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(2)[0] == Approx(-4905).epsilon(tolerance));
REQUIRE(stresses.at(2)[1] == Approx(-4905).epsilon(tolerance));
REQUIRE(stresses.at(2)[2] == Approx(-9810).epsilon(tolerance));
REQUIRE(stresses.at(2)[3] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(2)[4] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(2)[5] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(3)[0] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(3)[1] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(3)[2] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(3)[3] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(3)[4] == Approx(0).epsilon(tolerance));
REQUIRE(stresses.at(3)[5] == Approx(0).epsilon(tolerance));
}
6 changes: 6 additions & 0 deletions tests/regression_global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef REGRESSION_GLOBAL_H_
#define REGRESSION_GLOBAL_H_

extern std::string filename;

#endif // REGRESSION_GLOBAL_H_
27 changes: 27 additions & 0 deletions tests/regression_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
#include "regression_global.h"

std::string filename;

int main(int argc, char** argv) {

try {
//! Check the number of arguments
if (argc != 2) {
std::cout << "Usage: ./mpm_point_generator_regression_test /path/to/meshfile.msh\n";
throw std::runtime_error("Incorrect number of input arguments");
}

//! Pass the argument of the file
filename = argv[1];

int result = Catch::Session().run();

return ( result < 0xff ? result : 0xff );

} catch (std::exception& except) {
std::cout << "Caught exception: " << except.what() << '\n';
}

}
File renamed without changes.

0 comments on commit 71b1ea2

Please sign in to comment.