Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit 3b86061

Browse files
committed
add Autonomous tests
5 tests for the Autonomous command
1 parent 3bff2b9 commit 3b86061

5 files changed

Lines changed: 144 additions & 7 deletions

File tree

Robot2018/.classpath

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="tests"/>
45
<classpathentry kind="var" path="wpilib" sourcepath="wpilib.sources"/>
56
<classpathentry kind="var" path="networktables" sourcepath="networktables.sources"/>
67
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
78
<classpathentry kind="var" path="opencv" sourcepath="opencv.sources"/>
89
<classpathentry kind="var" path="cscore" sourcepath="cscore.sources"/>
910
<classpathentry kind="var" path="wpiutil" sourcepath="wpiutil.sources"/>
11+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
12+
<classpathentry kind="lib" path="libs/jars/mockito-all-1.10.19.jar"/>
1013
<classpathentry kind="output" path="bin"/>
1114
</classpath>
1.18 MB
Binary file not shown.

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/Autonomous.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.usfirst.frc.team199.Robot2018.commands;
22

3+
import java.util.ArrayList;
34
import java.util.Map;
45

56
import edu.wpi.first.wpilibj.command.CommandGroup;
@@ -68,6 +69,9 @@ public String getSDName () {
6869
}
6970
}
7071

72+
double delay;
73+
String scriptName = "";
74+
7175
/**
7276
* Based on the input given, generates a unique script name and executes RunScript with it
7377
*
@@ -79,16 +83,15 @@ public String getSDName () {
7983
* and other side switch, respectively
8084
*/
8185
public Autonomous(Position startPos, Map<String, Strategy> strategies, double delay, String fmsInput) {
82-
String scriptName = "";
83-
84-
scriptName += startPos.getShortName();
85-
8686
Strategy chosenStrat = strategies.get(fmsInput.substring(0, 2));
8787

88-
// skip the next steps if robot is chosen to do nothing
88+
// skip the whole thing if robot is chosen to do nothing
8989
if (chosenStrat == Strategy.NOTHING)
9090
return;
9191

92+
this.delay = delay;
93+
scriptName += startPos.getShortName();
94+
9295
// add switch, switch, and exchange location if going for them, "x" if not
9396
if (chosenStrat == Strategy.SWITCH || chosenStrat == Strategy.SWITCH_EXCHANGE || chosenStrat == Strategy.SWITCH_SCALE)
9497
scriptName += fmsInput.substring(0, 1);
@@ -108,4 +111,20 @@ public Autonomous(Position startPos, Map<String, Strategy> strategies, double de
108111
addSequential(new WaitCommand(delay));
109112
addSequential(new RunScript(scriptName));
110113
}
114+
115+
/**
116+
* Used for testing purposes only
117+
* @return the delay passed into the WaitCommand()
118+
*/
119+
public double getDelay() {
120+
return delay;
121+
}
122+
123+
/**
124+
* Used for testing purposes only
125+
* @return the scriptName passed into RunScriot()
126+
*/
127+
public String getScriptName() {
128+
return scriptName;
129+
}
111130
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/RunScript.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
import edu.wpi.first.wpilibj.command.WaitCommand;
1111

1212
/**
13-
* Gets the script name and runs the script.
13+
* Gets the script name and interprets the script into individual commands.
1414
*/
1515
public class RunScript extends CommandGroup implements RunScriptInterface {
1616

1717
public RunScript(String scriptName) {
1818
// make sure to uncomment this when autoScripts is written
19-
ArrayList<String> script = null; // Robot.autoScripts.getOrDefault(scriptName, new ArrayList<String>());
19+
ArrayList<String> script = new ArrayList<String>(); // Robot.autoScripts.getOrDefault(scriptName, new ArrayList<String>());
2020

2121
outerloop:
2222
for(String cmd : script) {
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package org.usfirst.frc.team199.Robot2018;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import org.junit.jupiter.api.Test;
6+
import org.usfirst.frc.team199.Robot2018.commands.Autonomous;
7+
import org.usfirst.frc.team199.Robot2018.commands.Autonomous.Position;
8+
import org.usfirst.frc.team199.Robot2018.commands.Autonomous.Strategy;
9+
10+
import java.util.HashMap;
11+
import java.util.Map;
12+
13+
class TestAutonomous {
14+
15+
@Test
16+
void mansNotHot() {
17+
assertEquals(4, 2+2);
18+
assertEquals(3, 4-1);
19+
}
20+
21+
@Test
22+
void test0() {
23+
Map<String, Autonomous.Strategy> strats = new HashMap<String, Autonomous.Strategy>();
24+
25+
strats.put("LL", Strategy.NOTHING);
26+
strats.put("LR", Strategy.NOTHING);
27+
strats.put("RL", Strategy.NOTHING);
28+
strats.put("RR", Strategy.NOTHING);
29+
30+
Position pos = Position.LEFT;
31+
String fmsInput = "LLL";
32+
double delay = 0;
33+
34+
Autonomous testAuto = new Autonomous(pos, strats, delay, fmsInput);
35+
36+
assertEquals("", testAuto.getScriptName());
37+
assertEquals(delay, testAuto.getDelay());
38+
}
39+
40+
@Test
41+
void test1() {
42+
Map<String, Autonomous.Strategy> strats = new HashMap<String, Autonomous.Strategy>();
43+
44+
strats.put("LL", Strategy.NOTHING);
45+
strats.put("LR", Strategy.AUTO_LINE);
46+
strats.put("RL", Strategy.NOTHING);
47+
strats.put("RR", Strategy.NOTHING);
48+
49+
Position pos = Position.RIGHT;
50+
String fmsInput = "LRL";
51+
double delay = 0;
52+
53+
Autonomous testAuto = new Autonomous(pos, strats, delay, fmsInput);
54+
55+
assertEquals("Rxxx", testAuto.getScriptName());
56+
assertEquals(delay, testAuto.getDelay());
57+
}
58+
59+
@Test
60+
void test2() {
61+
Map<String, Autonomous.Strategy> strats = new HashMap<String, Autonomous.Strategy>();
62+
63+
strats.put("LL", Strategy.AUTO_LINE);
64+
strats.put("LR", Strategy.SCALE);
65+
strats.put("RL", Strategy.SWITCH_EXCHANGE);
66+
strats.put("RR", Strategy.SWITCH_SCALE);
67+
68+
Position pos = Position.CENTER;
69+
String fmsInput = "RRL";
70+
double delay = 0;
71+
72+
Autonomous testAuto = new Autonomous(pos, strats, delay, fmsInput);
73+
74+
assertEquals("CRRx", testAuto.getScriptName());
75+
assertEquals(delay, testAuto.getDelay());
76+
}
77+
78+
@Test
79+
void test3() {
80+
Map<String, Autonomous.Strategy> strats = new HashMap<String, Autonomous.Strategy>();
81+
82+
strats.put("LL", Strategy.SWITCH);
83+
strats.put("LR", Strategy.SWITCH_EXCHANGE);
84+
strats.put("RL", Strategy.NOTHING);
85+
strats.put("RR", Strategy.SWITCH_SCALE);
86+
87+
Position pos = Position.LEFT;
88+
String fmsInput = "LLR";
89+
double delay = 0;
90+
91+
Autonomous testAuto = new Autonomous(pos, strats, delay, fmsInput);
92+
93+
assertEquals("LLxx", testAuto.getScriptName());
94+
assertEquals(delay, testAuto.getDelay());
95+
}
96+
97+
@Test
98+
void test4() {
99+
Map<String, Autonomous.Strategy> strats = new HashMap<String, Autonomous.Strategy>();
100+
101+
strats.put("LL", Strategy.SWITCH);
102+
strats.put("LR", Strategy.SWITCH_EXCHANGE);
103+
strats.put("RL", Strategy.SWITCH_SCALE);
104+
strats.put("RR", Strategy.NOTHING);
105+
106+
Position pos = Position.RIGHT;
107+
String fmsInput = "LRR";
108+
double delay = 0;
109+
110+
Autonomous testAuto = new Autonomous(pos, strats, delay, fmsInput);
111+
112+
assertEquals("RLxE", testAuto.getScriptName());
113+
assertEquals(delay, testAuto.getDelay());
114+
}
115+
}

0 commit comments

Comments
 (0)