4
4
5
5
package frc .lib ;
6
6
7
+ import static edu .wpi .first .wpilibj2 .command .Commands .*;
7
8
import static frc .lib .UnitTestingUtil .*;
8
9
10
+ import edu .wpi .first .wpilibj .DriverStation ;
9
11
import edu .wpi .first .wpilibj2 .command .Command ;
10
- import edu . wpi . first . wpilibj2 . command . Commands ;
12
+ import frc . lib . FaultsTable . Fault ;
11
13
import frc .lib .FaultsTable .FaultType ;
12
14
import java .util .function .BiConsumer ;
13
15
import org .junit .jupiter .api .AfterEach ;
17
19
public class AdvancedSubsystemTest {
18
20
static final double DELTA = 1e-2 ; // acceptable deviation range
19
21
20
- private TestImpl sub = new TestImpl () ;
22
+ private TestImpl _sub ;
21
23
22
24
@ BeforeEach
23
25
public void setup () {
24
26
setupTests ();
27
+
28
+ _sub = new TestImpl ();
25
29
}
26
30
27
31
@ AfterEach
28
32
public void close () throws Exception {
29
- reset (sub );
33
+ reset (_sub );
34
+ }
35
+
36
+ @ Test
37
+ public void robotIsEnabled () {
38
+ assert DriverStation .isEnabled ();
30
39
}
31
40
32
41
@ Test
33
42
public void subsystemSelfCheck () {
34
- // TODO
43
+ runToCompletion (_sub .fullSelfCheck ());
44
+
45
+ // should give FAULT 1 error
46
+ assert _sub .hasError ();
47
+
48
+ // should only give FAULT 1 error and stop there
49
+ assert _sub .getFaults ().contains (new Fault ("FAULT 1" , FaultType .ERROR ));
50
+ assert !_sub .getFaults ().contains (new Fault ("FAULT 2" , FaultType .ERROR ));
35
51
}
36
52
37
53
public class TestImpl extends AdvancedSubsystem {
@@ -54,16 +70,16 @@ public double getEncoderSpeed() {
54
70
55
71
@ Override
56
72
public Command selfCheck (BiConsumer <String , FaultType > faultAdder ) {
57
- return Commands . sequence (
58
- Commands . runOnce (
73
+ return sequence (
74
+ runOnce (
59
75
() -> {
60
76
if (_fault1 ) faultAdder .accept ("FAULT 1" , FaultType .ERROR );
61
77
}),
62
- Commands . runOnce (
78
+ runOnce (
63
79
() -> {
64
80
if (_fault2 ) faultAdder .accept ("FAULT 2" , FaultType .ERROR );
65
81
}),
66
- Commands . runOnce (
82
+ runOnce (
67
83
() -> {
68
84
if (_fault3 ) faultAdder .accept ("FAULT 3" , FaultType .WARNING );
69
85
}));
@@ -77,13 +93,16 @@ public double speed() {
77
93
78
94
@ Override
79
95
public Command selfCheck (BiConsumer <String , FaultType > faultAdder ) {
80
- return Commands . sequence (
96
+ return sequence (
81
97
_io .selfCheck (faultAdder ), // self check io devices first
82
98
runOnce (
83
99
() -> {
84
100
if (speed () < 2 ) faultAdder .accept ("TOO SLOW" , FaultType .WARNING );
85
101
}) // then check the whole subsystem
86
102
);
87
103
}
104
+
105
+ @ Override
106
+ public void close () throws Exception {}
88
107
}
89
108
}
0 commit comments