Skip to content

Commit 2bb999b

Browse files
author
James Hagborg
committed
Test for loop runs correctly on multiple runs
This implies that the while loop is working correctly too
1 parent f7c84a6 commit 2bb999b

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/test/java/org/usfirst/frc/team69/util/oi/test/ForCommandTest.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.concurrent.TimeUnit;
66

7+
import org.junit.Before;
78
import org.junit.BeforeClass;
89
import org.junit.Rule;
910
import org.junit.Test;
@@ -21,24 +22,36 @@ public class ForCommandTest {
2122
@Rule
2223
public Timeout globalTimeout = new Timeout(100, TimeUnit.MILLISECONDS);
2324

25+
private MockCommand mockCommand;
26+
private Command loopCommand;
27+
2428
@BeforeClass
2529
public static void setUpBeforeClass() throws Exception {
2630
UnitTestUtility.setupMockBase();
2731
}
2832

29-
@Test
30-
public void testForLoop() {
31-
MockCommand mockCommand = new MockCommand();
33+
@Before
34+
public void setUp() {
35+
mockCommand = new MockCommand();
3236
mockCommand.setHasFinished(true);
33-
Command loopCommand = new CommandBuilder()
37+
loopCommand = new CommandBuilder()
3438
.forLoop(10, mockCommand)
3539
.build();
40+
Scheduler.getInstance().removeAll();
41+
}
42+
43+
private void runLoopOnce() {
3644
loopCommand.start();
3745
Scheduler.getInstance().run();
3846

3947
while (loopCommand.isRunning()) {
4048
Scheduler.getInstance().run();
4149
}
50+
}
51+
52+
@Test
53+
public void testForLoop() {
54+
runLoopOnce();
4255

4356
assertEquals(10, mockCommand.getExecuteCount());
4457
assertEquals(10, mockCommand.getIsFinishedCount());
@@ -47,4 +60,15 @@ public void testForLoop() {
4760
assertEquals(0, mockCommand.getInterruptedCount());
4861
}
4962

63+
@Test
64+
public void testMultipleRuns() {
65+
runLoopOnce();
66+
runLoopOnce();
67+
68+
assertEquals(20, mockCommand.getExecuteCount());
69+
assertEquals(20, mockCommand.getIsFinishedCount());
70+
assertEquals(20, mockCommand.getInitializeCount());
71+
assertEquals(20, mockCommand.getEndCount());
72+
assertEquals(0, mockCommand.getInterruptedCount());
73+
}
5074
}

0 commit comments

Comments
 (0)