Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public double getRawAxis(int axis) {
* @param pov The POV to read
* @return The value of the POV
*/
public double getPOV(int pov) {
public int getPOV(int pov) {
if (SafeMode.isEnabled() && safeDisabledPOV.containsKey(pov) && safeDisabledPOV.get(pov).contains(unsafeJoystick.getPOV(pov))) {
return -1;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import static org.junit.Assert.assertEquals;

import org.carlmontrobotics.lib199.testUtils.ErrStreamTest;
import org.carlmontrobotics.lib199.testUtils.SimDeviceTestRule;
import org.carlmontrobotics.lib199.testUtils.TestRules;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

public class MotorControllerFactoryTest extends ErrStreamTest {

@ClassRule
public static SimDeviceTestRule.Class simClassRule = new SimDeviceTestRule.Class();
public static TestRules.InitializeHAL simClassRule = new TestRules.InitializeHAL();
@Rule
public SimDeviceTestRule.Test simTestRule = new SimDeviceTestRule.Test();
public TestRules.ResetSimDeviceSimData simTestRule = new TestRules.ResetSimDeviceSimData();

@Test
// AutoClosable.close() throws Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

import static org.junit.Assert.*;

import org.carlmontrobotics.lib199.testUtils.TestRules;
import org.junit.ClassRule;
import org.junit.Test;

import edu.wpi.first.wpilibj.GenericHID;

public class SafeJoystickTest {

@ClassRule
public static TestRules.InitializeHAL classRule = new TestRules.InitializeHAL();

@Test
public void testSafeJoystick() {
GenericHID normalJoystick = createDummyJoystick(0);
GenericHID unsafeJoystick1 = createDummyJoystick(1);
Expand Down Expand Up @@ -85,7 +93,7 @@ public void testSafeJoystick() {
assertTrue(safeJoystick1.getRawButton(1));
assertTrue(safeJoystick1.getRawButtonPressed(1));
assertTrue(safeJoystick1.getRawButtonReleased(1));
assertEquals(0.5, safeJoystick1.getRawAxis(0), 0.01);
assertEquals(0.0, safeJoystick1.getRawAxis(0), 0.01);
assertEquals(0.5, safeJoystick1.getRawAxis(1), 0.01);
assertEquals(1.0, safeJoystick1.getRawAxis(2), 0.01);
assertEquals(-1, safeJoystick1.getPOV(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@

import java.util.function.Function;

import org.carlmontrobotics.lib199.testUtils.TestRules;
import org.junit.ClassRule;
import org.junit.Test;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;

public class SafeModeCommandsTest {

@ClassRule
public static TestRules.InitializeHAL classRule = new TestRules.InitializeHAL();

@Test
public void testSafeCommand() {
testCommand(SafeCommand::new, true, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import java.util.function.LongSupplier;
import java.util.function.Supplier;

import org.carlmontrobotics.lib199.testUtils.TestRules;
import org.junit.ClassRule;
import org.junit.Test;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandScheduler;

public class SafeModeTest {

@ClassRule
public static TestRules.InitializeHAL classRule = new TestRules.InitializeHAL();
// Test SafeMode.java using JUnit

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import org.carlmontrobotics.lib199.Mocks;
import org.carlmontrobotics.lib199.testUtils.SafelyClosable;
import org.carlmontrobotics.lib199.testUtils.SimDeviceTestRule;
import org.carlmontrobotics.lib199.testUtils.TestRules;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -20,9 +20,9 @@
public abstract class MockPheonixControllerTest {

@ClassRule
public static SimDeviceTestRule.Class simClassRule = new SimDeviceTestRule.Class();
public static TestRules.InitializeHAL simClassRule = new TestRules.InitializeHAL();
@Rule
public SimDeviceTestRule.Test simTestRule = new SimDeviceTestRule.Test();
public TestRules.ResetSimDeviceSimData simTestRule = new TestRules.ResetSimDeviceSimData();

protected abstract BaseMotorController createController(int portPWM);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.carlmontrobotics.lib199.Mocks;
import org.carlmontrobotics.lib199.REVLibErrorAnswer;
import org.carlmontrobotics.lib199.testUtils.SafelyClosable;
import org.carlmontrobotics.lib199.testUtils.SimDeviceTestRule;
import org.carlmontrobotics.lib199.testUtils.TestRules;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -24,9 +24,9 @@
public class MockedSparkEncoderTest {

@ClassRule
public static SimDeviceTestRule.Class simClassRule = new SimDeviceTestRule.Class();
public static TestRules.InitializeHAL simClassRule = new TestRules.InitializeHAL();
@Rule
public SimDeviceTestRule.Test simTestRule = new SimDeviceTestRule.Test();
public TestRules.ResetSimDeviceSimData simTestRule = new TestRules.ResetSimDeviceSimData();

@Test
public void testDeviceCreation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.SimDeviceSim;

public class SimDeviceTestRule {
public class TestRules {

public static class Class implements TestRule {
public static class InitializeHAL implements TestRule {
@Override
public Statement apply(Statement base, Description description) {
return new Statement(){
@Override
public void evaluate() throws Throwable {
// HAL must be initialized or SimDeviceSim.resetData() will crash
// HAL must be initialized or SimDeviceSim.resetData() will crash and SmartDashboard might not work.
HAL.initialize(500, 0);
base.evaluate();
HAL.shutdown();
Expand All @@ -24,7 +24,7 @@ public void evaluate() throws Throwable {
}
}

public static class Test implements TestRule {
public static class ResetSimDeviceSimData implements TestRule {
@Override
public Statement apply(Statement base, Description description) {
return new Statement(){
Expand Down