[commands] Add property tests for command compositions (#4715)

This commit is contained in:
Starlight220
2022-11-28 02:23:56 +02:00
committed by GitHub
parent e4ac09077c
commit 8958b2a4da
31 changed files with 579 additions and 59 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}