Skip to content

Commit

Permalink
Created working swerve test
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTinker64 committed Sep 1, 2023
1 parent d5688c2 commit 59e7e9d
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/test/java/SwerveModuleTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -51,24 +49,20 @@ void setup() {

@Test
public void testResetEncoders() {
// Arrange percent of a full rotation ↓
subsystem.setDesiredState(new SwerveModuleState(0.5, new Rotation2d(10 * 2.0 * Math.PI)));
// Act
subsystem.resetEncoders();
// Assert
assertEquals(0.0, subsystem.getDrivePosition());
assertEquals(subsystem.getAbsoluteEncoderRad(), subsystem.getTurningPosition());
}

public void testSetStateTemplate(double speedMetersPerSecond, double angle) {
// Arrange
angle *= 2.0 * Math.PI;
SwerveModuleState goalState = new SwerveModuleState(speedMetersPerSecond, new Rotation2d(angle));
// Act
subsystem.setDesiredState(goalState);
@Test
public void testForwardDrive() {
// Act
subsystem.setDesiredState(new SwerveModuleState(0.5, new Rotation2d(0)));
// Assert
assertEquals(speedMetersPerSecond / DriveConstants.kPhysicalMaxSpeedMetersPerSecond, subsystem.getDriveVelocity());
assertTrue(-180 <= subsystem.getTurningPosition() / 360 && subsystem.getTurningPosition() / 360 <= 180);
verify(mockDriveMotor).set(0.5 / DriveConstants.kPhysicalMaxSpeedMetersPerSecond);
verify(mockTurningMotor).set(0.0);
}

@Test
Expand Down

0 comments on commit 59e7e9d

Please sign in to comment.