Improved testing setup

This commit is contained in:
Pascal Serrarens 2024-01-16 17:10:51 +01:00
parent ea4f4fdb19
commit 723c5a1cd7
3 changed files with 48 additions and 25 deletions

View File

@ -19,7 +19,7 @@ endif()
project(RoboidControl) project(RoboidControl)
add_subdirectory(VectorAlgebra) add_subdirectory(VectorAlgebra)
#add_subdirectory(test) add_subdirectory(test)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@ -56,16 +56,16 @@ add_library(RoboidControl STATIC
enable_testing() enable_testing()
add_executable( # add_executable(
RoboidControlTest # RoboidControlTest
"test/BB2B_Test.cc" # "test/BB2B_Test.cc"
) # )
target_link_libraries( # target_link_libraries(
RoboidControlTest # RoboidControlTest
gtest_main # gtest_main
RoboidControl # RoboidControl
VectorAlgebra # VectorAlgebra
) # )
include(GoogleTest) include(GoogleTest)
gtest_discover_tests(RoboidControlTest) # gtest_discover_tests(RoboidControlTest)

View File

@ -1,9 +1,10 @@
// #if GTEST // #if GTEST
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "DifferentialDrive.h" #include "../DifferentialDrive.h"
#include "DistanceSensor.h" #include "../DistanceSensor.h"
#include "Roboid.h" #include "../Roboid.h"
#include "../VectorAlgebra/Angle.h"
TEST(BB2B, Basics) { TEST(BB2B, Basics) {
Motor *motorLeft = new Motor(); Motor *motorLeft = new Motor();
@ -19,6 +20,9 @@ TEST(BB2B, Basics) {
Perception *perception = new Perception(sensors, 2); Perception *perception = new Perception(sensors, 2);
DifferentialDrive *propulsion = new DifferentialDrive(motorLeft, motorRight); DifferentialDrive *propulsion = new DifferentialDrive(motorLeft, motorRight);
propulsion->SetDimensions(
1 / Angle::pi, // we use this, such that motor speed 1 -> velocity 1 m/s
1);
Roboid *roboid = new Roboid(perception, propulsion); Roboid *roboid = new Roboid(perception, propulsion);
@ -31,9 +35,21 @@ TEST(BB2B, Basics) {
float leftMotorSpeed = obstacleRight ? -1.0F : 1.0F; float leftMotorSpeed = obstacleRight ? -1.0F : 1.0F;
float rightMotorSpeed = obstacleLeft ? -1.0F : 1.0F; float rightMotorSpeed = obstacleLeft ? -1.0F : 1.0F;
EXPECT_FLOAT_EQ(leftMotorSpeed, 1.0F);
EXPECT_FLOAT_EQ(rightMotorSpeed, 1.0F);
DifferentialDrive *diffDrive = (DifferentialDrive *)roboid->propulsion; DifferentialDrive *diffDrive = (DifferentialDrive *)roboid->propulsion;
diffDrive->SetMotorTargetSpeeds(leftMotorSpeed, rightMotorSpeed); diffDrive->SetMotorTargetSpeeds(leftMotorSpeed, rightMotorSpeed);
// cannot chek verlocity in this branch? float leftActualSpeed = motorLeft->GetActualSpeed();
float rightActualSpeed = motorRight->GetActualSpeed();
EXPECT_FLOAT_EQ(leftActualSpeed, 1.0F);
EXPECT_FLOAT_EQ(rightActualSpeed, 1.0F);
Polar velocity =
diffDrive->GetVelocity(); // this depends on the wheel diameter.
EXPECT_FLOAT_EQ(velocity.distance, 1.0F);
EXPECT_FLOAT_EQ(velocity.angle, 0.0F);
} }
// #endif // #endif

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.13) # CMake version check cmake_minimum_required(VERSION 3.13) # CMake version check
Project(test) Project(RoboidControlTestNew)
set(CMAKE_CXX_STANDARD 11) # Enable c++11 standard set(CMAKE_CXX_STANDARD 11) # Enable c++11 standard
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@ -14,17 +14,24 @@ FetchContent_Declare(
# For Windows: Prevent overriding the parent project's compiler/linker settings # For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest) FetchContent_MakeAvailable(googletest)
include_directories(include)
include_directories(
.
..
)
enable_testing() enable_testing()
add_executable( add_executable(
VectorAlgebraTest RoboidControlTestNew
"test/Angle_test.cc" "BB2B_test.cc"
"test/FloatSingle_test.cc" )
"test/Vector2_test.cc"
"test/Vector3_test.cc" target_link_libraries(
"test/Quaternion_test.cc" RoboidControlTestNew
gtest_main
RoboidControl
VectorAlgebra
) )
include(GoogleTest) include(GoogleTest)
gtest_discover_tests(RoboidControlTestNew)