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

Commit 6526862

Browse files
committed
fixed tests
added f in VelocityPIDController constructors to resolve errors added test to PIDSourceAverageTest to make sure it actually returns the average
1 parent f7c3e56 commit 6526862

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

Robot2018/test/org/usfirst/frc/team199/Robot2018/PIDSourceAverageTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,33 @@ void test2() {
5656
assertEquals(avg.getPIDSourceType(), PIDSourceType.kRate);
5757
}
5858

59+
@Test
60+
void test3() {
61+
62+
PIDSource lEnc = mock(PIDSource.class);
63+
when(lEnc.getPIDSourceType()).thenReturn(PIDSourceType.kDisplacement);
64+
65+
PIDSource rEnc = mock(PIDSource.class);
66+
when(rEnc.getPIDSourceType()).thenReturn(PIDSourceType.kDisplacement);
67+
68+
PIDSourceAverage avg;
69+
try {
70+
avg = new PIDSourceAverage(lEnc, rEnc);
71+
} catch (IllegalArgumentException e) {
72+
avg = new PIDSourceAverage(rEnc, rEnc);
73+
}
74+
assertEquals(avg.getPIDSourceType(), PIDSourceType.kDisplacement);
75+
76+
double leftVal = 2.0;
77+
double rightVal = 3.0;
78+
double avgVal = (leftVal + rightVal) / 2;
79+
80+
assertEquals(avgVal, 2.5);
81+
82+
when(lEnc.pidGet()).thenReturn(leftVal);
83+
when(rEnc.pidGet()).thenReturn(rightVal);
84+
85+
assertEquals(avg.pidGet(), avgVal);
86+
}
87+
5988
}

Robot2018/test/org/usfirst/frc/team199/Robot2018/VelocityPIDControllerTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ void test1() {
3636
double p = 1;
3737
double i = 0.5;
3838
double d = 0.0037;
39-
VelocityPIDController vPID = new VelocityPIDController(p, i, d, source, out);
39+
double f = 1.0 / 17;
40+
VelocityPIDController vPID = new VelocityPIDController(p, i, d, f, source, out);
4041

4142
vPID.set(20);
4243
assertEquals(vPID.get(), 20);
@@ -49,7 +50,8 @@ void test2() {
4950
double p = 1;
5051
double i = 0.5;
5152
double d = 0.0037;
52-
VelocityPIDController vPID = new VelocityPIDController(p, i, d, source, out);
53+
double f = 1.0 / 17;
54+
VelocityPIDController vPID = new VelocityPIDController(p, i, d, f, source, out);
5355

5456
vPID.pidWrite(20);
5557
assertEquals(vPID.getSetpoint(), 20);
@@ -62,7 +64,8 @@ void test3() {
6264
double p = 1;
6365
double i = 0.5;
6466
double d = 0.0037;
65-
VelocityPIDController vPID = new VelocityPIDController(p, i, d, source, out);
67+
double f = 1.0 / 17;
68+
VelocityPIDController vPID = new VelocityPIDController(p, i, d, f, source, out);
6669

6770
vPID.set(20);
6871
assertEquals(vPID.getSetpoint(), 20);

0 commit comments

Comments
 (0)