mirror of
https://github.com/Team4388/Robot-Essentials.git
synced 2026-06-09 00:38:01 -06:00
Add LEDSubsystem Test
This commit is contained in:
@@ -21,6 +21,7 @@ import frc4388.utility.LEDPatterns;
|
|||||||
public class LED extends SubsystemBase {
|
public class LED extends SubsystemBase {
|
||||||
|
|
||||||
private float m_currentLED;
|
private float m_currentLED;
|
||||||
|
private LEDPatterns m_currentPattern;
|
||||||
private Spark m_LEDController;
|
private Spark m_LEDController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,27 +30,35 @@ public class LED extends SubsystemBase {
|
|||||||
public LED(Spark LEDController){
|
public LED(Spark LEDController){
|
||||||
m_LEDController = LEDController;
|
m_LEDController = LEDController;
|
||||||
setPattern(LEDConstants.DEFAULT_PATTERN);
|
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.");
|
System.err.println("In the Beginning, there was Joe.\nAnd he said, 'Let there be LEDs.'\nAnd it was good.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void periodic(){
|
public void periodic(){
|
||||||
SmartDashboard.putNumber("LED", m_currentLED);
|
SmartDashboard.putNumber("LED", m_currentPattern.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add your docs here.
|
* Add your docs here.
|
||||||
*/
|
*/
|
||||||
public void updateLED(){
|
public void updateLED(){
|
||||||
m_LEDController.set(m_currentLED);
|
m_LEDController.set(m_currentPattern.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add your docs here.
|
* Add your docs here.
|
||||||
*/
|
*/
|
||||||
public void setPattern(LEDPatterns pattern){
|
public void setPattern(LEDPatterns pattern){
|
||||||
m_currentLED = pattern.getValue();
|
m_currentPattern = pattern;
|
||||||
m_LEDController.set(m_currentLED);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user