diff --git a/.github/workflows/CMakeLists.txt b/.github/workflows/CMakeLists.txt deleted file mode 100644 index e8f2b18..0000000 --- a/.github/workflows/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -# CMakeLists.txt for Tests - -#Add more test files like this -#set(TEST_SOURCES -# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/network_tests.cpp -# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/other_tests.cpp -#) - -# Set the source files for the tests in a variable (you can easily add more test files here later) -set(TEST_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/network_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/spline_tests.cpp -) - -# Add an executable for the tests (it will compile all the test sources) -add_executable(SplineNetLibTests ${TEST_SOURCES}) - -# Link the executable to your main library -target_link_libraries(SplineNetLibTests PRIVATE SplineNetLib) - -# Enable testing -include(CTest) -enable_testing() - -# Add the test to CTest -add_test(NAME SplineNetLibTests COMMAND SplineNetLibTests) \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 09d72d7..0ca428e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,17 +17,13 @@ jobs: runs-on: ubuntu-latest # Use the latest Ubuntu virtual environment steps: - # Step 1: Checkout the repository - - name: Checkout repository - uses: actions/checkout@v3 - - # Step 2: Install CMake and dependencies - - name: Install CMake and g++ + - uses: actions/checkout@v3 + + - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y cmake g++ # Ensure CMake and g++ are installed + sudo apt-get install -y cmake build-essential g++ - # Step 3: Build and run tests - name: Build and run tests run: | mkdir build diff --git a/CMakeLists.txt b/CMakeLists.txt index e7d3a6c..39fbdc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,17 @@ project(SplineNetLib VERSION 1.0) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) +#include fetch content for catch2 +include(FetchContent) + +# fetch catch2 and make usable +FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.4.0 +) +FetchContent_MakeAvailable(Catch2) + # Optionally enable warnings for all compilers if(MSVC) add_compile_options(/W4) @@ -27,6 +38,25 @@ add_library(SplineNetLib # Specify the include directories for the library target target_include_directories(SplineNetLib PUBLIC ${PROJECT_SOURCE_DIR}/include) +#enable testing +enable_testing() + +#Add test exe +add_executable(SplineNetTests + tests/unit_tests/spline_tests.cpp +) + +#link test exe with library +target_link_libraries(SplineNetTests PRIVATE + SplineNetLib + Catch2::Catch2WithMain +) + +list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) +include(Catch) +catch_discover_tests(SplineNetTests) + + # Add an example or test executable (optional) add_executable(SplineNetExample examples/example_network.cpp) @@ -49,3 +79,5 @@ write_basic_package_version_file( # Install the package configuration file install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SplineNetLibConfigVersion.cmake" DESTINATION lib/cmake/SplineNetLib) + + diff --git a/tests/unit_tests/spline_tests.cpp b/tests/unit_tests/spline_tests.cpp index 983e40a..1be708a 100644 --- a/tests/unit_tests/spline_tests.cpp +++ b/tests/unit_tests/spline_tests.cpp @@ -1,5 +1,5 @@ -#define CATCH_CONFIG_MAIN -#include "catch2/catch.hpp" +#include +#include #include "../include/SplineNetLib/layers.hpp" @@ -22,7 +22,7 @@ TEST_CASE("spline initialization using constructor method functions as expected" } TEST_CASE("spline interpolation functions as expected") { - std::vector> correct_points = {{0.0, 0.0}, {0.2, 1.0}, {0.4, 2.5}, {0.6, 2.0}, {0.8, 2.0}, {1.0, 0.5}}; + std::vector> correct_points = {{0.0, 0.0}, {0.2, 0.0}, {0.4, 0.0}, {0.6, 0.0}, {0.8, 0.0}, {1.0, 0.0}}; std::vector> correct_parameters(5, std::vector(4, 0.0)); spline Test_spline(correct_points, correct_parameters); @@ -77,3 +77,22 @@ TEST_CASE("spline interpolation functions as expected") { REQUIRE(spline_parameters == correct_parameters); } +TEST_CASE("spline sampling at x functions as expected"){ + std::vector> points = {{0.0,0.0},{0.2,1.0},{0.4,2.0},{0.6,3.0},{0.8,4.0},{1.0,5.0}}; + std::vector> parameters(5, std::vector(4, 0.0)); + + spline Test_spline(points,parameters); + Test_spline.interpolation(); + double y_0_0 = Test_spline.forward(0.0); + double y_0_25 = Test_spline.forward(0.25); + double y_0_5 = Test_spline.forward(0.5); + double y_0_75 = Test_spline.forward(0.75); + double y_1_0 = Test_spline.forward(1.0); + + REQUIRE(y_0_0 == Catch::Approx(0.0)); + REQUIRE(y_0_25 == Catch::Approx(1.25)); + REQUIRE(y_0_5 == Catch::Approx(2.5)); + REQUIRE(y_0_75 == Catch::Approx(3.75)); + REQUIRE(y_1_0 == Catch::Approx(5.0)); +} +