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

[commands] Use factories and decorators in Command tests #7006

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 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
6cb3ca5
Merge branch 'main' into factories-in-command-tests
TheComputer314 Dec 4, 2024
20b9250
Do CommandDecoratorTest.cpp
TheComputer314 Dec 7, 2024
4e14491
Do ParallelDeadlineGroupTest
TheComputer314 Dec 7, 2024
c2557a2
Do ParallelCommandGroupTest & ParallelDeadlineGroupTest
TheComputer314 Dec 7, 2024
c9bed3c
Do ParallelRaceGroupTest
TheComputer314 Dec 7, 2024
deea284
Do CommandDecoratorTest.java
TheComputer314 Dec 7, 2024
c132d57
Do PrintCommandTest
TheComputer314 Dec 7, 2024
c6febfe
Do RunCommandTest
TheComputer314 Dec 7, 2024
59f3d69
Do ProxyCommandTest
TheComputer314 Dec 7, 2024
8bbbe9c
Do SchedulerTest
TheComputer314 Dec 7, 2024
a431032
Do SchedulingRecursionTest
TheComputer314 Dec 7, 2024
4a1abdf
Do SequentialCommandGroupTest
TheComputer314 Dec 7, 2024
51de3fe
Do StartEndCommandTest
TheComputer314 Dec 7, 2024
d58f052
Do WaitCommandTest
TheComputer314 Dec 7, 2024
6dfa97c
Do WaitUntilCommandTest
TheComputer314 Dec 7, 2024
3f44144
Shorten command factory uses
TheComputer314 Dec 7, 2024
aa15a53
Do DefaultCommandTest
TheComputer314 Dec 7, 2024
dcd36be
Merge branch 'main' into factories-in-command-tests
TheComputer314 Dec 8, 2024
cb29447
Resolve requested changed
TheComputer314 Dec 9, 2024
6659f58
Do SchedulerTest
TheComputer314 Dec 12, 2024
17247a7
Do SchedulingRecusionTest
TheComputer314 Dec 12, 2024
5addac0
Do SelectCommandTest
TheComputer314 Dec 12, 2024
ed02b24
Formatting fixes
github-actions[bot] Dec 12, 2024
b8e6479
Do ParallelRaceGroupTest.ParallelRaceCopy
TheComputer314 Dec 15, 2024
49cced1
Merge branch 'refs/heads/main' into factories-in-command-tests
TheComputer314 Dec 28, 2024
d6e87ca
Do CompositionTestBase
TheComputer314 Dec 28, 2024
5210266
Do ConditionalCommandTest.AllCancelSelf
TheComputer314 Dec 28, 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 @@ -256,7 +256,7 @@ void deadlineForOrderTest() {
return true;
});
Command other =
new RunCommand(
Commands.run(
() ->
assertAll(
() -> assertTrue(dictatorHasRun.get()),
Expand Down Expand Up @@ -327,8 +327,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 @@ -360,7 +360,7 @@ void alongWithOrderTest() {
return true;
});
Command command2 =
new RunCommand(
Commands.run(
() ->
assertAll(
() -> assertTrue(firstHasRun.get()), () -> assertTrue(firstWasPolled.get())));
Expand All @@ -377,8 +377,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 All @@ -405,7 +405,7 @@ void raceWithOrderTest() {
return true;
});
Command command2 =
new RunCommand(
Commands.run(
() -> {
assertTrue(firstHasRun.get());
assertTrue(firstWasPolled.get());
Expand All @@ -426,7 +426,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 @@ -445,7 +445,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 @@ -531,7 +531,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does requirement.idle() exist?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

.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
Loading
Loading