allwpilib icon indicating copy to clipboard operation
allwpilib copied to clipboard

[cmd] Use command factories and decorators in command tests

Open KangarooKoala opened this issue 3 months ago • 1 comments

Currently, tests use command class constructors to make commands (e.g., new RunCommand(() -> {})). This deviates from the recommended coding style and is not as readable. The tests should be updated to use command factories and decorators instead where applicable. The list below has every spot I noticed that should be changed (excluding spots where the class itself is being tested, such as the class-specific tests (e.g., ConditionalCommandTest) and RobotDisabledCommandTest).

Spots to change (in Java, haven't checked C++ yet):

  • CommandDecoratorTest: (4x) new RunCommand(() -> {}) -> Commands.idle()
  • CommandDecoratorTest: (7x) new InstantCommand() -> Commands.none()
  • CommandDecoratorTest: new InstantCommand(() -> condition.set(true)) -> Commands.runOnce(() -> condition.set(true))
  • CommandDecoratorTest: (2x) new WaitUntilCommand(finish::get) -> Commands.waitUntil(finish::get)
  • CommandDecoratorTest: (2x) new WaitUntilCommand(() -> false) -> Commands.idle()
  • CommandDecoratorTest: (2x) new InstantCommand(() -> hasRun.set(true)) -> Commands.runOnce(() -> hasRun.set(true))
  • CommandRequirementsTest: new RunCommand(() -> {}, requirement) -> Commands.idle(requirement) or requirement.run(() -> {})
  • CommandRequirementsTest: new WaitUntilCommand(() -> false) -> Commands.idle()
  • ConditionalCommandTest: new InstantCommand(() -> {}, system3) -> Commands.runOnce(() -> {}, system3) or system3.runOnce(() -> {})
  • ConditionalCommandTest: (16x) new WaitUntilCommand(() -> false) -> Commands.idle()
  • MultiCompositionTestBase: (24x) new WaitUntilCommand(() -> false) -> Commands.idle()
  • MultiCompositionTestBase: (2x) new InstantComand(() -> {}) -> Commands.none()
  • ParallelDeadlineGroupTest: (3x) new InstantCommand(() -> {}) -> Commands.none()
  • ParallelRaceGroupTest: new SequentialCommandGroup(command1, command2) -> Commands.sequence(command1, command2) or command1.andThen(command2)
  • ProxyCommandTest: new WaitUntilCommand(cond::get) -> Commands.waitUntil(cond::get)
  • ScheduleCommandTest: new SequentialCommandGroup(new InstantCommand(), scheduleCommand) -> Commands.sequence(Commands.none(), scheduleCommand) or Commands.none().andThen(scheduleCommand) or scheduleCommand.beforeStarting(Commands.none())
  • ScheduleCommandTest: new RunCommand(() -> {}) -> Commands.idle()
  • SchedulerTest: new InstantCommand() -> Commands.none()
  • SchedulerTest: (3x) new WaitCommand(10) -> Commands.idle() (We don't actually care about the command ending after 10 seconds)
  • SchedulingRecursionTest: (3x) new RunCommand(() -> hasOtherRun.set(true), requirement) -> Commands.run(() -> hasOtherRun.set(true), requirement) or requirement.run(() -> hasOtherRun.set(true))
  • SchedulingRecursionTest: new RunCommand(() -> {}) -> Commands.idle()
  • SchedulingRecursionTest: (6x) new InstantCommand(() -> {}, requirement) -> Commands.runOnce(() -> {}, requirement) or requirement.runOnce(() -> {})
  • SelectCommandTest: new InstantCommand(() -> {}, system3) -> Commands.runOnce(() -> {}, system3) or system3.runOnce(() -> {})
  • SingleCompositionTestBase: (2x) new WaitUntilCommand(() -> false) -> Commands.idle()
  • SingleCompositionTestBase: (3x) new InstantCommand() -> Commands.none()
  • SingleCompositionTestBase: new RunCommand(() -> {}) -> Commands.idle()

Other notes:

  • There's a decent number of FunctionalCommand instances that can't be directly replaced with command factories. (We could reproduce the logic with some compositions, but that increases the logic complexity of the test)
  • Commands.none() can't accept any requirements, which may be a separate issue. (It also might not- I could also see the case for it not being able to accept any requirements, such as the meaning of a "do nothing command")
  • A Subsystem.idle() would make sense, but belongs in a separate issue.

KangarooKoala avatar May 24 '24 18:05 KangarooKoala