Commit 5d12f0cb authored by Jannick Wolters's avatar Jannick Wolters
Browse files

added Catch2 as unit testing framework

parent 64c39c71
......@@ -7,3 +7,6 @@
[submodule "code/ext/spdlog"]
path = code/ext/spdlog
url = git://github.com/gabime/spdlog.git
[submodule "code/ext/Catch2"]
path = code/ext/Catch2
url = git://github.com/catchorg/Catch2.git
......@@ -6,8 +6,10 @@ TBD
### Examples
TBD
---
## Build
### System dependencies
### Required dependencies
- Compiler with C++17 support (GCC >= v6, clang >= v3.8)
- cmake >= v3.5
- LAPACK
......@@ -25,7 +27,7 @@ git submodule init
git submodule update
```
### Compile
### Compile the code
**Make** build system (available on most systems)
```bash
......@@ -45,7 +47,9 @@ ninja
The resulting executable will automatically be placed in the `code/bin` folder.
---
## Run
### Local
Execute the compiled binary and hand over a valid *TOML*-styled config file.
......@@ -66,11 +70,29 @@ with `N` equal to the number of shared memory threads and `J` equal to the numbe
### BwUniCluster
TBD
---
## Tests
In order to also compile the unit tests, add `-DBUILD_TESTING=True` to the cmake command, e.g.:
```bash
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=True ../../
```
The resulting `unit_tests` executable will also be placed in `/bin`.
## Continuous Integration (CI)
TBD
---
## Code structure
![Can't load image](doc/uml.png "UML diagram")
<br/><br/>
The diagram can be modified by opening `doc/uml.zargo` with `ArgoUML`.
---
## Coding style
Please stick to the following coding style for easier code readability:
......
image: ubuntu:18.04
stages:
- build
- test
build:
stage: build
script:
- apt-get update
- apt-get install -y g++ cmake libopenmpi-dev libblas-dev liblapack-dev git ninja-build
- git submodule update --init --recursive
- cd code/build/debug
- cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=True -DCMAKE_EXPORT_COMPILE_COMMANDS=True ../../
- ninja
test:
stage: test
script:
- bin/unit_tests
cmake_minimum_required( VERSION 3.5 )
project( RTSN )
project( RTSN LANGUAGES CXX VERSION 0.0.1 )
set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native" )
set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3 -march=native -pg -no-pie" )
set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -Wall -Werror" )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/" )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin" )
file(GLOB_RECURSE SRCS RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp")
file( GLOB_RECURSE SRCS RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp" )
include_directories( ${CMAKE_SOURCE_DIR}/include )
add_executable( ${CMAKE_PROJECT_NAME} ${SRCS} )
find_package( OpenMP REQUIRED )
......@@ -23,12 +24,26 @@ include_directories( ${MPI_INCLUDE_PATH} )
find_package( LAPACK REQUIRED )
include_directories( ${LAPACK_INCLUDE_DIR} )
include_directories( ${CMAKE_SOURCE_DIR}/../ext/cpptoml/include )
include_directories( ${CMAKE_SOURCE_DIR}/../ext/spdlog/include )
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_definitions('-DGIT_HASH="${GIT_HASH}"')
add_definitions( '-DGIT_HASH="${GIT_HASH}"' )
set( CORE_LIBRARIES ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} -lstdc++fs )
target_link_libraries( ${CMAKE_PROJECT_NAME} ${LAPACK_LIBRARIES} ${VTK_LIBRARIES} ${MPI_LIBRARIES} -lstdc++fs)
target_link_libraries( ${CMAKE_PROJECT_NAME} ${CORE_LIBRARIES} )
if( BUILD_TESTING )
add_subdirectory( ${CMAKE_SOURCE_DIR}/ext/Catch2 )
include_directories( ${CMAKE_SOURCE_DIR}/ext/Catch2/single_include/catch2 )
file( GLOB_RECURSE TEST_SRCS RELATIVE ${CMAKE_SOURCE_DIR} "tests/*.cpp" )
list( REMOVE_ITEM SRCS "src/main.cpp" )
add_executable( unit_tests ${SRCS} ${TEST_SRCS} )
target_link_libraries( unit_tests ${CORE_LIBRARIES} )
endif()
Subproject commit 255aa5f2afe1a622c97422f65ace6ca915be0d8d
unsigned int Factorial( unsigned int number );
#include "factorial_example.h"
unsigned int Factorial( unsigned int number ) { return number > 1 ? Factorial( number - 1 ) * number : 1; }
#include "catch.hpp"
#include "factorial_example.h"
TEST_CASE( "Factorials are computed", "[factorial]" ) {
REQUIRE( Factorial( 0 ) == 1 );
REQUIRE( Factorial( 1 ) == 1 );
REQUIRE( Factorial( 2 ) == 2 );
REQUIRE( Factorial( 3 ) == 6 );
REQUIRE( Factorial( 10 ) == 3628800 );
}
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
Markdown is supported
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