Add LEDSubsystem Test

This commit is contained in:
Keenan D. Buckley
2020-03-28 23:16:04 -06:00
parent 7cad919e71
commit f06b36e443
2 changed files with 57 additions and 5 deletions
@@ -21,6 +21,7 @@ import frc4388.utility.LEDPatterns;
public class LED extends SubsystemBase {
private float m_currentLED;
private LEDPatterns m_currentPattern;
private Spark m_LEDController;
/**
@@ -29,27 +30,35 @@ public class LED extends SubsystemBase {
public LED(Spark LEDController){
m_LEDController = LEDController;
setPattern(LEDConstants.DEFAULT_PATTERN);
m_LEDController.set(m_currentLED);
updateLED();
System.err.println("In the Beginning, there was Joe.\nAnd he said, 'Let there be LEDs.'\nAnd it was good.");
}
@Override
public void periodic(){
SmartDashboard.putNumber("LED", m_currentLED);
SmartDashboard.putNumber("LED", m_currentPattern.getValue());
}
/**
* Add your docs here.
*/
public void updateLED(){
m_LEDController.set(m_currentLED);
m_LEDController.set(m_currentPattern.getValue());
}
/**
* Add your docs here.
*/
public void setPattern(LEDPatterns pattern){
m_currentLED = pattern.getValue();
m_LEDController.set(m_currentLED);
m_currentPattern = pattern;
m_LEDController.set(m_currentPattern.getValue());
}
/**
* Add your docs here.
* @return
*/
public LEDPatterns getPattern() {
return m_currentPattern;
}
}
@@ -0,0 +1,43 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc4388.robot.subsystems;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import org.junit.*;
import edu.wpi.first.wpilibj.*;
import frc4388.robot.Constants.LEDConstants;
import frc4388.utility.LEDPatterns;
/**
* Add your docs here.
*/
public class LEDSubsystemTest {
Spark ledController = mock(Spark.class);
LED led = new LED(ledController);
@Test
public void testPatterns() {
assertEquals(LEDConstants.DEFAULT_PATTERN.getValue(), led.getPattern().getValue(), 0.0001);
led.setPattern(LEDPatterns.RAINBOW_RAINBOW);
assertEquals(LEDPatterns.RAINBOW_RAINBOW.getValue(), led.getPattern().getValue(), 0.0001);
led.setPattern(LEDPatterns.BLUE_BREATH);
assertEquals(LEDPatterns.BLUE_BREATH.getValue(), led.getPattern().getValue(), 0.0001);
led.setPattern(LEDPatterns.C1_SCANNER);
assertEquals(LEDPatterns.C1_SCANNER.getValue(), led.getPattern().getValue(), 0.0001);
led.setPattern(LEDPatterns.C1_CHASE);
assertEquals(LEDPatterns.C1_CHASE.getValue(), led.getPattern().getValue(), 0.0001);
led.setPattern(LEDPatterns.SOLID_BLACK);
assertEquals(LEDPatterns.SOLID_BLACK.getValue(), led.getPattern().getValue(), 0.0001);
}
}