Skip to content
Snippets Groups Projects
Commit f6c638d9 authored by Stauder, Lucas's avatar Stauder, Lucas
Browse files

feat: switch to gtest

parent 23a2382d
Branches
No related tags found
No related merge requests found
...@@ -14,15 +14,15 @@ add_executable(Uebung0 src/main.c ...@@ -14,15 +14,15 @@ add_executable(Uebung0 src/main.c
src/controller.c src/controller.c
src/controller.h) src/controller.h)
# Fetch Catch2 # Fetch GoogleTest
Include(FetchContent) Include(FetchContent)
FetchContent_Declare( FetchContent_Declare(
Catch2 googletest
GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v3.3.2 GIT_TAG v1.15.2
) )
FetchContent_MakeAvailable(Catch2) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# Build Tests # Build Tests
enable_testing() enable_testing()
...@@ -32,7 +32,7 @@ add_executable(test_controller ...@@ -32,7 +32,7 @@ add_executable(test_controller
src/controller.test.cpp 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/) target_include_directories(test_controller PRIVATE src/)
add_test(test_controller ./test_controller) include(GoogleTest)
set_property(TEST test_controller PROPERTY ENVIRONMENT "CTEST_OUTPUT_ON_FAILURE=1") gtest_discover_tests(test_controller)
\ No newline at end of file
#include <catch2/catch_test_macros.hpp> #include <gtest/gtest.h>
extern "C" { extern "C" {
#include "controller.h" #include "controller.h"
} }
TEST(ControllerTest, gain) {
TEST_CASE("PI_Regler") { EXPECT_EQ(controller(8, 0, 500), 16);
REQUIRE(controller(8, 0, 500) == 16); EXPECT_EQ(controller(-2, 0, 500), -4);
REQUIRE(controller(-2, 0, 500) == -4); EXPECT_EQ(controller(0, 2, 500), -4);
REQUIRE(controller(0, 2, 500) == -4);
} }
TEST_CASE("limits") { TEST(ControllerTest, saturation) {
REQUIRE(controller(2, 0, 2) == 2); EXPECT_EQ(controller(2, 0, 2), 2);
REQUIRE(controller(-2, 0, 2) == -2); EXPECT_EQ(controller(-2, 0, 2), -2);
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment