From 9cf0fc77b7296c6771faee03455529d05dd4d316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sat, 24 Aug 2024 12:27:12 -0500 Subject: [PATCH 01/21] Do CommandDecoratorTest --- .../command/CommandDecoratorTest.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java index 1f9605d010c..d6448da09ff 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandDecoratorTest.java @@ -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(); @@ -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(); @@ -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(); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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(); @@ -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(); @@ -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()); From 2997b22e3a8ace83a8290736df6440d51c0261aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sat, 24 Aug 2024 17:23:38 -0500 Subject: [PATCH 02/21] Do CommandRequirementsTest --- .../wpi/first/wpilibj2/command/CommandRequirementsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandRequirementsTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandRequirementsTest.java index 47657e19ed8..45f017c3880 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandRequirementsTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/CommandRequirementsTest.java @@ -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(); @@ -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, From eb2d761e5b207bbc6f67a9062d40c9b150d2d5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sat, 24 Aug 2024 21:36:00 -0500 Subject: [PATCH 03/21] Do MultiCompositionTestBase.java --- .../command/MultiCompositionTestBase.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MultiCompositionTestBase.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MultiCompositionTestBase.java index 9fafc5905c3..882abaec56c 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MultiCompositionTestBase.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MultiCompositionTestBase.java @@ -27,38 +27,38 @@ static Stream interruptible() { arguments( "AllCancelSelf", InterruptionBehavior.kCancelSelf, - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelSelf)), arguments( "AllCancelIncoming", InterruptionBehavior.kCancelIncoming, - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelIncoming)), arguments( "TwoCancelSelfOneIncoming", InterruptionBehavior.kCancelSelf, - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelIncoming)), arguments( "TwoCancelIncomingOneSelf", InterruptionBehavior.kCancelSelf, - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelSelf))); } @@ -79,27 +79,27 @@ static Stream 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 @@ -115,8 +115,8 @@ void runsWhenDisabled( } static Stream 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}), From cdd2f05921af178292770df29dd621da427a9398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sat, 24 Aug 2024 21:40:57 -0500 Subject: [PATCH 04/21] Do ConditionalCommandTest --- .../command/ConditionalCommandTest.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java index 4659f0ec3d4..cd37ad75707 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java @@ -74,33 +74,33 @@ static Stream interruptible() { arguments( "AllCancelSelf", InterruptionBehavior.kCancelSelf, - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelSelf), (BooleanSupplier) () -> true), arguments( "AllCancelIncoming", InterruptionBehavior.kCancelIncoming, - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), (BooleanSupplier) () -> true), arguments( "OneCancelSelfOneIncoming", InterruptionBehavior.kCancelSelf, - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), (BooleanSupplier) () -> true), arguments( "OneCancelIncomingOneSelf", InterruptionBehavior.kCancelSelf, - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - new WaitUntilCommand(() -> false) + Commands.idle() .withInterruptBehavior(InterruptionBehavior.kCancelSelf), (BooleanSupplier) () -> true)); } @@ -122,26 +122,26 @@ static Stream 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)); } From 599556d7df3f23425a59f55a6d9237ba1132cbf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sat, 24 Aug 2024 21:45:17 -0500 Subject: [PATCH 05/21] Do ParallelDeadlineGroupTest --- .../first/wpilibj2/command/ParallelDeadlineGroupTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroupTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroupTest.java index 206d801015b..b3d7dfb5563 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroupTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelDeadlineGroupTest.java @@ -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)); } From 6ab83c892070da9c80c683358b2d047525aa2ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 25 Aug 2024 09:37:42 -0500 Subject: [PATCH 06/21] Do ParallelRaceGroupTest --- .../edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java index ea780c6216e..d20e851575d 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java @@ -140,7 +140,7 @@ void parallelRaceOnlyCallsEndOnceTest() { MockCommandHolder command3Holder = new MockCommandHolder(true); Command command3 = command3Holder.getMock(); - Command group1 = new SequentialCommandGroup(command1, command2); + Command group1 = command1.andThen(command2); assertNotNull(group1); assertNotNull(command3); Command group2 = new ParallelRaceGroup(group1, command3); From 25114a8e489db44643bfefd3a71b845431eaa21b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 25 Aug 2024 09:40:55 -0500 Subject: [PATCH 07/21] Do ProxyCommandTest --- .../java/edu/wpi/first/wpilibj2/command/ProxyCommandTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ProxyCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ProxyCommandTest.java index c4b43a609b7..2eae20bbc85 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ProxyCommandTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ProxyCommandTest.java @@ -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); From 075237667c3583cebe460f5eeed42583344ef4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 25 Aug 2024 09:46:58 -0500 Subject: [PATCH 08/21] Do ScheduleCommandTest --- .../edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java index 9014bc7b96e..096168ea879 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java @@ -36,7 +36,7 @@ void scheduleCommandDuringRunTest() { new SequentialCommandGroup(new InstantCommand(), scheduleCommand); scheduler.schedule(group); - scheduler.schedule(new RunCommand(() -> {})); + scheduler.schedule(Commands.idle()); scheduler.run(); assertDoesNotThrow(scheduler::run); } From b1d863affb7cc8458258080e42657f13213bed37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 25 Aug 2024 09:50:15 -0500 Subject: [PATCH 09/21] Do SchedulerTest --- .../edu/wpi/first/wpilibj2/command/SchedulerTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulerTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulerTest.java index 1e0b33332e8..0a6eb3df5ca 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulerTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulerTest.java @@ -23,7 +23,7 @@ void schedulerLambdaTestNoInterrupt() { scheduler.onCommandExecute(command -> counter.incrementAndGet()); scheduler.onCommandFinish(command -> counter.incrementAndGet()); - scheduler.schedule(new InstantCommand()); + scheduler.schedule(Commands.none()); scheduler.run(); assertEquals(counter.get(), 3); @@ -37,7 +37,7 @@ void schedulerInterruptLambdaTest() { scheduler.onCommandInterrupt(command -> counter.incrementAndGet()); - Command command = new WaitCommand(10); + Command command = Commands.idle(); scheduler.schedule(command); scheduler.cancel(command); @@ -162,8 +162,8 @@ void schedulerCancelAllTest() { scheduler.onCommandInterrupt(command -> counter.incrementAndGet()); scheduler.onCommandInterrupt((command, interruptor) -> assertFalse(interruptor.isPresent())); - Command command = new WaitCommand(10); - Command command2 = new WaitCommand(10); + Command command = Commands.idle(); + Command command2 = Commands.idle(); scheduler.schedule(command); scheduler.schedule(command2); From 9d65c17ed5c104b2040309cce45ef398dcf39121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 25 Aug 2024 09:53:45 -0500 Subject: [PATCH 10/21] Do SchedulingRecursionTest --- .../command/SchedulingRecursionTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java index a253740c028..0153f2f1d1e 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java @@ -48,7 +48,7 @@ public InterruptionBehavior getInterruptionBehavior() { return interruptionBehavior; } }; - Command other = new RunCommand(() -> hasOtherRun.set(true), requirement); + Command other = requirement.run(() -> hasOtherRun.set(true)); assertDoesNotThrow( () -> { @@ -87,7 +87,7 @@ public InterruptionBehavior getInterruptionBehavior() { return interruptionBehavior; } }; - Command other = new RunCommand(() -> hasOtherRun.set(true), requirement); + Command other = requirement.run(() -> hasOtherRun.set(true)); assertDoesNotThrow( () -> { @@ -132,7 +132,7 @@ public InterruptionBehavior getInterruptionBehavior() { return interruptionBehavior; } }; - Command other = new RunCommand(() -> hasOtherRun.set(true), requirement); + Command other = requirement.run(() -> hasOtherRun.set(true)); scheduler.setDefaultCommand(requirement, other); assertDoesNotThrow( @@ -173,7 +173,7 @@ public void end(boolean interrupted) { void cancelFromInterruptAction() { try (CommandScheduler scheduler = new CommandScheduler()) { AtomicInteger counter = new AtomicInteger(); - Command selfCancels = new RunCommand(() -> {}); + Command selfCancels = Commands.idle(); scheduler.onCommandInterrupt( cmd -> { counter.incrementAndGet(); @@ -329,7 +329,7 @@ void scheduleFromEndCancel() { try (CommandScheduler scheduler = new CommandScheduler()) { AtomicInteger counter = new AtomicInteger(); Subsystem requirement = new SubsystemBase() {}; - InstantCommand other = new InstantCommand(() -> {}, requirement); + Command other = requirement.runOnce(() -> {}); FunctionalCommand selfCancels = new FunctionalCommand( () -> {}, @@ -354,7 +354,7 @@ void scheduleFromEndInterrupt() { try (CommandScheduler scheduler = new CommandScheduler()) { AtomicInteger counter = new AtomicInteger(); Subsystem requirement = new SubsystemBase() {}; - InstantCommand other = new InstantCommand(() -> {}, requirement); + InstantCommand other = requirement.runOnce(() -> {}); FunctionalCommand selfCancels = new FunctionalCommand( () -> {}, @@ -380,8 +380,8 @@ void scheduleFromEndInterruptAction() { try (CommandScheduler scheduler = new CommandScheduler()) { AtomicInteger counter = new AtomicInteger(); Subsystem requirement = new Subsystem() {}; - InstantCommand other = new InstantCommand(() -> {}, requirement); - InstantCommand selfCancels = new InstantCommand(() -> {}, requirement); + InstantCommand other = requirement.runOnce(() -> {}); + InstantCommand selfCancels = requirement.runOnce(() -> {}); scheduler.onCommandInterrupt( cmd -> { counter.incrementAndGet(); @@ -403,7 +403,7 @@ void scheduleInitializeFromDefaultCommand(InterruptionBehavior interruptionBehav AtomicInteger counter = new AtomicInteger(); Subsystem requirement = new SubsystemBase() {}; Command other = - new InstantCommand(() -> {}, requirement).withInterruptBehavior(interruptionBehavior); + requirement.runOnce(() -> {}).withInterruptBehavior(interruptionBehavior); FunctionalCommand defaultCommand = new FunctionalCommand( () -> { @@ -438,7 +438,7 @@ void cancelDefaultCommandFromEnd() { interrupted -> counter.incrementAndGet(), () -> false, requirement); - Command other = new InstantCommand(() -> {}, requirement); + Command other = requirement.runOnce(() -> {}); Command cancelDefaultCommand = new FunctionalCommand( () -> {}, From 1240dc8a84859f402d9bffbcaaf024647c8b9fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 25 Aug 2024 09:55:00 -0500 Subject: [PATCH 11/21] Do SchedulingRecursionTest --- .../wpi/first/wpilibj2/command/SchedulingRecursionTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java index 0153f2f1d1e..4980a3c6c1a 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java @@ -354,7 +354,7 @@ void scheduleFromEndInterrupt() { try (CommandScheduler scheduler = new CommandScheduler()) { AtomicInteger counter = new AtomicInteger(); Subsystem requirement = new SubsystemBase() {}; - InstantCommand other = requirement.runOnce(() -> {}); + Command other = requirement.runOnce(() -> {}); FunctionalCommand selfCancels = new FunctionalCommand( () -> {}, @@ -380,8 +380,8 @@ void scheduleFromEndInterruptAction() { try (CommandScheduler scheduler = new CommandScheduler()) { AtomicInteger counter = new AtomicInteger(); Subsystem requirement = new Subsystem() {}; - InstantCommand other = requirement.runOnce(() -> {}); - InstantCommand selfCancels = requirement.runOnce(() -> {}); + Command other = requirement.runOnce(() -> {}); + Command selfCancels = requirement.runOnce(() -> {}); scheduler.onCommandInterrupt( cmd -> { counter.incrementAndGet(); From 063ebaed58ac6386411263276c9e344ff043861a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 25 Aug 2024 10:25:42 -0500 Subject: [PATCH 12/21] Fix ParallelRaceGroupTest failing command1 and command2 are mock Commands that don't actually implement Command decorators --- .../edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java index d20e851575d..bd44a128b8c 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ParallelRaceGroupTest.java @@ -140,7 +140,7 @@ void parallelRaceOnlyCallsEndOnceTest() { MockCommandHolder command3Holder = new MockCommandHolder(true); Command command3 = command3Holder.getMock(); - Command group1 = command1.andThen(command2); + Command group1 = Commands.sequence(command1, command2); assertNotNull(group1); assertNotNull(command3); Command group2 = new ParallelRaceGroup(group1, command3); From c44fb833908ef4abb066d0fcc72bc341e90618c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 25 Aug 2024 10:27:55 -0500 Subject: [PATCH 13/21] Do SelectCommandTest --- .../java/edu/wpi/first/wpilibj2/command/SelectCommandTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SelectCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SelectCommandTest.java index e364468186c..f6f551bd6e9 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SelectCommandTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SelectCommandTest.java @@ -97,7 +97,7 @@ void selectCommandRequirementTest() { () -> "one"); scheduler.schedule(selectCommand); - scheduler.schedule(new InstantCommand(() -> {}, system3)); + scheduler.schedule(system3.runOnce(() -> {})); assertFalse(scheduler.isScheduled(selectCommand)); From 2c879601fae7f7d25c98ba84f3013b3a21dcd170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 25 Aug 2024 10:29:57 -0500 Subject: [PATCH 14/21] Do SingleCompositionTestBase --- .../wpilibj2/command/SingleCompositionTestBase.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SingleCompositionTestBase.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SingleCompositionTestBase.java index a063a1de638..ce4ef549bed 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SingleCompositionTestBase.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SingleCompositionTestBase.java @@ -20,7 +20,7 @@ public abstract class SingleCompositionTestBase extends Comma void interruptible(Command.InterruptionBehavior interruptionBehavior) { var command = composeSingle( - new WaitUntilCommand(() -> false).withInterruptBehavior(interruptionBehavior)); + Commands.idle().withInterruptBehavior(interruptionBehavior)); assertEquals(interruptionBehavior, command.getInterruptionBehavior()); } @@ -28,27 +28,27 @@ void interruptible(Command.InterruptionBehavior interruptionBehavior) { @ParameterizedTest void runWhenDisabled(boolean runsWhenDisabled) { var command = - composeSingle(new WaitUntilCommand(() -> false).ignoringDisable(runsWhenDisabled)); + composeSingle(Commands.idle().ignoringDisable(runsWhenDisabled)); assertEquals(runsWhenDisabled, command.runsWhenDisabled()); } @Test void commandInOtherCompositionTest() { - var command = new InstantCommand(); + var command = Commands.none(); new WrapperCommand(command) {}; assertThrows(IllegalArgumentException.class, () -> composeSingle(command)); } @Test void commandInMultipleCompositionsTest() { - var command = new InstantCommand(); + var command = Commands.none(); composeSingle(command); assertThrows(IllegalArgumentException.class, () -> composeSingle(command)); } @Test void composeThenScheduleTest() { - var command = new InstantCommand(); + var command = Commands.none(); composeSingle(command); assertThrows( IllegalArgumentException.class, () -> CommandScheduler.getInstance().schedule(command)); @@ -56,7 +56,7 @@ void composeThenScheduleTest() { @Test void scheduleThenComposeTest() { - var command = new RunCommand(() -> {}); + var command = Commands.idle(); CommandScheduler.getInstance().schedule(command); assertThrows(IllegalArgumentException.class, () -> composeSingle(command)); } From 443b982c15516075376adc96605f568f05706abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 25 Aug 2024 10:35:24 -0500 Subject: [PATCH 15/21] Do ScheduleCommandTest --- .../edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java index 096168ea879..68299d86726 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java @@ -30,10 +30,10 @@ 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(Commands.idle()); From 8088350cf75e4b1c752b98d035fb53e4aa136957 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 25 Aug 2024 15:56:56 +0000 Subject: [PATCH 16/21] Formatting fixes --- .../command/ConditionalCommandTest.java | 24 +++++-------- .../command/MultiCompositionTestBase.java | 36 +++++++------------ .../wpilibj2/command/ScheduleCommandTest.java | 3 +- .../command/SchedulingRecursionTest.java | 3 +- .../command/SingleCompositionTestBase.java | 7 ++-- 5 files changed, 24 insertions(+), 49 deletions(-) diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java index cd37ad75707..7b9817f5645 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ConditionalCommandTest.java @@ -74,34 +74,26 @@ static Stream interruptible() { arguments( "AllCancelSelf", InterruptionBehavior.kCancelSelf, - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelSelf), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf), (BooleanSupplier) () -> true), arguments( "AllCancelIncoming", InterruptionBehavior.kCancelIncoming, - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming), (BooleanSupplier) () -> true), arguments( "OneCancelSelfOneIncoming", InterruptionBehavior.kCancelSelf, - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming), (BooleanSupplier) () -> true), arguments( "OneCancelIncomingOneSelf", InterruptionBehavior.kCancelSelf, - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelSelf), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf), (BooleanSupplier) () -> true)); } diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MultiCompositionTestBase.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MultiCompositionTestBase.java index 882abaec56c..1b0e8e91419 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MultiCompositionTestBase.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/MultiCompositionTestBase.java @@ -27,39 +27,27 @@ static Stream interruptible() { arguments( "AllCancelSelf", InterruptionBehavior.kCancelSelf, - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelSelf)), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf)), arguments( "AllCancelIncoming", InterruptionBehavior.kCancelIncoming, - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelIncoming)), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming)), arguments( "TwoCancelSelfOneIncoming", InterruptionBehavior.kCancelSelf, - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelSelf), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelIncoming)), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming)), arguments( "TwoCancelIncomingOneSelf", InterruptionBehavior.kCancelSelf, - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelIncoming), - Commands.idle() - .withInterruptBehavior(InterruptionBehavior.kCancelSelf))); + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelIncoming), + Commands.idle().withInterruptBehavior(InterruptionBehavior.kCancelSelf))); } @MethodSource diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java index 68299d86726..875b2e5ea9b 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/ScheduleCommandTest.java @@ -32,8 +32,7 @@ void scheduleCommandDuringRunTest() { try (CommandScheduler scheduler = CommandScheduler.getInstance()) { Command toSchedule = Commands.none(); ScheduleCommand scheduleCommand = new ScheduleCommand(toSchedule); - Command group = - Commands.sequence(Commands.none(), scheduleCommand); + Command group = Commands.sequence(Commands.none(), scheduleCommand); scheduler.schedule(group); scheduler.schedule(Commands.idle()); diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java index 4980a3c6c1a..06f4023f6b8 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SchedulingRecursionTest.java @@ -402,8 +402,7 @@ void scheduleInitializeFromDefaultCommand(InterruptionBehavior interruptionBehav try (CommandScheduler scheduler = new CommandScheduler()) { AtomicInteger counter = new AtomicInteger(); Subsystem requirement = new SubsystemBase() {}; - Command other = - requirement.runOnce(() -> {}).withInterruptBehavior(interruptionBehavior); + Command other = requirement.runOnce(() -> {}).withInterruptBehavior(interruptionBehavior); FunctionalCommand defaultCommand = new FunctionalCommand( () -> { diff --git a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SingleCompositionTestBase.java b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SingleCompositionTestBase.java index ce4ef549bed..5f6fe9e8616 100644 --- a/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SingleCompositionTestBase.java +++ b/wpilibNewCommands/src/test/java/edu/wpi/first/wpilibj2/command/SingleCompositionTestBase.java @@ -18,17 +18,14 @@ public abstract class SingleCompositionTestBase extends Comma @EnumSource(Command.InterruptionBehavior.class) @ParameterizedTest void interruptible(Command.InterruptionBehavior interruptionBehavior) { - var command = - composeSingle( - Commands.idle().withInterruptBehavior(interruptionBehavior)); + var command = composeSingle(Commands.idle().withInterruptBehavior(interruptionBehavior)); assertEquals(interruptionBehavior, command.getInterruptionBehavior()); } @ValueSource(booleans = {true, false}) @ParameterizedTest void runWhenDisabled(boolean runsWhenDisabled) { - var command = - composeSingle(Commands.idle().ignoringDisable(runsWhenDisabled)); + var command = composeSingle(Commands.idle().ignoringDisable(runsWhenDisabled)); assertEquals(runsWhenDisabled, command.runsWhenDisabled()); } From 717b66fd0172b0742ce508b669883aeb6f6c295c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Fri, 13 Sep 2024 23:05:41 -0500 Subject: [PATCH 17/21] Start work on CommandDecoratorTest --- .../cpp/frc2/command/CommandDecoratorTest.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp index a5059b16e11..7bf1eed3fec 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp @@ -7,6 +7,7 @@ #include "CommandTestBase.h" #include "frc2/command/FunctionalCommand.h" #include "frc2/command/InstantCommand.h" +#include "frc2/command/Commands.h" #include "frc2/command/RunCommand.h" #include "frc2/command/WaitUntilCommand.h" @@ -18,7 +19,7 @@ TEST_F(CommandDecoratorTest, WithTimeout) { frc::sim::PauseTiming(); - auto command = RunCommand([] {}, {}).WithTimeout(100_ms); + auto command = cmd::Idle().WithTimeout(100_ms); scheduler.Schedule(command); scheduler.Run(); @@ -39,7 +40,7 @@ TEST_F(CommandDecoratorTest, Until) { bool finish = false; - auto command = RunCommand([] {}, {}).Until([&finish] { return finish; }); + auto command = cmd::Idle().Until([&finish] { return finish; }); scheduler.Schedule(command); scheduler.Run(); @@ -82,7 +83,7 @@ TEST_F(CommandDecoratorTest, OnlyWhile) { bool run = true; - auto command = RunCommand([] {}, {}).OnlyWhile([&run] { return run; }); + auto command = cmd::Idle().OnlyWhile([&run] { return run; }); scheduler.Schedule(command); scheduler.Run(); @@ -123,7 +124,7 @@ TEST_F(CommandDecoratorTest, OnlyWhileOrder) { TEST_F(CommandDecoratorTest, IgnoringDisable) { CommandScheduler scheduler = GetScheduler(); - auto command = RunCommand([] {}, {}).IgnoringDisable(true); + auto command = cmd::Idle().IgnoringDisable(true); SetDSEnabled(false); @@ -138,7 +139,7 @@ TEST_F(CommandDecoratorTest, BeforeStarting) { bool finished = false; - auto command = InstantCommand([] {}, {}).BeforeStarting( + auto command = cmd::None().BeforeStarting( [&finished] { finished = true; }); scheduler.Schedule(command); @@ -160,7 +161,7 @@ TEST_F(CommandDecoratorTest, AndThenLambda) { bool finished = false; auto command = - InstantCommand([] {}, {}).AndThen([&finished] { finished = true; }); + cmd::None().AndThen([&finished] { finished = true; }); scheduler.Schedule(command); From 497e3cc6efdd0b18397ca13ab5c980dd25edfffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Fri, 20 Sep 2024 11:20:58 -0500 Subject: [PATCH 18/21] CommandDecoratorTest done --- .../cpp/frc2/command/CommandDecoratorTest.cpp | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp index 7bf1eed3fec..5cc1bb99afb 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp @@ -181,9 +181,9 @@ TEST_F(CommandDecoratorTest, AndThen) { bool finished = false; - auto command1 = InstantCommand(); - auto command2 = InstantCommand([&finished] { finished = true; }); - auto group = std::move(command1).AndThen(std::move(command2).ToPtr()); + auto command1 = cmd::None(); + auto command2 = cmd::RunOnce([&finished] { finished = true; }); + auto group = std::move(command1).AndThen(std::move(command2)); scheduler.Schedule(group); @@ -203,10 +203,10 @@ TEST_F(CommandDecoratorTest, DeadlineFor) { bool finish = false; - auto dictator = WaitUntilCommand([&finish] { return finish; }); - auto endsAfter = WaitUntilCommand([] { return false; }); + auto dictator = cmd::WaitUntil([&finish] { return finish; }); + auto endsAfter = cmd::Idle(); - auto group = std::move(dictator).DeadlineFor(std::move(endsAfter).ToPtr()); + auto group = std::move(dictator).DeadlineFor(std::move(endsAfter)); scheduler.Schedule(group); scheduler.Run(); @@ -224,10 +224,10 @@ TEST_F(CommandDecoratorTest, AlongWith) { bool finish = false; - auto command1 = WaitUntilCommand([&finish] { return finish; }); - auto command2 = InstantCommand(); + auto command1 = cmd::WaitUntil([&finish] { return finish; }); + auto command2 = cmd::None(); - auto group = std::move(command1).AlongWith(std::move(command2).ToPtr()); + auto group = std::move(command1).AlongWith(std::move(command2)); scheduler.Schedule(group); scheduler.Run(); @@ -243,10 +243,10 @@ TEST_F(CommandDecoratorTest, AlongWith) { TEST_F(CommandDecoratorTest, RaceWith) { CommandScheduler scheduler = GetScheduler(); - auto command1 = WaitUntilCommand([] { return false; }); - auto command2 = InstantCommand(); + auto command1 = cmd::Idle(); + auto command2 = cmd::None(); - auto group = std::move(command1).RaceWith(std::move(command2).ToPtr()); + auto group = std::move(command1).RaceWith(std::move(command2)); scheduler.Schedule(group); scheduler.Run(); @@ -267,12 +267,12 @@ TEST_F(CommandDecoratorTest, DeadlineForOrder) { dictatorWasPolled = true; return true; }); - auto other = RunCommand([&dictatorHasRun, &dictatorWasPolled] { + auto other = cmd::Run([&dictatorHasRun, &dictatorWasPolled] { EXPECT_TRUE(dictatorHasRun); EXPECT_TRUE(dictatorWasPolled); }); - auto group = std::move(dictator).DeadlineFor(std::move(other).ToPtr()); + auto group = std::move(dictator).DeadlineFor(std::move(other)); scheduler.Schedule(group); scheduler.Run(); @@ -293,12 +293,12 @@ TEST_F(CommandDecoratorTest, AlongWithOrder) { firstWasPolled = true; return true; }); - auto command2 = RunCommand([&firstHasRun, &firstWasPolled] { + auto command2 = cmd::Run([&firstHasRun, &firstWasPolled] { EXPECT_TRUE(firstHasRun); EXPECT_TRUE(firstWasPolled); }); - auto group = std::move(command1).AlongWith(std::move(command2).ToPtr()); + auto group = std::move(command1).AlongWith(std::move(command2)); scheduler.Schedule(group); scheduler.Run(); @@ -319,12 +319,12 @@ TEST_F(CommandDecoratorTest, RaceWithOrder) { firstWasPolled = true; return true; }); - auto command2 = RunCommand([&firstHasRun, &firstWasPolled] { + auto command2 = cmd::Run([&firstHasRun, &firstWasPolled] { EXPECT_TRUE(firstHasRun); EXPECT_TRUE(firstWasPolled); }); - auto group = std::move(command1).RaceWith(std::move(command2).ToPtr()); + auto group = std::move(command1).RaceWith(std::move(command2)); scheduler.Schedule(group); scheduler.Run(); @@ -339,7 +339,7 @@ TEST_F(CommandDecoratorTest, Unless) { bool hasRun = false; bool unlessCondition = true; - auto command = InstantCommand([&hasRun] { hasRun = true; }, {}) + auto command = cmd::RunOnce([&hasRun] { hasRun = true; }, {}) .Unless([&unlessCondition] { return unlessCondition; }); scheduler.Schedule(command); From 1d115a47ef153b64431117bf9c08bc34fd39c494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 27 Oct 2024 12:08:06 -0500 Subject: [PATCH 19/21] Do CommandDecoratorTest --- .../src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp index 85dd3dc5126..63025780f0a 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp @@ -361,8 +361,8 @@ TEST_F(CommandDecoratorTest, OnlyIf) { bool hasRun = false; bool onlyIfCondition = false; - auto command = InstantCommand([&hasRun] { hasRun = true; }, {}) - .OnlyIf([&onlyIfCondition] { return onlyIfCondition; }); + auto command = cmd::RunOnce([&hasRun] {hasRun = true;}, {}) + .OnlyIf([&onlyIfCondition] { return onlyIfCondition; }); scheduler.Schedule(command); scheduler.Run(); From a6898a9dbdf47be1c449efe119add23f8ad9e4c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8F=E3=82=A4=E3=83=89=E3=83=A9=E3=83=B3=E3=83=88?= Date: Sun, 27 Oct 2024 13:05:15 -0500 Subject: [PATCH 20/21] Do ConditionalCommandTest --- .../frc2/command/ConditionalCommandTest.cpp | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp index 7896a1aa326..25aefd6309b 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp @@ -57,32 +57,32 @@ TEST_F(ConditionalCommandTest, ConditionalCommandRequirement) { TEST_F(ConditionalCommandTest, AllTrue) { CommandPtr command = - cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(true), - cmd::WaitUntil([] { return false; }).IgnoringDisable(true), + cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(true), + cmd::Run([] {}, {}).IgnoringDisable(true), [] { return true; }); EXPECT_EQ(true, command.get()->RunsWhenDisabled()); } TEST_F(ConditionalCommandTest, AllFalse) { CommandPtr command = - cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(false), - cmd::WaitUntil([] { return false; }).IgnoringDisable(false), + cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(false), + cmd::Run([] {}, {}).IgnoringDisable(false), [] { return true; }); EXPECT_EQ(false, command.get()->RunsWhenDisabled()); } TEST_F(ConditionalCommandTest, OneTrueOneFalse) { CommandPtr command = - cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(true), - cmd::WaitUntil([] { return false; }).IgnoringDisable(false), + cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(true), + cmd::Run([] {}, {}).IgnoringDisable(false), [] { return true; }); EXPECT_EQ(false, command.get()->RunsWhenDisabled()); } TEST_F(ConditionalCommandTest, TwoFalseOneTrue) { CommandPtr command = - cmd::Either(cmd::WaitUntil([] { return false; }).IgnoringDisable(false), - cmd::WaitUntil([] { return false; }).IgnoringDisable(true), + cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(false), + cmd::Run([] {}, {}).IgnoringDisable(true), [] { return true; }); EXPECT_EQ(false, command.get()->RunsWhenDisabled()); } @@ -102,12 +102,8 @@ TEST_F(ConditionalCommandTest, AllCancelSelf) { TEST_F(ConditionalCommandTest, AllCancelIncoming) { CommandPtr command = cmd::Either( - cmd::WaitUntil([] { - return false; - }).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), - cmd::WaitUntil([] { - return false; - }).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), + cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), + cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), [] { return false; }); EXPECT_EQ(Command::InterruptionBehavior::kCancelIncoming, command.get()->GetInterruptionBehavior()); @@ -115,12 +111,8 @@ TEST_F(ConditionalCommandTest, AllCancelIncoming) { TEST_F(ConditionalCommandTest, OneCancelSelfOneIncoming) { CommandPtr command = cmd::Either( - cmd::WaitUntil([] { - return false; - }).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf), - cmd::WaitUntil([] { - return false; - }).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), + cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf), + cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), [] { return false; }); EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf, command.get()->GetInterruptionBehavior()); @@ -128,12 +120,8 @@ TEST_F(ConditionalCommandTest, OneCancelSelfOneIncoming) { TEST_F(ConditionalCommandTest, OneCancelIncomingOneSelf) { CommandPtr command = cmd::Either( - cmd::WaitUntil([] { - return false; - }).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), - cmd::WaitUntil([] { - return false; - }).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf), + cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), + cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf), [] { return false; }); EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf, command.get()->GetInterruptionBehavior()); From 739b76cf2d24a5196830cd942821892059337b29 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 27 Oct 2024 18:36:00 +0000 Subject: [PATCH 21/21] Formatting fixes --- .../cpp/frc2/command/CommandDecoratorTest.cpp | 20 ++++--- .../frc2/command/ConditionalCommandTest.cpp | 58 ++++++++++--------- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp index 63025780f0a..e7e5971b4f8 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp @@ -8,9 +8,9 @@ #include #include "CommandTestBase.h" +#include "frc2/command/Commands.h" #include "frc2/command/FunctionalCommand.h" #include "frc2/command/InstantCommand.h" -#include "frc2/command/Commands.h" #include "frc2/command/RunCommand.h" #include "frc2/command/WaitUntilCommand.h" @@ -142,8 +142,7 @@ TEST_F(CommandDecoratorTest, BeforeStarting) { bool finished = false; - auto command = cmd::None().BeforeStarting( - [&finished] { finished = true; }); + auto command = cmd::None().BeforeStarting([&finished] { finished = true; }); scheduler.Schedule(command); @@ -163,8 +162,7 @@ TEST_F(CommandDecoratorTest, AndThenLambda) { bool finished = false; - auto command = - cmd::None().AndThen([&finished] { finished = true; }); + auto command = cmd::None().AndThen([&finished] { finished = true; }); scheduler.Schedule(command); @@ -342,8 +340,10 @@ TEST_F(CommandDecoratorTest, Unless) { bool hasRun = false; bool unlessCondition = true; - auto command = cmd::RunOnce([&hasRun] { hasRun = true; }, {}) - .Unless([&unlessCondition] { return unlessCondition; }); + auto command = + cmd::RunOnce([&hasRun] { hasRun = true; }, {}).Unless([&unlessCondition] { + return unlessCondition; + }); scheduler.Schedule(command); scheduler.Run(); @@ -361,8 +361,10 @@ TEST_F(CommandDecoratorTest, OnlyIf) { bool hasRun = false; bool onlyIfCondition = false; - auto command = cmd::RunOnce([&hasRun] {hasRun = true;}, {}) - .OnlyIf([&onlyIfCondition] { return onlyIfCondition; }); + auto command = + cmd::RunOnce([&hasRun] { hasRun = true; }, {}).OnlyIf([&onlyIfCondition] { + return onlyIfCondition; + }); scheduler.Schedule(command); scheduler.Run(); diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp index 25aefd6309b..90fb4adcf4e 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/ConditionalCommandTest.cpp @@ -56,34 +56,30 @@ TEST_F(ConditionalCommandTest, ConditionalCommandRequirement) { } TEST_F(ConditionalCommandTest, AllTrue) { - CommandPtr command = - cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(true), - cmd::Run([] {}, {}).IgnoringDisable(true), - [] { return true; }); + CommandPtr command = cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(true), + cmd::Run([] {}, {}).IgnoringDisable(true), + [] { return true; }); EXPECT_EQ(true, command.get()->RunsWhenDisabled()); } TEST_F(ConditionalCommandTest, AllFalse) { - CommandPtr command = - cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(false), - cmd::Run([] {}, {}).IgnoringDisable(false), - [] { return true; }); + CommandPtr command = cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(false), + cmd::Run([] {}, {}).IgnoringDisable(false), + [] { return true; }); EXPECT_EQ(false, command.get()->RunsWhenDisabled()); } TEST_F(ConditionalCommandTest, OneTrueOneFalse) { - CommandPtr command = - cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(true), - cmd::Run([] {}, {}).IgnoringDisable(false), - [] { return true; }); + CommandPtr command = cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(true), + cmd::Run([] {}, {}).IgnoringDisable(false), + [] { return true; }); EXPECT_EQ(false, command.get()->RunsWhenDisabled()); } TEST_F(ConditionalCommandTest, TwoFalseOneTrue) { - CommandPtr command = - cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(false), - cmd::Run([] {}, {}).IgnoringDisable(true), - [] { return true; }); + CommandPtr command = cmd::Either(cmd::Run([] {}, {}).IgnoringDisable(false), + cmd::Run([] {}, {}).IgnoringDisable(true), + [] { return true; }); EXPECT_EQ(false, command.get()->RunsWhenDisabled()); } @@ -101,28 +97,34 @@ TEST_F(ConditionalCommandTest, AllCancelSelf) { } TEST_F(ConditionalCommandTest, AllCancelIncoming) { - CommandPtr command = cmd::Either( - cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), - cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), - [] { return false; }); + CommandPtr command = + cmd::Either(cmd::Run([] {}, {}).WithInterruptBehavior( + Command::InterruptionBehavior::kCancelIncoming), + cmd::Run([] {}, {}).WithInterruptBehavior( + Command::InterruptionBehavior::kCancelIncoming), + [] { return false; }); EXPECT_EQ(Command::InterruptionBehavior::kCancelIncoming, command.get()->GetInterruptionBehavior()); } TEST_F(ConditionalCommandTest, OneCancelSelfOneIncoming) { - CommandPtr command = cmd::Either( - cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf), - cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), - [] { return false; }); + CommandPtr command = + cmd::Either(cmd::Run([] {}, {}).WithInterruptBehavior( + Command::InterruptionBehavior::kCancelSelf), + cmd::Run([] {}, {}).WithInterruptBehavior( + Command::InterruptionBehavior::kCancelIncoming), + [] { return false; }); EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf, command.get()->GetInterruptionBehavior()); } TEST_F(ConditionalCommandTest, OneCancelIncomingOneSelf) { - CommandPtr command = cmd::Either( - cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelIncoming), - cmd::Run([] {}, {}).WithInterruptBehavior(Command::InterruptionBehavior::kCancelSelf), - [] { return false; }); + CommandPtr command = + cmd::Either(cmd::Run([] {}, {}).WithInterruptBehavior( + Command::InterruptionBehavior::kCancelIncoming), + cmd::Run([] {}, {}).WithInterruptBehavior( + Command::InterruptionBehavior::kCancelSelf), + [] { return false; }); EXPECT_EQ(Command::InterruptionBehavior::kCancelSelf, command.get()->GetInterruptionBehavior()); }