diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/TriggerTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/TriggerTest.java index 87f8d163c93..8cd5fdea2f1 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/TriggerTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/button/TriggerTest.java @@ -62,6 +62,32 @@ void onFalseTest() { assertFalse(command1.isScheduled()); } + @Test + void onChangeTest() { + CommandScheduler scheduler = CommandScheduler.getInstance(); + AtomicBoolean finished = new AtomicBoolean(false); + Command command1 = new WaitUntilCommand(finished::get); + + InternalButton button = new InternalButton(); + button.setPressed(true); + button.onChange(command1); + scheduler.run(); + assertFalse(command1.isScheduled()); + button.setPressed(false); + scheduler.run(); + assertTrue(command1.isScheduled()); + finished.set(true); + scheduler.run(); + assertFalse(command1.isScheduled()); + finished.set(false); + button.setPressed(true); + scheduler.run(); + assertTrue(command1.isScheduled()); + finished.set(true); + scheduler.run(); + assertFalse(command1.isScheduled()); + } + @Test void whileTrueRepeatedlyTest() { CommandScheduler scheduler = CommandScheduler.getInstance(); diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/button/TriggerTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/button/TriggerTest.cpp index 4acaa662088..a97b4f566c3 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/button/TriggerTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/button/TriggerTest.cpp @@ -52,6 +52,30 @@ TEST_F(TriggerTest, OnFalse) { EXPECT_FALSE(scheduler.IsScheduled(&command)); } +TEST_F(TriggerTest, OnChange) { + auto& scheduler = CommandScheduler::GetInstance(); + bool finished = false; + bool pressed = true; + WaitUntilCommand command([&finished] { return finished; }); + + Trigger([&pressed] { return pressed; }).OnChange(&command); + scheduler.Run(); + EXPECT_FALSE(command.IsScheduled()); + pressed = false; + scheduler.Run(); + EXPECT_TRUE(command.IsScheduled()); + finished = true; + scheduler.Run(); + EXPECT_FALSE(command.IsScheduled()); + finished = false; + pressed = true; + scheduler.Run(); + EXPECT_TRUE(command.IsScheduled()); + finished = true; + scheduler.Run(); + EXPECT_FALSE(command.IsScheduled()); +} + TEST_F(TriggerTest, WhileTrueRepeatedly) { auto& scheduler = CommandScheduler::GetInstance(); int inits = 0;