From 5df0b30844ec9c2320092941514d91955367d9fa Mon Sep 17 00:00:00 2001 From: K-T0BIAS Date: Tue, 28 Jan 2025 13:21:04 +0100 Subject: [PATCH 1/8] more test.cpp changes --- .github/workflows/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CMakeLists.txt b/.github/workflows/CMakeLists.txt index e8f2b18..6fed46f 100644 --- a/.github/workflows/CMakeLists.txt +++ b/.github/workflows/CMakeLists.txt @@ -8,8 +8,8 @@ # 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 + ${CMAKE_CURRENT_SOURCE_DIR}tests/unit_tests/network_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}tests/unit_tests/spline_tests.cpp ) # Add an executable for the tests (it will compile all the test sources) From ab9dc75bd7b9ba2053ae8e5edf2b277fa54cdc5e Mon Sep 17 00:00:00 2001 From: K-T0BIAS Date: Tue, 28 Jan 2025 13:28:13 +0100 Subject: [PATCH 2/8] more test.cpp changes --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7d3a6c..631e29e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,3 +49,10 @@ write_basic_package_version_file( # Install the package configuration file install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SplineNetLibConfigVersion.cmake" DESTINATION lib/cmake/SplineNetLib) + +enable_testing() + +add_executable(test tests/unit_tests/spline_tests.cpp) +target_link_libraries(test SplineNetLib) + +add_test(NAME TestA COMMAND test) \ No newline at end of file From 60fd560663f0d306c49f98d49fe45a7e949675a8 Mon Sep 17 00:00:00 2001 From: K-T0BIAS Date: Tue, 28 Jan 2025 14:09:04 +0100 Subject: [PATCH 3/8] more test.cpp changes --- .github/workflows/CMakeLists.txt | 26 -------------------------- .github/workflows/test.yml | 12 ++++-------- CMakeLists.txt | 20 +++++++++++++++----- 3 files changed, 19 insertions(+), 39 deletions(-) delete mode 100644 .github/workflows/CMakeLists.txt diff --git a/.github/workflows/CMakeLists.txt b/.github/workflows/CMakeLists.txt deleted file mode 100644 index 6fed46f..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}tests/unit_tests/network_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}tests/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 631e29e..1fe2085 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,21 @@ 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) + +#add tests to ctest +add_test(NAME SplineNetTests COMMAND SplineNetTests) + + # Add an example or test executable (optional) add_executable(SplineNetExample examples/example_network.cpp) @@ -50,9 +65,4 @@ write_basic_package_version_file( # Install the package configuration file install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SplineNetLibConfigVersion.cmake" DESTINATION lib/cmake/SplineNetLib) -enable_testing() - -add_executable(test tests/unit_tests/spline_tests.cpp) -target_link_libraries(test SplineNetLib) -add_test(NAME TestA COMMAND test) \ No newline at end of file From f664c1371422cf1c2f45262b634722b9bb850248 Mon Sep 17 00:00:00 2001 From: K-T0BIAS Date: Tue, 28 Jan 2025 14:19:09 +0100 Subject: [PATCH 4/8] more test.cpp changes --- CMakeLists.txt | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fe2085..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) @@ -36,10 +47,14 @@ add_executable(SplineNetTests ) #link test exe with library -target_link_libraries(SplineNetTests PRIVATE SplineNetLib) +target_link_libraries(SplineNetTests PRIVATE + SplineNetLib + Catch2::Catch2WithMain +) -#add tests to ctest -add_test(NAME SplineNetTests COMMAND SplineNetTests) +list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) +include(Catch) +catch_discover_tests(SplineNetTests) # Add an example or test executable (optional) From 8c3be928c494a76db08f3f6b8c0b236e2db1a80a Mon Sep 17 00:00:00 2001 From: K-T0BIAS Date: Tue, 28 Jan 2025 14:25:25 +0100 Subject: [PATCH 5/8] more test.cpp changes --- tests/unit_tests/spline_tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/spline_tests.cpp b/tests/unit_tests/spline_tests.cpp index 983e40a..5badd99 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" From cb376f2a9151a47c0136a249dae9d2d706aec687 Mon Sep 17 00:00:00 2001 From: K-T0BIAS Date: Wed, 29 Jan 2025 11:57:36 +0100 Subject: [PATCH 6/8] more test.cpp changes --- tests/unit_tests/spline_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/spline_tests.cpp b/tests/unit_tests/spline_tests.cpp index 5badd99..7409501 100644 --- a/tests/unit_tests/spline_tests.cpp +++ b/tests/unit_tests/spline_tests.cpp @@ -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); From 1f300ace17772d58a71c37de3c3bb82848e0875e Mon Sep 17 00:00:00 2001 From: K-T0BIAS Date: Wed, 29 Jan 2025 12:16:02 +0100 Subject: [PATCH 7/8] more test.cpp changes --- tests/unit_tests/spline_tests.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/unit_tests/spline_tests.cpp b/tests/unit_tests/spline_tests.cpp index 7409501..0f0eaf9 100644 --- a/tests/unit_tests/spline_tests.cpp +++ b/tests/unit_tests/spline_tests.cpp @@ -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(std::vector(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)); +} + From ff3245ca5230ba8fbb661df65b23045b9234be1d Mon Sep 17 00:00:00 2001 From: K-T0BIAS Date: Wed, 29 Jan 2025 12:19:15 +0100 Subject: [PATCH 8/8] more test.cpp changes --- tests/unit_tests/spline_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/spline_tests.cpp b/tests/unit_tests/spline_tests.cpp index 0f0eaf9..1be708a 100644 --- a/tests/unit_tests/spline_tests.cpp +++ b/tests/unit_tests/spline_tests.cpp @@ -79,7 +79,7 @@ TEST_CASE("spline interpolation functions as expected") { 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(std::vector(5, std::vector(4, 0.0)); + std::vector> parameters(5, std::vector(4, 0.0)); spline Test_spline(points,parameters); Test_spline.interpolation();