Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Command tests use command factories and decorators. #7006

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9cf0fc7
Do CommandDecoratorTest
TheComputer314 Aug 24, 2024
2997b22
Do CommandRequirementsTest
TheComputer314 Aug 24, 2024
eb2d761
Do MultiCompositionTestBase.java
TheComputer314 Aug 25, 2024
cdd2f05
Do ConditionalCommandTest
TheComputer314 Aug 25, 2024
599556d
Do ParallelDeadlineGroupTest
TheComputer314 Aug 25, 2024
6ab83c8
Do ParallelRaceGroupTest
TheComputer314 Aug 25, 2024
25114a8
Do ProxyCommandTest
TheComputer314 Aug 25, 2024
0752376
Do ScheduleCommandTest
TheComputer314 Aug 25, 2024
b1d863a
Do SchedulerTest
TheComputer314 Aug 25, 2024
9d65c17
Do SchedulingRecursionTest
TheComputer314 Aug 25, 2024
1240dc8
Do SchedulingRecursionTest
TheComputer314 Aug 25, 2024
063ebae
Fix ParallelRaceGroupTest failing
TheComputer314 Aug 25, 2024
c44fb83
Do SelectCommandTest
TheComputer314 Aug 25, 2024
2c87960
Do SingleCompositionTestBase
TheComputer314 Aug 25, 2024
443b982
Do ScheduleCommandTest
TheComputer314 Aug 25, 2024
8088350
Formatting fixes
github-actions[bot] Aug 25, 2024
717b66f
Start work on CommandDecoratorTest
TheComputer314 Sep 14, 2024
7ff7356
Merge branch 'factories-in-command-tests' into cpp-factories-in-comma…
TheComputer314 Sep 14, 2024
497e3cc
CommandDecoratorTest done
TheComputer314 Sep 20, 2024
649b8fc
Merge branch 'main' into cpp-factories-in-command-tests
TheComputer314 Oct 27, 2024
1d115a4
Do CommandDecoratorTest
TheComputer314 Oct 27, 2024
a6898a9
Do ConditionalCommandTest
TheComputer314 Oct 27, 2024
739b76c
Formatting fixes
github-actions[bot] Oct 27, 2024
1e6a43e
Merge branch 'main' into factories-in-command-tests
TheComputer314 Oct 31, 2024
0ca7b7f
Merge branch 'main' into factories-in-command-tests
TheComputer314 Nov 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void withTimeoutTest() {
HAL.initialize(500, 0);
SimHooks.pauseTiming();
try (CommandScheduler scheduler = new CommandScheduler()) {
Command timeout = new RunCommand(() -> {}).withTimeout(0.1);
Command timeout = Commands.idle().withTimeout(0.1);

scheduler.schedule(timeout);
scheduler.run();
Expand All @@ -44,7 +44,7 @@ void untilTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicBoolean finish = new AtomicBoolean();

Command command = new RunCommand(() -> {}).until(finish::get);
Command command = Commands.idle().until(finish::get);

scheduler.schedule(command);
scheduler.run();
Expand Down Expand Up @@ -93,7 +93,7 @@ void onlyWhileTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicBoolean run = new AtomicBoolean(true);

Command command = new RunCommand(() -> {}).onlyWhile(run::get);
Command command = Commands.idle().onlyWhile(run::get);

scheduler.schedule(command);
scheduler.run();
Expand Down Expand Up @@ -140,7 +140,7 @@ void onlyWhileOrderTest() {
@Test
void ignoringDisableTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
var command = new RunCommand(() -> {}).ignoringDisable(true);
var command = Commands.idle().ignoringDisable(true);

setDSEnabled(false);

Expand All @@ -157,7 +157,7 @@ void beforeStartingTest() {
AtomicBoolean finished = new AtomicBoolean();
finished.set(false);

Command command = new InstantCommand().beforeStarting(() -> finished.set(true));
Command command = Commands.none().beforeStarting(() -> finished.set(true));

scheduler.schedule(command);

Expand All @@ -178,7 +178,7 @@ void andThenLambdaTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicBoolean finished = new AtomicBoolean(false);

Command command = new InstantCommand().andThen(() -> finished.set(true));
Command command = Commands.none().andThen(() -> finished.set(true));

scheduler.schedule(command);

Expand All @@ -199,8 +199,8 @@ void andThenTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicBoolean condition = new AtomicBoolean(false);

Command command1 = new InstantCommand();
Command command2 = new InstantCommand(() -> condition.set(true));
Command command1 = Commands.none();
Command command2 = Commands.runOnce(() -> condition.set(true));
Command group = command1.andThen(command2);

scheduler.schedule(group);
Expand All @@ -222,9 +222,9 @@ void deadlineForTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicBoolean finish = new AtomicBoolean(false);

Command dictator = new WaitUntilCommand(finish::get);
Command endsBefore = new InstantCommand();
Command endsAfter = new WaitUntilCommand(() -> false);
Command dictator = Commands.waitUntil(finish::get);
Command endsBefore = Commands.none();
Command endsAfter = Commands.idle();

Command group = dictator.deadlineFor(endsBefore, endsAfter);

Expand Down Expand Up @@ -276,8 +276,8 @@ void alongWithTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
AtomicBoolean finish = new AtomicBoolean(false);

Command command1 = new WaitUntilCommand(finish::get);
Command command2 = new InstantCommand();
Command command1 = Commands.waitUntil(finish::get);
Command command2 = Commands.none();

Command group = command1.alongWith(command2);

Expand Down Expand Up @@ -326,8 +326,8 @@ void alongWithOrderTest() {
@Test
void raceWithTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Command command1 = new WaitUntilCommand(() -> false);
Command command2 = new InstantCommand();
Command command1 = Commands.idle();
Command command2 = Commands.none();

Command group = command1.raceWith(command2);

Expand Down Expand Up @@ -375,7 +375,7 @@ void unlessTest() {
AtomicBoolean hasRun = new AtomicBoolean(false);
AtomicBoolean unlessCondition = new AtomicBoolean(true);

Command command = new InstantCommand(() -> hasRun.set(true)).unless(unlessCondition::get);
Command command = Commands.runOnce(() -> hasRun.set(true)).unless(unlessCondition::get);

scheduler.schedule(command);
scheduler.run();
Expand All @@ -394,7 +394,7 @@ void onlyIfTest() {
AtomicBoolean hasRun = new AtomicBoolean(false);
AtomicBoolean onlyIfCondition = new AtomicBoolean(false);

Command command = new InstantCommand(() -> hasRun.set(true)).onlyIf(onlyIfCondition::get);
Command command = Commands.runOnce(() -> hasRun.set(true)).onlyIf(onlyIfCondition::get);

scheduler.schedule(command);
scheduler.run();
Expand Down Expand Up @@ -480,7 +480,7 @@ void handleInterruptTest() {

@Test
void withNameTest() {
InstantCommand command = new InstantCommand();
Command command = Commands.none();
String name = "Named";
Command named = command.withName(name);
assertEquals(name, named.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void requirementUninterruptibleTest() {
Subsystem requirement = new SubsystemBase() {};

Command notInterrupted =
new RunCommand(() -> {}, requirement)
Commands.idle(requirement)
.withInterruptBehavior(Command.InterruptionBehavior.kCancelIncoming);
MockCommandHolder interrupterHolder = new MockCommandHolder(true, requirement);
Command interrupter = interrupterHolder.getMock();
Expand All @@ -63,7 +63,7 @@ void defaultCommandRequirementErrorTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Subsystem system = new SubsystemBase() {};

Command missingRequirement = new WaitUntilCommand(() -> false);
Command missingRequirement = Commands.idle();

assertThrows(
IllegalArgumentException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,26 @@ static Stream<Arguments> interruptible() {
arguments(
"AllCancelSelf",
InterruptionBehavior.kCancelSelf,
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelSelf),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelSelf),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf),
(BooleanSupplier) () -> true),
arguments(
"AllCancelIncoming",
InterruptionBehavior.kCancelIncoming,
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
(BooleanSupplier) () -> true),
arguments(
"OneCancelSelfOneIncoming",
InterruptionBehavior.kCancelSelf,
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelSelf),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
(BooleanSupplier) () -> true),
arguments(
"OneCancelIncomingOneSelf",
InterruptionBehavior.kCancelSelf,
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelSelf),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf),
(BooleanSupplier) () -> true));
}

Expand All @@ -122,26 +114,26 @@ static Stream<Arguments> runsWhenDisabled() {
arguments(
"AllFalse",
false,
new WaitUntilCommand(() -> false).ignoringDisable(false),
new WaitUntilCommand(() -> false).ignoringDisable(false),
Commands.idle().ignoringDisable(false),
Commands.idle().ignoringDisable(false),
(BooleanSupplier) () -> true),
arguments(
"AllTrue",
true,
new WaitUntilCommand(() -> false).ignoringDisable(true),
new WaitUntilCommand(() -> false).ignoringDisable(true),
Commands.idle().ignoringDisable(true),
Commands.idle().ignoringDisable(true),
(BooleanSupplier) () -> true),
arguments(
"OneTrueOneFalse",
false,
new WaitUntilCommand(() -> false).ignoringDisable(true),
new WaitUntilCommand(() -> false).ignoringDisable(false),
Commands.idle().ignoringDisable(true),
Commands.idle().ignoringDisable(false),
(BooleanSupplier) () -> true),
arguments(
"OneFalseOneTrue",
false,
new WaitUntilCommand(() -> false).ignoringDisable(false),
new WaitUntilCommand(() -> false).ignoringDisable(true),
Commands.idle().ignoringDisable(false),
Commands.idle().ignoringDisable(true),
(BooleanSupplier) () -> true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,27 @@ static Stream<Arguments> interruptible() {
arguments(
"AllCancelSelf",
InterruptionBehavior.kCancelSelf,
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelSelf),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelSelf),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelSelf)),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf)),
arguments(
"AllCancelIncoming",
InterruptionBehavior.kCancelIncoming,
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelIncoming)),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming)),
arguments(
"TwoCancelSelfOneIncoming",
InterruptionBehavior.kCancelSelf,
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelSelf),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelSelf),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelIncoming)),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming)),
arguments(
"TwoCancelIncomingOneSelf",
InterruptionBehavior.kCancelSelf,
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
new WaitUntilCommand(() -> false)
.withInterruptBehavior(InterruptionBehavior.kCancelSelf)));
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming),
Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf)));
}

