mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 03:33:34 +08:00
Unit tests: use EXPECT_FLOAT_EQ for float comparisons
as precaution to prevent failing tests because of small potential rounding errors on certain platforms or compilares.
This commit is contained in:
committed by
Lorenz Meier
parent
ee62d0296f
commit
ffff35a597
@@ -313,7 +313,7 @@ TEST_F(CollisionPreventionTest, testPurgeOldData)
|
||||
if (i < 6) {
|
||||
// THEN: If the data is new enough, the velocity setpoint should stay the same as the input
|
||||
// Note: direction will change slightly due to guidance
|
||||
EXPECT_EQ(original_setpoint.norm(), modified_setpoint.norm());
|
||||
EXPECT_FLOAT_EQ(original_setpoint.norm(), modified_setpoint.norm());
|
||||
|
||||
} else {
|
||||
// THEN: If the data is expired, the velocity setpoint should be cut down to zero because there is no data
|
||||
@@ -381,7 +381,7 @@ TEST_F(CollisionPreventionTest, testNoRangeData)
|
||||
if (i < 5) {
|
||||
// THEN: If the data is new enough, the velocity setpoint should stay the same as the input
|
||||
// Note: direction will change slightly due to guidance
|
||||
EXPECT_EQ(original_setpoint.norm(), modified_setpoint.norm());
|
||||
EXPECT_FLOAT_EQ(original_setpoint.norm(), modified_setpoint.norm());
|
||||
|
||||
} else {
|
||||
// THEN: If the data is expired, the velocity setpoint should be cut down to zero because there is no data
|
||||
@@ -1008,8 +1008,8 @@ TEST_F(CollisionPreventionTest, adaptSetpointDirection_flat_minimum)
|
||||
|
||||
//THEN: the setpoint direction should be modified correctly
|
||||
EXPECT_EQ(sp_index, 2);
|
||||
EXPECT_FLOAT_EQ(setpoint_dir(0), 0.93969262);
|
||||
EXPECT_FLOAT_EQ(setpoint_dir(1), 0.34202012);
|
||||
EXPECT_FLOAT_EQ(setpoint_dir(0), 0.93969262f);
|
||||
EXPECT_FLOAT_EQ(setpoint_dir(1), 0.34202012f);
|
||||
}
|
||||
|
||||
TEST_F(CollisionPreventionTest, overlappingSensors)
|
||||
|
||||
@@ -58,9 +58,9 @@ TEST_F(ManualVelocitySmoothingXYTest, setGet)
|
||||
_smoothing.setMaxVel(5.f);
|
||||
|
||||
// THEN: We should be able to get them back
|
||||
EXPECT_EQ(_smoothing.getMaxJerk(), 11.f);
|
||||
EXPECT_EQ(_smoothing.getMaxAccel(), 7.f);
|
||||
EXPECT_EQ(_smoothing.getMaxVel(), 5.f);
|
||||
EXPECT_FLOAT_EQ(_smoothing.getMaxJerk(), 11.f);
|
||||
EXPECT_FLOAT_EQ(_smoothing.getMaxAccel(), 7.f);
|
||||
EXPECT_FLOAT_EQ(_smoothing.getMaxVel(), 5.f);
|
||||
}
|
||||
|
||||
TEST_F(ManualVelocitySmoothingXYTest, getCurrentState)
|
||||
|
||||
@@ -172,9 +172,9 @@ TEST_F(VelocitySmoothingTest, testZeroSetpoint)
|
||||
|
||||
// THEN: All the trajectories should still be zero
|
||||
for (int i = 0; i < 3; i++) {
|
||||
EXPECT_EQ(_trajectories[i].getCurrentJerk(), 0.f);
|
||||
EXPECT_EQ(_trajectories[i].getCurrentAcceleration(), 0.f);
|
||||
EXPECT_EQ(_trajectories[i].getCurrentVelocity(), 0.f);
|
||||
EXPECT_EQ(_trajectories[i].getCurrentPosition(), 0.f);
|
||||
EXPECT_FLOAT_EQ(_trajectories[i].getCurrentJerk(), 0.f);
|
||||
EXPECT_FLOAT_EQ(_trajectories[i].getCurrentAcceleration(), 0.f);
|
||||
EXPECT_FLOAT_EQ(_trajectories[i].getCurrentVelocity(), 0.f);
|
||||
EXPECT_FLOAT_EQ(_trajectories[i].getCurrentPosition(), 0.f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ TEST_F(ParameterTest, testParamReadWrite)
|
||||
|
||||
// THEN it should be successful and have the default value
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_EQ(-1, value);
|
||||
EXPECT_FLOAT_EQ(-1.f, value);
|
||||
|
||||
// WHEN: we set the parameter
|
||||
value = 42.f;
|
||||
@@ -74,7 +74,7 @@ TEST_F(ParameterTest, testParamReadWrite)
|
||||
|
||||
// THEN: it should be exactly the value we set
|
||||
EXPECT_EQ(0, status);
|
||||
EXPECT_EQ(42.f, value2);
|
||||
EXPECT_FLOAT_EQ(42.f, value2);
|
||||
}
|
||||
|
||||
|
||||
@@ -99,8 +99,8 @@ TEST_F(ParameterTest, testUorbSendReceive)
|
||||
|
||||
// AND: the values we got should be the same
|
||||
EXPECT_EQ(message.timestamp, obstacle_distance.timestamp);
|
||||
EXPECT_EQ(message.min_distance, obstacle_distance.min_distance);
|
||||
EXPECT_EQ(message.max_distance, obstacle_distance.max_distance);
|
||||
EXPECT_FLOAT_EQ(message.min_distance, obstacle_distance.min_distance);
|
||||
EXPECT_FLOAT_EQ(message.max_distance, obstacle_distance.max_distance);
|
||||
|
||||
// AND: all the bytes should be equal
|
||||
EXPECT_EQ(0, memcmp(&message, &obstacle_distance, sizeof(message)));
|
||||
|
||||
Reference in New Issue
Block a user