Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Tests in EGOA #18

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 65 additions & 2 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,69 @@ jobs:
-DEGOA_ENABLE_BONMIN=OFF
-DEGOA_ENABLE_BOOST=OFF
-DEGOA_ENABLE_CPLEX=OFF
-DEGOA_ENABLE_DOCUMENTATION=OFF
-DEGOA_ENABLE_EXCEPTION_HANDLING=ON
-DEGOA_ENABLE_GUROBI=OFF
-DEGOA_ENABLE_IPOPT=OFF
-DEGOA_ENABLE_OGDF=OFF
-DEGOA_ENABLE_OPENMP=OFF
-DEGOA_ENABLE_TESTS=OFF
-DEGOA_ENABLE_VERBOSE_MAKEFILE=ON
-DEGOA_PEDANTIC_AS_ERRORS=OFF
-DEGOA_PEDANTIC_MODE=ON
-DEGOA_TEST_FRAMEWORK=OfflineGoogleTestFramework
-DEGOA_TEST_FRAMEWORK_LOCATION=external/GoogleTestFramework
-DEGOA_THREAD_LIMIT=0
-DEGOA_WARNINGS_AS_ERRORS=ON
-DBONMIN_ROOT_DIR="NONE-DIR"
-DBoost_DIRECTORIES="/opt/homebrew/opt/boost/"
-DCOIN_INCLUDE_DIR="NONE-DIR"
-DCOIN_LIBRARY_DIR="NONE-DIR"
-DCPLEX_HOME="NONE-DIR"
-DGUROBI_ROOT_DIR="NONE-DIR"
-DOGDF_AUTOGEN_INCLUDE_DIR="NONE-DIR"
-DOGDF_INCLUDE_DIR="NONE-DIR"
-DOGDF_LIBRARY_DIR="NONE-DIR"
-DOPENMP_INCLUDES="/opt/homebrew/opt/llvm/include"
-DOPENMP_LIBRARIES="/opt/homebrew/opt/llvm/lib"
-S ${{ github.workspace }}

- name: Build (Unix)
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
if: ${{ !startsWith(matrix.os,'windows-') }}
run: sudo cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Build (Windows)
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
if: startsWith(matrix.os,'windows-')
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

# Downloads are done
- name: Configure CMake Full
env:
CMAKE_PREFIX_PATH: ${{env.Qt6_DIR}}
CMAKE_MODULE_PATH: ${{env.Qt6_DIR}}
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DBoost_NO_SYSTEM_PATHS=TRUE
-DEGOA_BUILD_TYPE=${{ matrix.build_type }}
-DEGOA_DOWNLOAD_CPPAD=OFF
-DEGOA_DOWNLOAD_EIGEN=OFF
-DEGOA_DOWNLOAD_GOOGLE_TEST_FRAMEWORK=OFF
-DEGOA_DOWNLOAD_IEEE=OFF
-DEGOA_DOWNLOAD_PYPSA_EUR=OFF
-DEGOA_DOWNLOAD_PYPSA_ITI_COLLABORATION=OFF
-DEGOA_DOWNLOAD_SCIGRID=OFF
-DEGOA_DOWNLOAD_WINDFARM=OFF
-DEGOA_ENABLE_ASSERTION=ON
-DEGOA_ENABLE_BONMIN=OFF
-DEGOA_ENABLE_BOOST=OFF
-DEGOA_ENABLE_CPLEX=OFF
-DEGOA_ENABLE_DOCUMENTATION=ON
-DEGOA_ENABLE_EXCEPTION_HANDLING=ON
-DEGOA_ENABLE_GUROBI=OFF
Expand Down Expand Up @@ -171,7 +234,7 @@ jobs:
-DOPENMP_LIBRARIES="/opt/homebrew/opt/llvm/lib"
-S ${{ github.workspace }}

