Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 0 additions & 26 deletions .github/workflows/CMakeLists.txt

This file was deleted.

12 changes: 4 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)


25 changes: 22 additions & 3 deletions tests/unit_tests/spline_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>

#include "../include/SplineNetLib/layers.hpp"

Expand All @@ -22,7 +22,7 @@ TEST_CASE("spline initialization using constructor method functions as expected"
}

TEST_CASE("spline interpolation functions as expected") {
std::vector<std::vector<double>> 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<std::vector<double>> 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<std::vector<double>> correct_parameters(5, std::vector<double>(4, 0.0));

spline Test_spline(correct_points, correct_parameters);
Expand Down Expand Up @@ -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<std::vector<double>> 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<std::vector<double>> parameters(5, std::vector<double>(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));
}