diff --git a/CMakeLists.txt b/CMakeLists.txt index d24113b32541c27b804f6f639beef2bed16ad4b6..d7e7de7fb2038ccc54e559b2adbdf2efd8370ba2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,15 +14,15 @@ add_executable(Uebung0 src/main.c src/controller.c src/controller.h) -# Fetch Catch2 +# Fetch GoogleTest Include(FetchContent) FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.3.2 + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.15.2 ) -FetchContent_MakeAvailable(Catch2) - +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) # Build Tests enable_testing() @@ -32,7 +32,7 @@ add_executable(test_controller src/controller.test.cpp ) -target_link_libraries(test_controller PRIVATE Catch2::Catch2WithMain) +target_link_libraries(test_controller PRIVATE GTest::gtest_main) target_include_directories(test_controller PRIVATE src/) -add_test(test_controller ./test_controller) -set_property(TEST test_controller PROPERTY ENVIRONMENT "CTEST_OUTPUT_ON_FAILURE=1") +include(GoogleTest) +gtest_discover_tests(test_controller) \ No newline at end of file diff --git a/src/controller.test.cpp b/src/controller.test.cpp index 228c355505d93d50c34411dea367edb77440a59e..9163b03f05190fc4f66c6223abfb6ada3a814f18 100644 --- a/src/controller.test.cpp +++ b/src/controller.test.cpp @@ -1,15 +1,14 @@ -#include <catch2/catch_test_macros.hpp> +#include <gtest/gtest.h> extern "C" { #include "controller.h" } - -TEST_CASE("PI_Regler") { - REQUIRE(controller(8, 0, 500) == 16); - REQUIRE(controller(-2, 0, 500) == -4); - REQUIRE(controller(0, 2, 500) == -4); +TEST(ControllerTest, gain) { + EXPECT_EQ(controller(8, 0, 500), 16); + EXPECT_EQ(controller(-2, 0, 500), -4); + EXPECT_EQ(controller(0, 2, 500), -4); } -TEST_CASE("limits") { - REQUIRE(controller(2, 0, 2) == 2); - REQUIRE(controller(-2, 0, 2) == -2); +TEST(ControllerTest, saturation) { + EXPECT_EQ(controller(2, 0, 2), 2); + EXPECT_EQ(controller(-2, 0, 2), -2); } \ No newline at end of file