Skip to content

Commit

Permalink
heck me
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan1522 committed Nov 5, 2024
1 parent 52fbf88 commit 0d45bba
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/java/frc/robot/BuildConstants.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package frc.robot;

/** Automatically generated file containing build version information. */
/**
* Automatically generated file containing build version information.
*/
public final class BuildConstants {
public static final String MAVEN_GROUP = "";
public static final String MAVEN_NAME = "4829-BaseRobotCode-1";
public static final String MAVEN_NAME = "4829-BaseRobotCode";
public static final String VERSION = "unspecified";
public static final int GIT_REVISION = 32;
public static final String GIT_SHA = "71a47d311fd066ba3b76be8d09eff3e03b893cd8";
public static final String GIT_DATE = "2024-10-28 22:21:12 EDT";
public static final String GIT_BRANCH = "docs";
public static final String BUILD_DATE = "2024-10-29 16:56:45 EDT";
public static final long BUILD_UNIX_TIME = 1730235405242L;
public static final int GIT_REVISION = 8;
public static final String GIT_SHA = "52fbf88798bd786d25dffff6b4769182ad9ea51c";
public static final String GIT_DATE = "2024-10-29 17:58:37 EDT";
public static final String GIT_BRANCH = "main";
public static final String BUILD_DATE = "2024-11-05 07:52:13 EST";
public static final long BUILD_UNIX_TIME = 1730811133569L;
public static final int DIRTY = 0;

private BuildConstants() {}
private BuildConstants(){}
}
94 changes: 94 additions & 0 deletions src/test/java/RobotTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

// import com.igknighters.commands.autos.Autos;
// import com.igknighters.constants.ConstValues;
// import com.igknighters.constants.RobotSetup;
// import com.igknighters.constants.RobotSetup.RobotID;
// import com.igknighters.util.RobotExtension.Robo;
import com.pathplanner.lib.commands.PathPlannerAuto;

import edu.wpi.first.hal.AllianceStationID;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.ProxyCommand;

public class RobotTest {

@BeforeEach
protected void startSim() {
GlobalState.setUnitTest(true);
assert HAL.initialize(500, 0);
}

@AfterEach
protected void teardownSim() {
HAL.exitMain();
HAL.shutdown();
GlobalState.restoreDefaultState();
var cmdScheduler = CommandScheduler.getInstance();
cmdScheduler.cancelAll();
cmdScheduler.getActiveButtonLoop().clear();
cmdScheduler.getDefaultButtonLoop().clear();
cmdScheduler.clearComposedCommands();
cmdScheduler.unregisterAllSubsystems();
}

@Test
public void testRobotSetup() {
for (RobotID id : RobotID.values()) {
if (id == RobotID.Unlabeled) {
continue;
}

RobotSetup.testOverrideRobotID(id);

com.igknighters.ConstantHelper.applyRoboConst(ConstValues.class);

new RobotContainer();

CommandScheduler.getInstance().getActiveButtonLoop().clear();
CommandScheduler.getInstance().getDefaultButtonLoop().clear();

System.gc();

Check failure on line 58 in src/test/java/RobotTest.java

View workflow job for this annotation

GitHub Actions / Lint

Do not explicitly trigger a garbage collection.

Calls to `System.gc()`, `Runtime.getRuntime().gc()`, and `System.runFinalization()` are not advised. Code should have the same behavior whether the garbage collection is disabled using the option `-Xdisableexplicitgc` or not. Moreover, "modern" JVMs do a very good job handling garbage collections. If memory usage issues unrelated to memory leaks develop within an application, it should be dealt with JVM options rather than within the code itself. DoNotCallGarbageCollectionExplicitly (Priority: 2, Ruleset: Error Prone) https://docs.pmd-code.org/pmd-doc-7.7.0/pmd_rules_java_errorprone.html#donotcallgarbagecollectionexplicitly
}
}

@Test
public void testAuto(@Robo Robot robot) {
RobotSetup.testOverrideRobotID(RobotID.SIM_CRASH);
Pose2d desiredEndPose = new Pose2d(
new Translation2d(3.0, 7.0),
new Rotation2d());

DriverStationSim.setAllianceStationId(AllianceStationID.Blue1);

// meters
final double translationTolerance = 0.2;

Autos.setAutoOverrideTest(new ProxyCommand(() -> new PathPlannerAuto("1 Meter Auto")));
DriverStationSim.setAutonomous(true);
DriverStationSim.setEnabled(true);

robot.withAutonomousPeriodicTest(robo -> {
boolean isFinished = GlobalState.getLocalizedPose()
.getTranslation()
.getDistance(desiredEndPose.getTranslation()) < translationTolerance;

if (isFinished) {
robo.finishUnitTestRobot();
} else if (robo.getElapsedTime() > 2.5) {
throw new RuntimeException(
"Auto took to long, ended at "
+ GlobalState.getLocalizedPose().toString());
}
});

robot.runTest(3);
}
}

0 comments on commit 0d45bba

Please sign in to comment.