- name: Build without Windows
- name: Build (Unix)
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
if: ${{ !startsWith(matrix.os,'windows-') }}
run: sudo cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
franziska-wegner marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -185,7 +248,7 @@ jobs:
working-directory: ${{ steps.strings.outputs.build-output-dir }}
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --build-config ${{ matrix.build_type }}
run: ctest --verbose --build-config ${{ matrix.build_type }}

- name: Generate documentation
if: startsWith(matrix.os,'ubuntu-')
Expand Down
29 changes: 22 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@
#

cmake_minimum_required ( VERSION 3.13.1 )
# Required for CMAKE_MSVC_RUNTIME_LIBRARY
# https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html#variable:CMAKE_MSVC_RUNTIME_LIBRARY
cmake_policy(SET CMP0091 NEW)

project ( EGOA CXX )

# The version number.
set ( EGOA_VERSION_MAJOR 1 )
set ( EGOA_VERSION_MINOR 0 )

if ( ${EGOA_BUILD_TYPE} STREQUAL "Debug")
# Select the MSVC runtime library
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebugDLL")
else ()
# Select the MSVC runtime library
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif ()
message ( STATUS "CMAKE_MSVC_RUNTIME_LIBRARY: ${CMAKE_MSVC_RUNTIME_LIBRARY} in ${EGOA_BUILD_TYPE}" )

####################################################################
# Input Parameter ##################################################
####################################################################
Expand Down Expand Up @@ -121,13 +134,15 @@ endif ( EGOA_ENABLE_BOOST )
# Google tests
if ( EGOA_ENABLE_TESTS )
include ( CTest )
if ( EGOA_TEST_FRAMEWORK STREQUAL "OfflineGoogleTestFramework" )
find_package ( GoogleTestFramework PATHS ${EGOA_TEST_FRAMEWORK_LOCATION})
elseif ( EGOA_TEST_FRAMEWORK STREQUAL "OnlineGoogleTestFramework" )
find_package ( GoogleTestFrameworkOnlineVersion )
else ()
find_package ( GoogleTestFramework )
endif ()
franziska-wegner marked this conversation as resolved.
Show resolved Hide resolved
# Temp for all, maybe only Windows and MacOS
include(FindGoogleTestFramework)
# if ( EGOA_TEST_FRAMEWORK STREQUAL "OfflineGoogleTestFramework" )
# find_package ( GoogleTestFramework PATHS ${EGOA_TEST_FRAMEWORK_LOCATION})
# elseif ( EGOA_TEST_FRAMEWORK STREQUAL "OnlineGoogleTestFramework" )
# find_package ( GoogleTestFrameworkOnlineVersion )
# else ()
# find_package ( GoogleTestFramework )
# endif ()

# Add test coverage
# -coverage includes -fprofile-arcs -ftest-coverage while compiling and
Expand Down
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

# Now simply link against gtest or gtest_main as needed
# add_executable(TestBound DataStructures/TestBound.cpp)
# target_link_libraries(TestBound gtest gtest_main gmock_main EGOA ${GUROBI_LIBRARIES})
# add_test(NAME TestBound COMMAND TestBound)
add_executable(TestBound DataStructures/TestBound.cpp)
target_link_libraries(TestBound EGOA gtest gtest_main gmock_main) #${GUROBI_LIBRARIES}
add_test(NAME TestBound COMMAND TestBound)

####################################################################################
# Tests for QUEUE data structures ##################################################
Expand Down
74 changes: 74 additions & 0 deletions tests/DataStructures/TestBound.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* TestBound.cpp
*
* Created on: Jan 28, 2019
* Author: Franziska Wegner
*/

#include "TestBound.hpp"

#include "DataStructures/Bound.hpp"

#include "Helper/TestHelper.hpp"

// using ::testing::Eq;
// using ::testing::ByRef;
using ::testing::Ge;
using ::testing::Le;

