mirror of
https://github.com/Team4388/Swerve-Drive.git
synced 2026-06-09 00:38:04 -06:00
Initial commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 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.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj2.command.*;
|
||||
import frc4388.robot.subsystems.*;
|
||||
import org.junit.*;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class CommandTest {
|
||||
private CommandScheduler scheduler = null;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
scheduler = CommandScheduler.getInstance();
|
||||
}
|
||||
|
||||
// TODO: Update this to use an actual command. Won't work with inline commands for some reason
|
||||
|
||||
@Test
|
||||
public void testExample() {
|
||||
// Arrange
|
||||
Drive drive = mock(Drive.class);
|
||||
RunCommand command = new RunCommand(() -> drive.driveWithInput(0, 0), drive);
|
||||
|
||||
// Act
|
||||
scheduler.schedule(command);
|
||||
scheduler.run();
|
||||
|
||||
// Assert
|
||||
verify(drive).driveWithInput(0, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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.Spark;
|
||||
import frc4388.robot.Constants.LEDConstants;
|
||||
import frc4388.utility.LEDPatterns;
|
||||
|
||||
/**
|
||||
* Based off the LEDSubsystemTest class
|
||||
*/
|
||||
public class SubsystemTest {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* 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 com.kauailabs.navx.frc.AHRS;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
import frc4388.mocks.MockPigeonIMU;
|
||||
import frc4388.robot.Constants.DriveConstants;
|
||||
|
||||
/**
|
||||
* Based on the RobotGyroUtilityTest class
|
||||
*/
|
||||
public class UtilityTest {
|
||||
private RobotGyro gyroPigeon;
|
||||
private RobotGyro gyroNavX;
|
||||
|
||||
@Test
|
||||
public void testConstructor() {
|
||||
// Arrange
|
||||
MockPigeonIMU pigeon = new MockPigeonIMU(DriveConstants.DRIVE_PIGEON_ID);
|
||||
AHRS navX = mock(AHRS.class);
|
||||
gyroPigeon = new RobotGyro(pigeon);
|
||||
gyroNavX = new RobotGyro(navX);
|
||||
|
||||
// Assert
|
||||
assertEquals(true, gyroPigeon.m_isGyroAPigeon);
|
||||
assertEquals(pigeon, gyroPigeon.getPigeon());
|
||||
assertEquals(null, gyroPigeon.getNavX());
|
||||
assertEquals(false, gyroNavX.m_isGyroAPigeon);
|
||||
assertEquals(navX, gyroNavX.getNavX());
|
||||
assertEquals(null, gyroNavX.getPigeon());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeadingPigeon() {
|
||||
// Arrange
|
||||
MockPigeonIMU pigeon = new MockPigeonIMU(DriveConstants.DRIVE_PIGEON_ID);
|
||||
gyroPigeon = new RobotGyro(pigeon);
|
||||
|
||||
// Act & Assert
|
||||
assertEquals(-90, gyroPigeon.getHeading(270), 0.0001);
|
||||
assertEquals(-45, gyroPigeon.getHeading(315), 0.0001);
|
||||
assertEquals(-60, gyroPigeon.getHeading(-60), 0.0001);
|
||||
assertEquals(30, gyroPigeon.getHeading(30), 0.0001);
|
||||
assertEquals(0, gyroPigeon.getHeading(0), 0.0001);
|
||||
assertEquals(180, gyroPigeon.getHeading(180), 0.0001);
|
||||
assertEquals(-180, gyroPigeon.getHeading(-180), 0.0001);
|
||||
assertEquals(97, gyroPigeon.getHeading(1537), 0.0001);
|
||||
assertEquals(99, gyroPigeon.getHeading(-2781), 0.0001);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user