mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[commands] Add unless() decorator (#4244)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <frc/simulation/SimHooks.h>
|
||||
|
||||
#include "CommandTestBase.h"
|
||||
#include "frc2/command/ConditionalCommand.h"
|
||||
#include "frc2/command/InstantCommand.h"
|
||||
#include "frc2/command/ParallelRaceGroup.h"
|
||||
#include "frc2/command/PerpetualCommand.h"
|
||||
@@ -101,3 +102,24 @@ TEST_F(CommandDecoratorTest, Perpetually) {
|
||||
|
||||
EXPECT_TRUE(scheduler.IsScheduled(&command));
|
||||
}
|
||||
|
||||
TEST_F(CommandDecoratorTest, Unless) {
|
||||
CommandScheduler scheduler = GetScheduler();
|
||||
|
||||
bool hasRun = false;
|
||||
bool unlessBool = true;
|
||||
|
||||
auto command =
|
||||
InstantCommand([&hasRun] { hasRun = true; }, {}).Unless([&unlessBool] {
|
||||
return unlessBool;
|
||||
});
|
||||
|
||||
scheduler.Schedule(&command);
|
||||
scheduler.Run();
|
||||
EXPECT_FALSE(hasRun);
|
||||
|
||||
unlessBool = false;
|
||||
scheduler.Schedule(&command);
|
||||
scheduler.Run();
|
||||
EXPECT_TRUE(hasRun);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user