namespace egoa::test {

TestBound::TestBound () {}

TestBound::~TestBound () {}

void TestBound::SetUp () {}

void TestBound::TearDown () {}

TEST_F ( TestBound, MinPositiveNos ) {
egoa::Bound<> bound(2.1, 2.5);

EXPECT_DOUBLE_EQ (2.1, bound.Minimum());
ASSERT_THAT(bound.Minimum(), Le(bound.Maximum()));

bound.Range(2.00000001, 2.00000005);

EXPECT_DOUBLE_EQ (2.00000001, bound.Minimum());
ASSERT_THAT(bound.Minimum(), Le(bound.Maximum()));
}

TEST_F ( TestBound, MaxPositiveNos ) {
egoa::Bound<> bound(2.1, 2.5);

EXPECT_DOUBLE_EQ (2.5, bound.Maximum());
ASSERT_THAT(bound.Maximum(), Ge(bound.Minimum()));

bound.Range(2.00000001, 2.00000005);
EXPECT_DOUBLE_EQ (2.00000005, bound.Maximum());
ASSERT_THAT(bound.Maximum(), Ge(bound.Minimum()));
}

TEST_F ( TestBound, DeathTest ) {
// ASSERT_DEATH({ Bound(3, 1);}, "terminating with uncaught exception of type BoundMismatch: Minimum > maximum: 3 < 1");
#ifdef EGOA_EXCEPTION_HANDLING
try {
egoa::Bound<> bound (3,1);
FAIL() << "Expected BoundMismatch";
}
catch(egoa::BoundMismatch const & err) {
EXPECT_EQ(err.What(), std::string("Minimum > maximum: 3 < 1"));
}
catch(...) {
FAIL() << "Expected BoundMismatch2";
}
#elif EGOA_ENABLE_ASSERTION
auto assertionString = buildAssertionString ( "Bound.hpp"
, "Bound"
, "Bound"
, "minimum_ <= maximum_");
ASSERT_DEATH( {egoa::Bound<> bound (3,1);}, assertionString );
#endif
}

} // namespace egoa::test
43 changes: 43 additions & 0 deletions tests/DataStructures/TestBound.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* TestBound.hpp
*
* Created on: Jan 28, 2019
* Author: Franziska Wegner
*/

#ifndef EGOA__TESTS__DATA_STRUCTURES__BOUND_HPP
#define EGOA__TESTS__DATA_STRUCTURES__BOUND_HPP

#include "gtest/gtest.h"
#include "gmock/gmock.h"

namespace egoa::test {

/**
* @brief Fixture for testing class Bound
*/
class TestBound : public ::testing::Test {

protected:

// You can do set-up work for each test here.
TestBound();

// You can do clean-up work that doesn't throw exceptions here.
virtual ~TestBound();

// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:

// Code here will be called immediately after the constructor (right
// before each test).
virtual void SetUp();

// Code here will be called immediately after each test (right
// before the destructor).
virtual void TearDown();
};

} // namespace egoa::test

#endif // EGOA__TESTS__DATA_STRUCTURES__BOUND_HPP
8 changes: 4 additions & 4 deletions tests/Helper/TestHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ Types::string buildAssertionString ( Types::string fileName
{
std::stringstream result;
#ifdef EGOA_ENABLE_ASSERTION
result << "(.*) assertion failed at (.*)"
result << ".* assertion failed at .*"
<< fileName
<< ":(.*) inside "
<< ":.* inside .*"
<< function
<< ".\n Condition: "
<< message
<< "";
#else // ifdef EGOA_ENABLE_ASSERTION
#ifdef EGOA_ENABLE_EXCEPTION_HANDLING
result << "(.*) exception at (.*)"
result << ".* exception at .*"
<< fileName
<< ":(.*) inside "
<< ":.* inside .*"
franziska-wegner marked this conversation as resolved.
Show resolved Hide resolved
<< function
<< ".\n Condition: "
<< message
Expand Down