-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/test/java/command_tests/simple_command_tests/LEDWaitingCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package command_tests.simple_command_tests; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static subsystem_tests.led_tests.utils.LEDTestUtils.testAtTime; | ||
|
||
import command_tests.utils.CommandTestBase; | ||
import edu.wpi.first.wpilibj.Timer; | ||
import frc.robot.commands.led_commands.LEDLoadingWaitCommand; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class LEDWaitingCommandTest extends CommandTestBase { | ||
private static final double kWaitTime = 2.0; | ||
private LEDLoadingWaitCommand ledLoadingWaitCommand; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
super.setUp(); | ||
ledLoadingWaitCommand = new LEDLoadingWaitCommand(kWaitTime); | ||
commandScheduler.schedule(ledLoadingWaitCommand); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
super.tearDown(); | ||
} | ||
|
||
void testLEDLoading(double waitTime) { | ||
double startTime = Timer.getFPGATimestamp(); | ||
for (double i = 0.1; Timer.getFPGATimestamp() - startTime + i < waitTime; i += 0.1) { | ||
Timer.delay(i); | ||
commandScheduler.run(); | ||
testAtTime(ledSubsystem, startTime, waitTime); | ||
} | ||
} | ||
|
||
/** | ||
* This test takes a lot of time as it tries a lot of differently timed {@link | ||
* LEDLoadingWaitCommand}s | ||
*/ | ||
@Test | ||
void testLEDLoading() { | ||
// try multiple wait times, just so we can do it | ||
for (double i = 0.0; i <= 6; i += 1.2) { | ||
commandScheduler.cancelAll(); | ||
commandScheduler.schedule(new LEDLoadingWaitCommand(i)); | ||
commandScheduler.run(); | ||
testLEDLoading(i); | ||
} | ||
} | ||
|
||
@Test | ||
void itActuallyEnds() { | ||
commandScheduler.run(); | ||
assertEquals( | ||
false, | ||
ledLoadingWaitCommand.isFinished(), | ||
"led wait command shouldn't finish before wait time"); | ||
Timer.delay(kWaitTime); // just in case add a little bit extra time | ||
assertEquals( | ||
true, ledLoadingWaitCommand.isFinished(), "led wait command should finish after wait time"); | ||
} | ||
} |