mirror of
https://github.com/Team4388/Robot-Essentials.git
synced 2026-06-09 00:38:01 -06:00
Add Subsystem Test Template
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* 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.utility;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
import edu.wpi.first.wpilibj.*;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add your docs here.
|
||||||
|
*/
|
||||||
|
public class UtilityTest {
|
||||||
|
@Test
|
||||||
|
public void testConstructor() {
|
||||||
|
// Arrange
|
||||||
|
Spark ledController = mock(Spark.class);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
LED led = new LED(ledController);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertEquals(LEDConstants.DEFAULT_PATTERN.getValue(), led.getPattern().getValue(), 0.0001);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPatterns() {
|
||||||
|
// Arrange
|
||||||
|
Spark ledController = mock(Spark.class);
|
||||||
|
LED led = new LED(ledController);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
led.setPattern(LEDPatterns.RAINBOW_RAINBOW);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertEquals(LEDPatterns.RAINBOW_RAINBOW.getValue(), led.getPattern().getValue(), 0.0001);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
led.setPattern(LEDPatterns.BLUE_BREATH);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertEquals(LEDPatterns.BLUE_BREATH.getValue(), led.getPattern().getValue(), 0.0001);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
led.setPattern(LEDPatterns.SOLID_BLACK);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertEquals(LEDPatterns.SOLID_BLACK.getValue(), led.getPattern().getValue(), 0.0001);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void wait(int millis) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(millis);
|
||||||
|
} catch (Exception e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,24 +18,46 @@ import frc4388.utility.LEDPatterns;
|
|||||||
* Add your docs here.
|
* Add your docs here.
|
||||||
*/
|
*/
|
||||||
public class LEDSubsystemTest {
|
public class LEDSubsystemTest {
|
||||||
Spark ledController = mock(Spark.class);
|
@Test
|
||||||
LED led = new LED(ledController);
|
public void testConstructor() {
|
||||||
|
// Arrange
|
||||||
|
Spark ledController = mock(Spark.class);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
LED led = new LED(ledController);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
assertEquals(LEDConstants.DEFAULT_PATTERN.getValue(), led.getPattern().getValue(), 0.0001);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPatterns() {
|
public void testPatterns() {
|
||||||
// TEST 1
|
// Arrange
|
||||||
assertEquals(LEDConstants.DEFAULT_PATTERN.getValue(), led.getPattern().getValue(), 0.0001);
|
Spark ledController = mock(Spark.class);
|
||||||
|
LED led = new LED(ledController);
|
||||||
|
|
||||||
// TEST 2
|
// Act
|
||||||
led.setPattern(LEDPatterns.RAINBOW_RAINBOW);
|
led.setPattern(LEDPatterns.RAINBOW_RAINBOW);
|
||||||
|
|
||||||
|
// Assert
|
||||||
assertEquals(LEDPatterns.RAINBOW_RAINBOW.getValue(), led.getPattern().getValue(), 0.0001);
|
assertEquals(LEDPatterns.RAINBOW_RAINBOW.getValue(), led.getPattern().getValue(), 0.0001);
|
||||||
|
|
||||||
// TEST 3
|
// Act
|
||||||
led.setPattern(LEDPatterns.BLUE_BREATH);
|
led.setPattern(LEDPatterns.BLUE_BREATH);
|
||||||
|
|
||||||
|
// Assert
|
||||||
assertEquals(LEDPatterns.BLUE_BREATH.getValue(), led.getPattern().getValue(), 0.0001);
|
assertEquals(LEDPatterns.BLUE_BREATH.getValue(), led.getPattern().getValue(), 0.0001);
|
||||||
|
|
||||||
// TEST 4
|
// Act
|
||||||
led.setPattern(LEDPatterns.SOLID_BLACK);
|
led.setPattern(LEDPatterns.SOLID_BLACK);
|
||||||
|
|
||||||
|
// Assert
|
||||||
assertEquals(LEDPatterns.SOLID_BLACK.getValue(), led.getPattern().getValue(), 0.0001);
|
assertEquals(LEDPatterns.SOLID_BLACK.getValue(), led.getPattern().getValue(), 0.0001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void wait(int millis) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(millis);
|
||||||
|
} catch (Exception e) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user