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

feat: switch to gtest

parent 23a2382d
No related branches found
No related tags found
No related merge requests found
......@@ -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
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment