Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ dependencies {

testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testImplementation 'org.mockito:mockito-core:5.8.0'
testImplementation 'org.mockito:mockito-junit-jupiter:5.8.0'

def akitJson = new groovy.json.JsonSlurper().parseText(new File(projectDir.getAbsolutePath() + "/vendordeps/AdvantageKit.json").text)
annotationProcessor "org.littletonrobotics.akit:akit-autolog:$akitJson.version"
Expand Down Expand Up @@ -278,4 +280,4 @@ spotless {
indentWithSpaces(2)
endWithNewline()
}
}
}
2 changes: 1 addition & 1 deletion gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions src/test/java/frc/alotobots/ConstantsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* ALOTOBOTS - FRC Team 5152
https://github.com/5152Alotobots
* Copyright (C) 2026 ALOTOBOTS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Source code must be publicly available on GitHub or an alternative web accessible site
*/
package frc.alotobots;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class ConstantsTest {

@Test
void testRobotEnumValues() {
// Verify Robot enum has expected values
assertEquals(2, Constants.Robot.values().length);
assertNotNull(Constants.Robot.COMPETITION);
assertNotNull(Constants.Robot.DEV);
}

@Test
void testModeEnumValues() {
// Verify Mode enum has expected values
assertEquals(3, Constants.Mode.values().length);
assertNotNull(Constants.Mode.REAL);
assertNotNull(Constants.Mode.SIM);
assertNotNull(Constants.Mode.REPLAY);
}

@Test
void testCurrentRobotIsNotNull() {
assertNotNull(Constants.currentRobot);
}

@Test
void testCurrentModeIsNotNull() {
assertNotNull(Constants.currentMode);
}

@Test
void testSimModeIsNotNull() {
assertNotNull(Constants.simMode);
}

@Test
void testTunerConstantsIsNotNull() {
assertNotNull(Constants.tunerConstants);
}

@Test
void testCanIdConstants() {
// Verify CAN bus constants
assertNotNull(Constants.CanId.SWERVE_CAN_BUS);
assertNotNull(Constants.CanId.RIO_CAN_BUS);

// Verify CAN frequency is positive
assertTrue(Constants.CanId.DEFAULT_CAN_FREQUENCY > 0);

// Verify PDH CAN ID
assertEquals(1, Constants.CanId.PDH_CAN_ID);

// Verify other CAN IDs are in valid range (1-63)
assertTrue(Constants.CanId.CANDLE_CAN_ID >= 1 && Constants.CanId.CANDLE_CAN_ID <= 63);
assertTrue(Constants.CanId.CLIMBER_CAN_ID >= 1 && Constants.CanId.CLIMBER_CAN_ID <= 63);
assertTrue(
Constants.CanId.INTAKE_EXTENDO_CAN_ID >= 1 && Constants.CanId.INTAKE_EXTENDO_CAN_ID <= 63);
assertTrue(
Constants.CanId.INTAKE_ROLLER_CAN_ID >= 1 && Constants.CanId.INTAKE_ROLLER_CAN_ID <= 63);
assertTrue(Constants.CanId.CONVEYOR_CAN_ID >= 1 && Constants.CanId.CONVEYOR_CAN_ID <= 63);
assertTrue(Constants.CanId.TURRET_CAN_ID >= 1 && Constants.CanId.TURRET_CAN_ID <= 63);
assertTrue(
Constants.CanId.DEFLECTOR_MOTOR_CAN_ID >= 1
&& Constants.CanId.DEFLECTOR_MOTOR_CAN_ID <= 63);
assertTrue(
Constants.CanId.SHOOTER_LEFT_CAN_ID >= 1 && Constants.CanId.SHOOTER_LEFT_CAN_ID <= 63);
assertTrue(
Constants.CanId.SHOOTER_RIGHT_CAN_ID >= 1 && Constants.CanId.SHOOTER_RIGHT_CAN_ID <= 63);
assertTrue(Constants.CanId.KICKER_CAN_ID >= 1 && Constants.CanId.KICKER_CAN_ID <= 63);
assertTrue(
Constants.CanId.DEFLECTOR_ENCODER_CAN_ID >= 1
&& Constants.CanId.DEFLECTOR_ENCODER_CAN_ID <= 63);
}

@Test
void testCanIdUniqueness() {
// Verify all motor CAN IDs are unique
int[] motorIds = {
Constants.CanId.CLIMBER_CAN_ID,
Constants.CanId.INTAKE_EXTENDO_CAN_ID,
Constants.CanId.INTAKE_ROLLER_CAN_ID,
Constants.CanId.CONVEYOR_CAN_ID,
Constants.CanId.TURRET_CAN_ID,
Constants.CanId.DEFLECTOR_MOTOR_CAN_ID,
Constants.CanId.SHOOTER_LEFT_CAN_ID,
Constants.CanId.SHOOTER_RIGHT_CAN_ID,
Constants.CanId.KICKER_CAN_ID
};

for (int i = 0; i < motorIds.length; i++) {
for (int j = i + 1; j < motorIds.length; j++) {
assertNotEquals(motorIds[i], motorIds[j], "CAN IDs must be unique");
}
}
}

@Test
void testDIOConstants() {
// Verify DIO channel is in valid range (0-25 for RoboRIO 2.0)
assertTrue(
Constants.DIO.TURRET_RESET_LIMIT_SWITCH_CHANNEL >= 0
&& Constants.DIO.TURRET_RESET_LIMIT_SWITCH_CHANNEL <= 25);
}

@Test
void testCurrentRobotMatchesTunerConstants() {
// Verify that tuner constants are initialized based on current robot
assertNotNull(Constants.tunerConstants);
}
}
92 changes: 92 additions & 0 deletions src/test/java/frc/alotobots/OITest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* ALOTOBOTS - FRC Team 5152
https://github.com/5152Alotobots
* Copyright (C) 2026 ALOTOBOTS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Source code must be publicly available on GitHub or an alternative web accessible site
*/
package frc.alotobots;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class OITest {

@Test
void testDeadbandValue() {
// Verify deadband is a reasonable value
assertTrue(OI.DEADBAND > 0.0);
assertTrue(OI.DEADBAND < 0.2); // Typical deadband is less than 0.2
}

@Test
void testAxisLimits() {
// Verify axis limits are correct
assertEquals(1.0, OI.AxisLimits.MAX_AXIS_LIMIT, 0.001);
assertEquals(-1.0, OI.AxisLimits.MIN_AXIS_LIMIT, 0.001);
}

@Test
void testHasDriverInputTriggerExists() {
// Verify hasDriverInput trigger is not null
assertNotNull(OI.hasDriverInput);
}

@Test
void testButtonTriggersExist() {
// Verify all button triggers are not null
assertNotNull(OI.resetGyroButton);
assertNotNull(OI.retractClimber);
assertNotNull(OI.extendClimber);
assertNotNull(OI.intakeOut);
assertNotNull(OI.intakeIn);
assertNotNull(OI.intake);
assertNotNull(OI.shoot);
assertNotNull(OI.rotateTurretRight);
assertNotNull(OI.rotateTurretLeft);
assertNotNull(OI.turretAimPass);
assertNotNull(OI.turretAimShoot);
}

@Test
void testTurretAxisReturnsValidRange() {
// Test that getTurretAxis returns a value (even if it's 0 in test environment)
double axis = OI.getTurretAxis();
assertTrue(
axis >= OI.AxisLimits.MIN_AXIS_LIMIT && axis <= OI.AxisLimits.MAX_AXIS_LIMIT,
"Turret axis should be within valid range");
}

@Test
void testAxisMethodsReturnValues() {
// These methods should return values without throwing exceptions
assertDoesNotThrow(() -> OI.getTranslateForwardAxis());
assertDoesNotThrow(() -> OI.getTranslateStrafeAxis());
assertDoesNotThrow(() -> OI.getRotationAxis());
assertDoesNotThrow(() -> OI.getTurtleSpeedTrigger());
assertDoesNotThrow(() -> OI.getTurboSpeedTrigger());
assertDoesNotThrow(() -> OI.getTurretAxis());
}

@Test
void testAxisMethodsReturnValidRange() {
// In test environment, these should return 0 but be within valid range
double translateForward = OI.getTranslateForwardAxis();
double translateStrafe = OI.getTranslateStrafeAxis();
double rotation = OI.getRotationAxis();
double turtleSpeed = OI.getTurtleSpeedTrigger();
double turboSpeed = OI.getTurboSpeedTrigger();

assertTrue(translateForward >= -1.0 && translateForward <= 1.0);
assertTrue(translateStrafe >= -1.0 && translateStrafe <= 1.0);
assertTrue(rotation >= -1.0 && rotation <= 1.0);
assertTrue(turtleSpeed >= 0.0 && turtleSpeed <= 1.0);
assertTrue(turboSpeed >= 0.0 && turboSpeed <= 1.0);
}
}
61 changes: 61 additions & 0 deletions src/test/java/frc/alotobots/RobotContainerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* ALOTOBOTS - FRC Team 5152
https://github.com/5152Alotobots
* Copyright (C) 2026 ALOTOBOTS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Source code must be publicly available on GitHub or an alternative web accessible site
*/
package frc.alotobots;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class RobotContainerTest {

@Test
void testRobotContainerCanBeInstantiated() {
assertDoesNotThrow(() -> new RobotContainer());
}

@Test
void testGetAutonomousCommand() {
RobotContainer container = new RobotContainer();
// Should return a command (may be null if no auto selected)
assertDoesNotThrow(() -> container.getAutonomousCommand());
}

@Test
void testResetSimulationFieldDoesNotThrow() {
RobotContainer container = new RobotContainer();
assertDoesNotThrow(() -> container.resetSimulationField());
}

@Test
void testDisplaySimFieldToAdvantageScopeDoesNotThrow() {
RobotContainer container = new RobotContainer();
assertDoesNotThrow(() -> container.displaySimFieldToAdvantageScope());
}

@Test
void testMultipleInstantiation() {
// Test that multiple instances can be created (though typically only one exists)
assertDoesNotThrow(
() -> {
new RobotContainer();
new RobotContainer();
});
}

@Test
void testAutonomousCommandIsNotNullAfterInstantiation() {
RobotContainer container = new RobotContainer();
// Get autonomous command should not throw
assertDoesNotThrow(() -> container.getAutonomousCommand());
}
}
Loading
Loading