Skip to content

Commit 5acb410

Browse files
[examples] Fix flaky ArmSimulationTest (#7170)
Co-authored-by: Starlight220 <[email protected]>
1 parent fc83d48 commit 5acb410

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

wpilibcExamples/src/test/cpp/examples/ArmSimulation/cpp/ArmSimulationTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class ArmSimulationTest : public testing::TestWithParam<units::degree_t> {
5050
TEST_P(ArmSimulationTest, Teleop) {
5151
EXPECT_TRUE(frc::Preferences::ContainsKey(kArmPositionKey));
5252
EXPECT_TRUE(frc::Preferences::ContainsKey(kArmPKey));
53-
EXPECT_DOUBLE_EQ(kDefaultArmSetpoint.value(),
54-
frc::Preferences::GetDouble(kArmPositionKey, NAN));
55-
5653
frc::Preferences::SetDouble(kArmPositionKey, GetParam().value());
5754
units::degree_t setpoint = GetParam();
55+
EXPECT_DOUBLE_EQ(setpoint.value(),
56+
frc::Preferences::GetDouble(kArmPositionKey, NAN));
57+
5858
// teleop init
5959
{
6060
frc::sim::DriverStationSim::SetAutonomous(false);
@@ -68,7 +68,7 @@ TEST_P(ArmSimulationTest, Teleop) {
6868
{
6969
frc::sim::StepTiming(3_s);
7070

71-
// Ensure elevator is still at 0.
71+
// Ensure arm is still at minimum angle.
7272
EXPECT_NEAR(kMinAngle.value(), m_encoderSim.GetDistance(), 2.0);
7373
}
7474

wpilibjExamples/src/test/java/edu/wpi/first/wpilibj/examples/armsimulation/ArmSimulationTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ void stopThread() {
7171
void teleopTest(double setpoint) {
7272
assertTrue(Preferences.containsKey(Constants.kArmPositionKey));
7373
assertTrue(Preferences.containsKey(Constants.kArmPKey));
74-
assertEquals(
75-
Constants.kDefaultArmSetpointDegrees,
76-
Preferences.getDouble(Constants.kArmPositionKey, Double.NaN));
77-
7874
Preferences.setDouble(Constants.kArmPositionKey, setpoint);
75+
assertEquals(setpoint, Preferences.getDouble(Constants.kArmPositionKey, Double.NaN));
7976
// teleop init
8077
{
8178
DriverStationSim.setAutonomous(false);
@@ -87,10 +84,10 @@ void teleopTest(double setpoint) {
8784
}
8885

8986
{
90-
// advance 50 timesteps
87+
// advance 150 timesteps
9188
SimHooks.stepTiming(3);
9289

93-
// Ensure elevator is still at 0.
90+
// Ensure arm is still at minimum angle.
9491
assertEquals(Constants.kMinAngleRads, m_encoderSim.getDistance(), 2.0);
9592
}
9693

@@ -115,7 +112,7 @@ void teleopTest(double setpoint) {
115112
m_joystickSim.setTrigger(false);
116113
m_joystickSim.notifyNewData();
117114

118-
// advance 75 timesteps
115+
// advance 150 timesteps
119116
SimHooks.stepTiming(3.0);
120117

121118
assertEquals(Constants.kMinAngleRads, m_encoderSim.getDistance(), 2.0);

0 commit comments

Comments
 (0)