mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[commands] Add property tests for command compositions (#4715)
This commit is contained in:
@@ -19,6 +19,7 @@ public class ParallelCommandGroup extends CommandGroupBase {
|
||||
// maps commands in this group to whether they are still running
|
||||
private final Map<Command, Boolean> m_commands = new HashMap<>();
|
||||
private boolean m_runWhenDisabled = true;
|
||||
private InterruptionBehavior m_interruptBehavior = InterruptionBehavior.kCancelIncoming;
|
||||
|
||||
/**
|
||||
* Creates a new ParallelCommandGroup. The given commands will be executed simultaneously. The
|
||||
@@ -50,6 +51,9 @@ public class ParallelCommandGroup extends CommandGroupBase {
|
||||
m_commands.put(command, false);
|
||||
m_requirements.addAll(command.getRequirements());
|
||||
m_runWhenDisabled &= command.runsWhenDisabled();
|
||||
if (command.getInterruptionBehavior() == InterruptionBehavior.kCancelSelf) {
|
||||
m_interruptBehavior = InterruptionBehavior.kCancelSelf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,4 +99,9 @@ public class ParallelCommandGroup extends CommandGroupBase {
|
||||
public boolean runsWhenDisabled() {
|
||||
return m_runWhenDisabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterruptionBehavior getInterruptionBehavior() {
|
||||
return m_interruptBehavior;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public class ParallelDeadlineGroup extends CommandGroupBase {
|
||||
private boolean m_runWhenDisabled = true;
|
||||
private boolean m_finished = true;
|
||||
private Command m_deadline;
|
||||
private InterruptionBehavior m_interruptBehavior = InterruptionBehavior.kCancelIncoming;
|
||||
|
||||
/**
|
||||
* Creates a new ParallelDeadlineGroup. The given commands (including the deadline) will be
|
||||
@@ -72,6 +73,9 @@ public class ParallelDeadlineGroup extends CommandGroupBase {
|
||||
m_commands.put(command, false);
|
||||
m_requirements.addAll(command.getRequirements());
|
||||
m_runWhenDisabled &= command.runsWhenDisabled();
|
||||
if (command.getInterruptionBehavior() == InterruptionBehavior.kCancelSelf) {
|
||||
m_interruptBehavior = InterruptionBehavior.kCancelSelf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,4 +123,9 @@ public class ParallelDeadlineGroup extends CommandGroupBase {
|
||||
public boolean runsWhenDisabled() {
|
||||
return m_runWhenDisabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterruptionBehavior getInterruptionBehavior() {
|
||||
return m_interruptBehavior;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public class ParallelRaceGroup extends CommandGroupBase {
|
||||
private final Set<Command> m_commands = new HashSet<>();
|
||||
private boolean m_runWhenDisabled = true;
|
||||
private boolean m_finished = true;
|
||||
private InterruptionBehavior m_interruptBehavior = InterruptionBehavior.kCancelIncoming;
|
||||
|
||||
/**
|
||||
* Creates a new ParallelCommandRace. The given commands will be executed simultaneously, and will
|
||||
@@ -51,6 +52,9 @@ public class ParallelRaceGroup extends CommandGroupBase {
|
||||
m_commands.add(command);
|
||||
m_requirements.addAll(command.getRequirements());
|
||||
m_runWhenDisabled &= command.runsWhenDisabled();
|
||||
if (command.getInterruptionBehavior() == InterruptionBehavior.kCancelSelf) {
|
||||
m_interruptBehavior = InterruptionBehavior.kCancelSelf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,4 +92,9 @@ public class ParallelRaceGroup extends CommandGroupBase {
|
||||
public boolean runsWhenDisabled() {
|
||||
return m_runWhenDisabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterruptionBehavior getInterruptionBehavior() {
|
||||
return m_interruptBehavior;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ public class SelectCommand extends CommandBase {
|
||||
private final Supplier<Object> m_selector;
|
||||
private final Supplier<Command> m_toRun;
|
||||
private Command m_selectedCommand;
|
||||
private boolean m_runsWhenDisabled = true;
|
||||
private InterruptionBehavior m_interruptBehavior = InterruptionBehavior.kCancelIncoming;
|
||||
|
||||
/**
|
||||
* Creates a new selectcommand.
|
||||
@@ -50,6 +52,10 @@ public class SelectCommand extends CommandBase {
|
||||
|
||||
for (Command command : m_commands.values()) {
|
||||
m_requirements.addAll(command.getRequirements());
|
||||
m_runsWhenDisabled &= command.runsWhenDisabled();
|
||||
if (command.getInterruptionBehavior() == InterruptionBehavior.kCancelSelf) {
|
||||
m_interruptBehavior = InterruptionBehavior.kCancelSelf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +68,10 @@ public class SelectCommand extends CommandBase {
|
||||
m_commands = null;
|
||||
m_selector = null;
|
||||
m_toRun = requireNonNullParam(toRun, "toRun", "SelectCommand");
|
||||
|
||||
// we have no way of checking the underlying command, so default.
|
||||
m_runsWhenDisabled = false;
|
||||
m_interruptBehavior = InterruptionBehavior.kCancelSelf;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,14 +107,11 @@ public class SelectCommand extends CommandBase {
|
||||
|
||||
@Override
|
||||
public boolean runsWhenDisabled() {
|
||||
if (m_commands != null) {
|
||||
boolean runsWhenDisabled = true;
|
||||
for (Command command : m_commands.values()) {
|
||||
runsWhenDisabled &= command.runsWhenDisabled();
|
||||
}
|
||||
return runsWhenDisabled;
|
||||
} else {
|
||||
return m_toRun.get().runsWhenDisabled();
|
||||
}
|
||||
return m_runsWhenDisabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterruptionBehavior getInterruptionBehavior() {
|
||||
return m_interruptBehavior;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class SequentialCommandGroup extends CommandGroupBase {
|
||||
private final List<Command> m_commands = new ArrayList<>();
|
||||
private int m_currentCommandIndex = -1;
|
||||
private boolean m_runWhenDisabled = true;
|
||||
private InterruptionBehavior m_interruptBehavior = InterruptionBehavior.kCancelIncoming;
|
||||
|
||||
/**
|
||||
* Creates a new SequentialCommandGroup. The given commands will be run sequentially, with the
|
||||
@@ -44,6 +45,9 @@ public class SequentialCommandGroup extends CommandGroupBase {
|
||||
m_commands.add(command);
|
||||
m_requirements.addAll(command.getRequirements());
|
||||
m_runWhenDisabled &= command.runsWhenDisabled();
|
||||
if (command.getInterruptionBehavior() == InterruptionBehavior.kCancelSelf) {
|
||||
m_interruptBehavior = InterruptionBehavior.kCancelSelf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,4 +98,9 @@ public class SequentialCommandGroup extends CommandGroupBase {
|
||||
public boolean runsWhenDisabled() {
|
||||
return m_runWhenDisabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterruptionBehavior getInterruptionBehavior() {
|
||||
return m_interruptBehavior;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user