@MethodSource
Expand All @@ -79,27 +67,27 @@ static Stream<Arguments> runsWhenDisabled() {
arguments(
"AllFalse",
false,
new WaitUntilCommand(() -> false).ignoringDisable(false),
new WaitUntilCommand(() -> false).ignoringDisable(false),
new WaitUntilCommand(() -> false).ignoringDisable(false)),
Commands.idle().ignoringDisable(false),
Commands.idle().ignoringDisable(false),
Commands.idle().ignoringDisable(false)),
arguments(
"AllTrue",
true,
new WaitUntilCommand(() -> false).ignoringDisable(true),
new WaitUntilCommand(() -> false).ignoringDisable(true),
new WaitUntilCommand(() -> false).ignoringDisable(true)),
Commands.idle().ignoringDisable(true),
Commands.idle().ignoringDisable(true),
Commands.idle().ignoringDisable(true)),
arguments(
"TwoTrueOneFalse",
false,
new WaitUntilCommand(() -> false).ignoringDisable(true),
new WaitUntilCommand(() -> false).ignoringDisable(true),
new WaitUntilCommand(() -> false).ignoringDisable(false)),
Commands.idle().ignoringDisable(true),
Commands.idle().ignoringDisable(true),
Commands.idle().ignoringDisable(false)),
arguments(
"TwoFalseOneTrue",
false,
new WaitUntilCommand(() -> false).ignoringDisable(false),
new WaitUntilCommand(() -> false).ignoringDisable(false),
new WaitUntilCommand(() -> false).ignoringDisable(true)));
Commands.idle().ignoringDisable(false),
Commands.idle().ignoringDisable(false),
Commands.idle().ignoringDisable(true)));
}

