mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[commands] Add property tests for command compositions (#4715)
This commit is contained in:
@@ -84,11 +84,15 @@ class ParallelCommandGroup
|
||||
|
||||
bool RunsWhenDisabled() const override;
|
||||
|
||||
Command::InterruptionBehavior GetInterruptionBehavior() const override;
|
||||
|
||||
private:
|
||||
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
|
||||
|
||||
std::vector<std::pair<std::unique_ptr<Command>, bool>> m_commands;
|
||||
bool m_runWhenDisabled{true};
|
||||
Command::InterruptionBehavior m_interruptBehavior{
|
||||
Command::InterruptionBehavior::kCancelIncoming};
|
||||
bool isRunning = false;
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
@@ -92,6 +92,8 @@ class ParallelDeadlineGroup
|
||||
|
||||
bool RunsWhenDisabled() const override;
|
||||
|
||||
Command::InterruptionBehavior GetInterruptionBehavior() const override;
|
||||
|
||||
private:
|
||||
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
|
||||
|
||||
@@ -100,6 +102,8 @@ class ParallelDeadlineGroup
|
||||
std::vector<std::pair<std::unique_ptr<Command>, bool>> m_commands;
|
||||
Command* m_deadline;
|
||||
bool m_runWhenDisabled{true};
|
||||
Command::InterruptionBehavior m_interruptBehavior{
|
||||
Command::InterruptionBehavior::kCancelIncoming};
|
||||
bool m_finished{true};
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
@@ -72,11 +72,15 @@ class ParallelRaceGroup
|
||||
|
||||
bool RunsWhenDisabled() const override;
|
||||
|
||||
Command::InterruptionBehavior GetInterruptionBehavior() const override;
|
||||
|
||||
private:
|
||||
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
|
||||
|
||||
std::vector<std::unique_ptr<Command>> m_commands;
|
||||
bool m_runWhenDisabled{true};
|
||||
Command::InterruptionBehavior m_interruptBehavior{
|
||||
Command::InterruptionBehavior::kCancelIncoming};
|
||||
bool m_finished{false};
|
||||
bool isRunning = false;
|
||||
};
|
||||
|
||||
@@ -69,6 +69,10 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
|
||||
for (auto&& command : foo) {
|
||||
this->AddRequirements(command.second->GetRequirements());
|
||||
m_runsWhenDisabled &= command.second->RunsWhenDisabled();
|
||||
if (command.second->GetInterruptionBehavior() ==
|
||||
Command::InterruptionBehavior::kCancelSelf) {
|
||||
m_interruptBehavior = Command::InterruptionBehavior::kCancelSelf;
|
||||
}
|
||||
m_commands.emplace(std::move(command.first), std::move(command.second));
|
||||
}
|
||||
}
|
||||
@@ -86,6 +90,10 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
|
||||
for (auto&& command : commands) {
|
||||
this->AddRequirements(command.second->GetRequirements());
|
||||
m_runsWhenDisabled &= command.second->RunsWhenDisabled();
|
||||
if (command.second->GetInterruptionBehavior() ==
|
||||
Command::InterruptionBehavior::kCancelSelf) {
|
||||
m_interruptBehavior = Command::InterruptionBehavior::kCancelSelf;
|
||||
}
|
||||
m_commands.emplace(std::move(command.first), std::move(command.second));
|
||||
}
|
||||
}
|
||||
@@ -118,6 +126,10 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
|
||||
|
||||
bool RunsWhenDisabled() const override { return m_runsWhenDisabled; }
|
||||
|
||||
Command::InterruptionBehavior GetInterruptionBehavior() const override {
|
||||
return m_interruptBehavior;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<Command> TransferOwnership() && override {
|
||||
return std::make_unique<SelectCommand>(std::move(*this));
|
||||
@@ -129,6 +141,8 @@ class SelectCommand : public CommandHelper<CommandBase, SelectCommand<Key>> {
|
||||
std::function<Command*()> m_toRun;
|
||||
Command* m_selectedCommand;
|
||||
bool m_runsWhenDisabled = true;
|
||||
Command::InterruptionBehavior m_interruptBehavior{
|
||||
Command::InterruptionBehavior::kCancelIncoming};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -87,12 +87,16 @@ class SequentialCommandGroup
|
||||
|
||||
bool RunsWhenDisabled() const override;
|
||||
|
||||
Command::InterruptionBehavior GetInterruptionBehavior() const override;
|
||||
|
||||
private:
|
||||
void AddCommands(std::vector<std::unique_ptr<Command>>&& commands) final;
|
||||
|
||||
wpi::SmallVector<std::unique_ptr<Command>, 4> m_commands;
|
||||
size_t m_currentCommandIndex{invalid_index};
|
||||
bool m_runWhenDisabled{true};
|
||||
Command::InterruptionBehavior m_interruptBehavior{
|
||||
Command::InterruptionBehavior::kCancelIncoming};
|
||||
};
|
||||
} // namespace frc2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user