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 5c1b5074dbd..7c5f7abf71f 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 @@ -450,13 +450,15 @@ void repeatForTest() { Command group = command.repeatedly(3); scheduler.schedule(group); - for (int i = 0; - scheduler.isScheduled(group); - i++) { // If this causes an infinite loop, repeatedly is cooked + assertEquals(1, counter.get()); + for (int i = 1; i < 3; i++) { scheduler.run(); - assertEquals(i + 1, counter.get()); + assertEquals(i, counter.get()); + assertTrue(scheduler.isScheduled(group), "Expected group to be scheduled with i = " + i); } - assertEquals(3, counter.get()); + scheduler.run(); + assertEquals(3, counter.get(), "Loop should have run 3 times something went wrong"); + assertFalse(scheduler.isScheduled(group), "This command should have gotten unscheduled"); } } diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp index edfa7cf9706..5355c2e99ac 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/CommandDecoratorTest.cpp @@ -408,12 +408,16 @@ TEST_F(CommandDecoratorTest, RepeatFor) { auto command = InstantCommand([&counter] { counter++; }, {}).Repeatedly(3); scheduler.Schedule(command); - for (int i = 0; scheduler.IsScheduled(command); i++) { + EXPECT_TRUE(scheduler.IsScheduled(command)); + for (int i = 1; i < 3; i++) { scheduler.Run(); - EXPECT_EQ(i + 1, counter); + EXPECT_EQ(i, counter); + EXPECT_TRUE(scheduler.IsScheduled(command)); } + scheduler.Run(); EXPECT_EQ(3, counter); + EXPECT_FALSE(scheduler.IsScheduled(command)); } TEST_F(CommandDecoratorTest, Unless) {