@MethodSource
Expand All @@ -115,8 +103,8 @@ void runsWhenDisabled(
}

static Stream<Arguments> composeDuplicates() {
Command a = new InstantCommand(() -> {});
Command b = new InstantCommand(() -> {});
Command a = Commands.none();
Command b = Commands.none();
return Stream.of(
arguments("AA", new Command[] {a, a}),
arguments("ABA", new Command[] {a, b, a}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ void parallelDeadlineRequirementErrorTest() {

@Test
void parallelDeadlineSetDeadlineToDeadlineTest() {
Command a = new InstantCommand(() -> {});
Command a = Commands.none();
ParallelDeadlineGroup group = new ParallelDeadlineGroup(a);
assertDoesNotThrow(() -> group.setDeadline(a));
}

@Test
void parallelDeadlineSetDeadlineDuplicateTest() {
Command a = new InstantCommand(() -> {});
Command b = new InstantCommand(() -> {});
Command a = Commands.none();
Command b = Commands.none();
ParallelDeadlineGroup group = new ParallelDeadlineGroup(a, b);
assertThrows(IllegalArgumentException.class, () -> group.setDeadline(b));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void parallelRaceOnlyCallsEndOnceTest() {
MockCommandHolder command3Holder = new MockCommandHolder(true);
Command command3 = command3Holder.getMock();

Command group1 = new SequentialCommandGroup(command1, command2);
Command group1 = Commands.sequence(command1, command2);
assertNotNull(group1);
assertNotNull(command3);
Command group2 = new ParallelRaceGroup(group1, command3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void proxyCommandEndTest() {
try (CommandScheduler scheduler = CommandScheduler.getInstance()) {
AtomicBoolean cond = new AtomicBoolean();

WaitUntilCommand command = new WaitUntilCommand(cond::get);
Command command = Commands.waitUntil(cond::get);

ProxyCommand scheduleCommand = new ProxyCommand(command);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ void scheduleCommandScheduleTest() {
@Test
void scheduleCommandDuringRunTest() {
try (CommandScheduler scheduler = CommandScheduler.getInstance()) {
InstantCommand toSchedule = new InstantCommand();
Command toSchedule = Commands.none();
ScheduleCommand scheduleCommand = new ScheduleCommand(toSchedule);
SequentialCommandGroup group =
new SequentialCommandGroup(new InstantCommand(), scheduleCommand);
Command group = Commands.sequence(Commands.none(), scheduleCommand);

scheduler.schedule(group);
scheduler.schedule(new RunCommand(() -> {}));
scheduler.schedule(Commands.idle());
scheduler.run();
assertDoesNotThrow(scheduler::run);
}
Expand Down
Loading
Loading