Skip to content

Instantly share code, notes, and snippets.

@Muirrum
Last active January 19, 2019 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Muirrum/71109ce6afada076169acce8d11e1567 to your computer and use it in GitHub Desktop.
Save Muirrum/71109ce6afada076169acce8d11e1567 to your computer and use it in GitHub Desktop.
package frc.robot.utilities;
import edu.wpi.first.wpilibj.I2C;
public class FakeI2CBus extends I2C {
public FakeI2CBus(int address) {
super(I2C.Port.kOnboard, address);
}
public byte[] readOnly() {
byte[] buffer = new byte[16];
for (int i = 0; i < buffer.length; i++) {
if (i%2 != 0) {
buffer[i] = 2;
}
}
buffer[0] = 15;
buffer[2] = 14;
buffer[4] = 16;
buffer[6] = 25;
buffer[8] = 26;
buffer[10] = 17;
buffer[12] = 16;
buffer[14] = 15;
buffer[16] = 14;
return buffer;
}
}
package frc.robot.sensors;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import frc.robot.sensors.LineFollowerSensorArray;
import frc.robot.utilities.*;
public class LineFollowerSensorTest {
FakeI2CBus i2cBus = new FakeI2CBus(9);
LineFollowerSensorArray lfs = new LineFollowerSensorArray(i2cBus);
@Test
public void isThereLineTest() {
boolean boolBufTest[] = new boolean[8];
// Set data
boolBufTest[0] = false;
boolBufTest[1] = false;
boolBufTest[2] = false;
boolBufTest[3] = true;
boolBufTest[4] = true;
boolBufTest[5] = false;
boolBufTest[6] = false;
boolBufTest[7] = false;
boolBufTest[8] = false;
boolean[] boolBuf = lfs.isThereLine();
assertArrayEquals(boolBufTest, boolBuf);
}
@Test
public void getSensorReadingTest() {
/*
Needs to:
- pass dummy i2c device
- have dummy i2c device return predefined data
- Make sure math works
*/
System.out.println(lfs.getSensorReading().lineFound);
assertTrue(lfs.getSensorReading().lineFound);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment