[build] Apply spotless for java formatting (#1768)

Update checkstyle config to be compatible with spotless.

Co-authored-by: Austin Shalit <austinshalit@gmail.com>
This commit is contained in:
Peter Johnson
2020-12-29 22:45:16 -08:00
committed by GitHub
parent e563a0b7db
commit a751fa22d2
883 changed files with 16526 additions and 17751 deletions

View File

@@ -4,21 +4,19 @@
package edu.wpi.first.wpilibj;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj.util.Color8Bit;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj.util.Color8Bit;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class AddressableLEDBufferTest {
@ParameterizedTest
@MethodSource("hsvToRgbProvider")
@@ -29,8 +27,7 @@ class AddressableLEDBufferTest {
assertAll(
() -> assertEquals((byte) r, buffer.m_buffer[2], "R value didn't match"),
() -> assertEquals((byte) g, buffer.m_buffer[1], "G value didn't match"),
() -> assertEquals((byte) b, buffer.m_buffer[0], "B value didn't match")
);
() -> assertEquals((byte) b, buffer.m_buffer[0], "B value didn't match"));
}
static Stream<Arguments> hsvToRgbProvider() {
@@ -51,7 +48,7 @@ class AddressableLEDBufferTest {
arguments(150, 255, 128, 128, 0, 127), // Purple (ish)
arguments(90, 255, 128, 0, 127, 128), // Teal (ish)
arguments(120, 255, 128, 0, 0, 128) // Navy
);
);
}
@Test

View File

@@ -4,17 +4,15 @@
package edu.wpi.first.wpilibj;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.params.provider.Arguments.arguments;
class DriverStationTest {
@ParameterizedTest
@MethodSource("isConnectedProvider")
@@ -30,13 +28,12 @@ class DriverStationTest {
static Stream<Arguments> isConnectedProvider() {
return Stream.of(
arguments(0, 0, 0, false),
arguments(1, 0, 0, true),
arguments(0, 1, 0, true),
arguments(0, 0, 1, true),
arguments(1, 1, 1, true),
arguments(4, 10, 1, true)
);
arguments(0, 0, 0, false),
arguments(1, 0, 0, true),
arguments(0, 1, 0, true),
arguments(0, 0, 1, true),
arguments(1, 1, 1, true),
arguments(4, 10, 1, true));
}
@MethodSource("connectionWarningProvider")
@@ -45,16 +42,14 @@ class DriverStationTest {
DriverStationSim.notifyNewData();
DriverStation.getInstance().silenceJoystickConnectionWarning(silence);
assertEquals(expected,
DriverStation.getInstance().isJoystickConnectionWarningSilenced());
assertEquals(expected, DriverStation.getInstance().isJoystickConnectionWarningSilenced());
}
static Stream<Arguments> connectionWarningProvider() {
return Stream.of(
arguments(false, true, true),
arguments(false, false, false),
arguments(true, true, false),
arguments(true, false, false)
);
arguments(false, true, true),
arguments(false, false, false),
arguments(true, true, false),
arguments(true, false, false));
}
}

View File

@@ -4,12 +4,11 @@
package edu.wpi.first.wpilibj;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.JoystickSim;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class JoystickTest {
@Test

View File

@@ -4,13 +4,12 @@
package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
public final class MockHardwareExtension implements BeforeAllCallback {
private static ExtensionContext getRoot(ExtensionContext context) {
return context.getParent().map(MockHardwareExtension::getRoot).orElse(context);
@@ -18,10 +17,15 @@ public final class MockHardwareExtension implements BeforeAllCallback {
@Override
public void beforeAll(ExtensionContext context) {
getRoot(context).getStore(Namespace.GLOBAL).getOrComputeIfAbsent("HAL Initialized", key -> {
initializeHardware();
return true;
}, Boolean.class);
getRoot(context)
.getStore(Namespace.GLOBAL)
.getOrComputeIfAbsent(
"HAL Initialized",
key -> {
initializeHardware();
return true;
},
Boolean.class);
}
private void initializeHardware() {

View File

@@ -4,6 +4,14 @@
package edu.wpi.first.wpilibj;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
@@ -11,7 +19,6 @@ import java.nio.file.Path;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Stream;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@@ -22,15 +29,6 @@ import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
class PreferencesTest {
private final Preferences m_prefs = Preferences.getInstance();
private final NetworkTable m_table = NetworkTableInstance.getDefault().getTable("Preferences");
@@ -73,8 +71,9 @@ class PreferencesTest {
Set<String> keys = m_table.getKeys();
keys.remove(".type");
assertTrue(keys.isEmpty(), "Preferences was not empty! Preferences in table: "
+ Arrays.toString(keys.toArray()));
assertTrue(
keys.isEmpty(),
"Preferences was not empty! Preferences in table: " + Arrays.toString(keys.toArray()));
}
@ParameterizedTest
@@ -97,8 +96,7 @@ class PreferencesTest {
() -> assertEquals("Hello. How are you?", m_prefs.getString("checkedValueString", "")),
() -> assertEquals(2, m_prefs.getInt("checkedValueInt", 0)),
() -> assertEquals(3.14, m_prefs.getFloat("checkedValueFloat", 0), 1e-6),
() -> assertFalse(m_prefs.getBoolean("checkedValueBoolean", true))
);
() -> assertFalse(m_prefs.getBoolean("checkedValueBoolean", true)));
}
@Test
@@ -111,8 +109,7 @@ class PreferencesTest {
() -> assertEquals("", m_prefs.getString("checkedValueString", "")),
() -> assertEquals(0, m_prefs.getInt("checkedValueInt", 0)),
() -> assertEquals(0, m_prefs.getFloat("checkedValueFloat", 0), 1e-6),
() -> assertTrue(m_prefs.getBoolean("checkedValueBoolean", true))
);
() -> assertTrue(m_prefs.getBoolean("checkedValueBoolean", true)));
}
@Nested
@@ -126,8 +123,7 @@ class PreferencesTest {
assertAll(
() -> assertEquals(value, m_prefs.getInt(key, -1)),
() -> assertEquals(value, m_table.getEntry(key).getNumber(-1).intValue())
);
() -> assertEquals(value, m_table.getEntry(key).getNumber(-1).intValue()));
}
@Test
@@ -139,8 +135,7 @@ class PreferencesTest {
assertAll(
() -> assertEquals(value, m_prefs.getLong(key, -1)),
() -> assertEquals(value, m_table.getEntry(key).getNumber(-1).longValue())
);
() -> assertEquals(value, m_table.getEntry(key).getNumber(-1).longValue()));
}
@Test
@@ -152,8 +147,7 @@ class PreferencesTest {
assertAll(
() -> assertEquals(value, m_prefs.getFloat(key, -1), 1e-6),
() -> assertEquals(value, m_table.getEntry(key).getNumber(-1).floatValue(), 1e-6)
);
() -> assertEquals(value, m_table.getEntry(key).getNumber(-1).floatValue(), 1e-6));
}
@Test
@@ -165,8 +159,7 @@ class PreferencesTest {
assertAll(
() -> assertEquals(value, m_prefs.getDouble(key, -1), 1e-6),
() -> assertEquals(value, m_table.getEntry(key).getNumber(-1).doubleValue(), 1e-6)
);
() -> assertEquals(value, m_table.getEntry(key).getNumber(-1).doubleValue(), 1e-6));
}
@Test
@@ -178,8 +171,7 @@ class PreferencesTest {
assertAll(
() -> assertEquals(value, m_prefs.getString(key, "")),
() -> assertEquals(value, m_table.getEntry(key).getString(""))
);
() -> assertEquals(value, m_table.getEntry(key).getString("")));
}
@Test
@@ -191,8 +183,7 @@ class PreferencesTest {
assertAll(
() -> assertEquals(value, m_prefs.getBoolean(key, false)),
() -> assertEquals(value, m_table.getEntry(key).getBoolean(false))
);
() -> assertEquals(value, m_table.getEntry(key).getBoolean(false)));
}
}
@@ -203,7 +194,6 @@ class PreferencesTest {
"checkedValueString",
"checkedValueInt",
"checkedValueFloat",
"checkedValueBoolean"
);
"checkedValueBoolean");
}
}

View File

@@ -4,11 +4,11 @@
package edu.wpi.first.wpilibj;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
public class SlewRateLimiterTest {
@Test
void slewRateLimitTest() {

View File

@@ -4,28 +4,32 @@
package edu.wpi.first.wpilibj;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SpeedControllerGroupTest {
private static Stream<Arguments> speedControllerArguments() {
return IntStream.of(1, 2, 3).mapToObj(number -> {
SpeedController[] speedControllers = Stream.generate(MockSpeedController::new)
.limit(number)
.toArray(SpeedController[]::new);
SpeedControllerGroup group = new SpeedControllerGroup(speedControllers[0],
Arrays.copyOfRange(speedControllers, 1, speedControllers.length));
return Arguments.of(group, speedControllers);
});
return IntStream.of(1, 2, 3)
.mapToObj(
number -> {
SpeedController[] speedControllers =
Stream.generate(MockSpeedController::new)
.limit(number)
.toArray(SpeedController[]::new);
SpeedControllerGroup group =
new SpeedControllerGroup(
speedControllers[0],
Arrays.copyOfRange(speedControllers, 1, speedControllers.length));
return Arguments.of(group, speedControllers);
});
}
@ParameterizedTest
@@ -33,15 +37,15 @@ class SpeedControllerGroupTest {
void setTest(final SpeedControllerGroup group, final SpeedController[] speedControllers) {
group.set(1.0);
assertArrayEquals(DoubleStream.generate(() -> 1.0).limit(speedControllers.length).toArray(),
assertArrayEquals(
DoubleStream.generate(() -> 1.0).limit(speedControllers.length).toArray(),
Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(),
0.00005);
}
@ParameterizedTest
@MethodSource("speedControllerArguments")
void getInvertedTest(final SpeedControllerGroup group,
final SpeedController[] speedControllers) {
void getInvertedTest(final SpeedControllerGroup group, final SpeedController[] speedControllers) {
group.setInverted(true);
assertTrue(group.getInverted());
@@ -49,57 +53,59 @@ class SpeedControllerGroupTest {
@ParameterizedTest
@MethodSource("speedControllerArguments")
void setInvertedDoesNotModifySpeedControllersTest(final SpeedControllerGroup group,
final SpeedController[] speedControllers) {
void setInvertedDoesNotModifySpeedControllersTest(
final SpeedControllerGroup group, final SpeedController[] speedControllers) {
group.setInverted(true);
assertArrayEquals(Stream.generate(() -> false).limit(speedControllers.length).toArray(),
assertArrayEquals(
Stream.generate(() -> false).limit(speedControllers.length).toArray(),
Arrays.stream(speedControllers).map(SpeedController::getInverted).toArray());
}
@ParameterizedTest
@MethodSource("speedControllerArguments")
void setInvertedDoesInvertTest(final SpeedControllerGroup group,
final SpeedController[] speedControllers) {
void setInvertedDoesInvertTest(
final SpeedControllerGroup group, final SpeedController[] speedControllers) {
group.setInverted(true);
group.set(1.0);
assertArrayEquals(DoubleStream.generate(() -> -1.0).limit(speedControllers.length).toArray(),
assertArrayEquals(
DoubleStream.generate(() -> -1.0).limit(speedControllers.length).toArray(),
Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(),
0.00005);
}
@ParameterizedTest
@MethodSource("speedControllerArguments")
void disableTest(final SpeedControllerGroup group,
final SpeedController[] speedControllers) {
void disableTest(final SpeedControllerGroup group, final SpeedController[] speedControllers) {
group.set(1.0);
group.disable();
assertArrayEquals(DoubleStream.generate(() -> 0.0).limit(speedControllers.length).toArray(),
assertArrayEquals(
DoubleStream.generate(() -> 0.0).limit(speedControllers.length).toArray(),
Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(),
0.00005);
}
@ParameterizedTest
@MethodSource("speedControllerArguments")
void stopMotorTest(final SpeedControllerGroup group,
final SpeedController[] speedControllers) {
void stopMotorTest(final SpeedControllerGroup group, final SpeedController[] speedControllers) {
group.set(1.0);
group.stopMotor();
assertArrayEquals(DoubleStream.generate(() -> 0.0).limit(speedControllers.length).toArray(),
assertArrayEquals(
DoubleStream.generate(() -> 0.0).limit(speedControllers.length).toArray(),
Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(),
0.00005);
}
@ParameterizedTest
@MethodSource("speedControllerArguments")
void pidWriteTest(final SpeedControllerGroup group,
final SpeedController[] speedControllers) {
void pidWriteTest(final SpeedControllerGroup group, final SpeedController[] speedControllers) {
group.pidWrite(1.0);
assertArrayEquals(DoubleStream.generate(() -> 1.0).limit(speedControllers.length).toArray(),
assertArrayEquals(
DoubleStream.generate(() -> 1.0).limit(speedControllers.length).toArray(),
Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(),
0.00005);
}

View File

@@ -4,18 +4,16 @@
package edu.wpi.first.wpilibj;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
import edu.wpi.first.wpilibj.simulation.SimHooks;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
import edu.wpi.first.wpilibj.simulation.SimHooks;
import static org.junit.jupiter.api.Assertions.assertEquals;
class TimedRobotTest {
class MockRobot extends TimedRobot {
public final AtomicInteger m_robotInitCount = new AtomicInteger(0);
@@ -108,14 +106,16 @@ class TimedRobotTest {
void disabledTest() {
MockRobot robot = new MockRobot();
Thread robotThread = new Thread(() -> {
robot.startCompetition();
});
Thread robotThread =
new Thread(
() -> {
robot.startCompetition();
});
robotThread.start();
DriverStationSim.setEnabled(false);
DriverStationSim.notifyNewData();
SimHooks.stepTiming(0.0); // Wait for Notifiers
SimHooks.stepTiming(0.0); // Wait for Notifiers
assertEquals(1, robot.m_robotInitCount.get());
assertEquals(1, robot.m_simulationInitCount.get());
@@ -178,16 +178,18 @@ class TimedRobotTest {
void autonomousTest() {
MockRobot robot = new MockRobot();
Thread robotThread = new Thread(() -> {
robot.startCompetition();
});
Thread robotThread =
new Thread(
() -> {
robot.startCompetition();
});
robotThread.start();
DriverStationSim.setEnabled(true);
DriverStationSim.setAutonomous(true);
DriverStationSim.setTest(false);
DriverStationSim.notifyNewData();
SimHooks.stepTiming(0.0); // Wait for Notifiers
SimHooks.stepTiming(0.0); // Wait for Notifiers
assertEquals(1, robot.m_robotInitCount.get());
assertEquals(1, robot.m_simulationInitCount.get());
@@ -250,16 +252,18 @@ class TimedRobotTest {
void teleopTest() {
MockRobot robot = new MockRobot();
Thread robotThread = new Thread(() -> {
robot.startCompetition();
});
Thread robotThread =
new Thread(
() -> {
robot.startCompetition();
});
robotThread.start();
DriverStationSim.setEnabled(true);
DriverStationSim.setAutonomous(false);
DriverStationSim.setTest(false);
DriverStationSim.notifyNewData();
SimHooks.stepTiming(0.0); // Wait for Notifiers
SimHooks.stepTiming(0.0); // Wait for Notifiers
assertEquals(1, robot.m_robotInitCount.get());
assertEquals(1, robot.m_simulationInitCount.get());
@@ -322,16 +326,18 @@ class TimedRobotTest {
void testTest() {
MockRobot robot = new MockRobot();
Thread robotThread = new Thread(() -> {
robot.startCompetition();
});
Thread robotThread =
new Thread(
() -> {
robot.startCompetition();
});
robotThread.start();
DriverStationSim.setEnabled(true);
DriverStationSim.setAutonomous(false);
DriverStationSim.setTest(true);
DriverStationSim.notifyNewData();
SimHooks.stepTiming(0.0); // Wait for Notifiers
SimHooks.stepTiming(0.0); // Wait for Notifiers
assertEquals(1, robot.m_robotInitCount.get());
assertEquals(1, robot.m_simulationInitCount.get());
@@ -395,18 +401,22 @@ class TimedRobotTest {
MockRobot robot = new MockRobot();
final AtomicInteger callbackCount = new AtomicInteger(0);
robot.addPeriodic(() -> {
callbackCount.addAndGet(1);
}, 0.01);
robot.addPeriodic(
() -> {
callbackCount.addAndGet(1);
},
0.01);
Thread robotThread = new Thread(() -> {
robot.startCompetition();
});
Thread robotThread =
new Thread(
() -> {
robot.startCompetition();
});
robotThread.start();
DriverStationSim.setEnabled(false);
DriverStationSim.notifyNewData();
SimHooks.stepTiming(0.0); // Wait for Notifiers
SimHooks.stepTiming(0.0); // Wait for Notifiers
assertEquals(0, robot.m_disabledInitCount.get());
assertEquals(0, robot.m_disabledPeriodicCount.get());
@@ -440,9 +450,12 @@ class TimedRobotTest {
MockRobot robot = new MockRobot();
final AtomicInteger callbackCount = new AtomicInteger(0);
robot.addPeriodic(() -> {
callbackCount.addAndGet(1);
}, 0.01, 0.005);
robot.addPeriodic(
() -> {
callbackCount.addAndGet(1);
},
0.01,
0.005);
// Expirations in this test (ms)
//
@@ -451,14 +464,16 @@ class TimedRobotTest {
// 20 | 15
// 40 | 25
Thread robotThread = new Thread(() -> {
robot.startCompetition();
});
Thread robotThread =
new Thread(
() -> {
robot.startCompetition();
});
robotThread.start();
DriverStationSim.setEnabled(false);
DriverStationSim.notifyNewData();
SimHooks.stepTiming(0.0); // Wait for Notifiers
SimHooks.stepTiming(0.0); // Wait for Notifiers
assertEquals(0, robot.m_disabledInitCount.get());
assertEquals(0, robot.m_disabledPeriodicCount.get());

View File

@@ -4,22 +4,21 @@
package edu.wpi.first.wpilibj;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.stream.Stream;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.stream.Stream;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
@SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod")
public abstract class UtilityClassTest<T> {
private final Class<T> m_clazz;
@@ -30,8 +29,7 @@ public abstract class UtilityClassTest<T> {
@Test
public void singleConstructorTest() {
assertEquals(1, m_clazz.getDeclaredConstructors().length,
"More than one constructor defined");
assertEquals(1, m_clazz.getDeclaredConstructors().length, "More than one constructor defined");
}
@Test
@@ -52,7 +50,9 @@ public abstract class UtilityClassTest<T> {
Stream<DynamicTest> publicMethodsStaticTestFactory() {
return Arrays.stream(m_clazz.getDeclaredMethods())
.filter(method -> Modifier.isPublic(method.getModifiers()))
.map(method -> dynamicTest(method.getName(),
() -> assertTrue(Modifier.isStatic(method.getModifiers()))));
.map(
method ->
dynamicTest(
method.getName(), () -> assertTrue(Modifier.isStatic(method.getModifiers()))));
}
}

View File

@@ -4,20 +4,18 @@
package edu.wpi.first.wpilibj;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.SimHooks;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.SimHooks;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class WatchdogTest {
@BeforeEach
void setup() {
@@ -35,9 +33,12 @@ class WatchdogTest {
void enableDisableTest() {
final AtomicInteger watchdogCounter = new AtomicInteger(0);
try (Watchdog watchdog = new Watchdog(0.4, () -> {
watchdogCounter.addAndGet(1);
})) {
try (Watchdog watchdog =
new Watchdog(
0.4,
() -> {
watchdogCounter.addAndGet(1);
})) {
// Run 1
watchdog.enable();
SimHooks.stepTiming(0.2);
@@ -51,8 +52,8 @@ class WatchdogTest {
SimHooks.stepTiming(0.4);
watchdog.disable();
assertEquals(1, watchdogCounter.get(),
"Watchdog either didn't trigger or triggered more than once");
assertEquals(
1, watchdogCounter.get(), "Watchdog either didn't trigger or triggered more than once");
// Run 3
watchdogCounter.set(0);
@@ -60,8 +61,8 @@ class WatchdogTest {
SimHooks.stepTiming(1.0);
watchdog.disable();
assertEquals(1, watchdogCounter.get(),
"Watchdog either didn't trigger or triggered more than once");
assertEquals(
1, watchdogCounter.get(), "Watchdog either didn't trigger or triggered more than once");
}
}
@@ -70,9 +71,12 @@ class WatchdogTest {
void resetTest() {
final AtomicInteger watchdogCounter = new AtomicInteger(0);
try (Watchdog watchdog = new Watchdog(0.4, () -> {
watchdogCounter.addAndGet(1);
})) {
try (Watchdog watchdog =
new Watchdog(
0.4,
() -> {
watchdogCounter.addAndGet(1);
})) {
watchdog.enable();
SimHooks.stepTiming(0.2);
watchdog.reset();
@@ -88,9 +92,12 @@ class WatchdogTest {
void setTimeoutTest() {
final AtomicInteger watchdogCounter = new AtomicInteger(0);
try (Watchdog watchdog = new Watchdog(1.0, () -> {
watchdogCounter.addAndGet(1);
})) {
try (Watchdog watchdog =
new Watchdog(
1.0,
() -> {
watchdogCounter.addAndGet(1);
})) {
watchdog.enable();
SimHooks.stepTiming(0.2);
watchdog.setTimeout(0.2);
@@ -101,16 +108,15 @@ class WatchdogTest {
SimHooks.stepTiming(0.3);
watchdog.disable();
assertEquals(1, watchdogCounter.get(),
"Watchdog either didn't trigger or triggered more than once");
assertEquals(
1, watchdogCounter.get(), "Watchdog either didn't trigger or triggered more than once");
}
}
@Test
@ResourceLock("timing")
void isExpiredTest() {
try (Watchdog watchdog = new Watchdog(0.2, () -> {
})) {
try (Watchdog watchdog = new Watchdog(0.2, () -> {})) {
assertFalse(watchdog.isExpired());
watchdog.enable();
@@ -131,9 +137,12 @@ class WatchdogTest {
void epochsTest() {
final AtomicInteger watchdogCounter = new AtomicInteger(0);
try (Watchdog watchdog = new Watchdog(0.4, () -> {
watchdogCounter.addAndGet(1);
})) {
try (Watchdog watchdog =
new Watchdog(
0.4,
() -> {
watchdogCounter.addAndGet(1);
})) {
// Run 1
watchdog.enable();
watchdog.addEpoch("Epoch 1");
@@ -164,12 +173,18 @@ class WatchdogTest {
final AtomicInteger watchdogCounter1 = new AtomicInteger(0);
final AtomicInteger watchdogCounter2 = new AtomicInteger(0);
try (Watchdog watchdog1 = new Watchdog(0.2, () -> {
watchdogCounter1.addAndGet(1);
});
Watchdog watchdog2 = new Watchdog(0.6, () -> {
watchdogCounter2.addAndGet(1);
})) {
try (Watchdog watchdog1 =
new Watchdog(
0.2,
() -> {
watchdogCounter1.addAndGet(1);
});
Watchdog watchdog2 =
new Watchdog(
0.6,
() -> {
watchdogCounter2.addAndGet(1);
})) {
watchdog2.enable();
SimHooks.stepTiming(0.25);
assertEquals(0, watchdogCounter1.get(), "Watchdog triggered early");
@@ -181,8 +196,8 @@ class WatchdogTest {
watchdog1.disable();
watchdog2.disable();
assertEquals(1, watchdogCounter1.get(),
"Watchdog either didn't trigger or triggered more than once");
assertEquals(
1, watchdogCounter1.get(), "Watchdog either didn't trigger or triggered more than once");
assertEquals(0, watchdogCounter2.get(), "Watchdog triggered early");
}
}

View File

@@ -4,15 +4,14 @@
package edu.wpi.first.wpilibj;
import org.junit.jupiter.api.Test;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.XboxControllerSim;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.XboxControllerSim;
import org.junit.jupiter.api.Test;
class XboxControllerTest {
@Test
void testGetX() {

View File

@@ -4,13 +4,12 @@
package edu.wpi.first.wpilibj.can;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.can.CANJNI;
import edu.wpi.first.hal.can.CANStatus;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import org.junit.jupiter.api.Test;
class CANStatusTest {
@Test

View File

@@ -4,10 +4,10 @@
package edu.wpi.first.wpilibj.controller;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class ControllerUtilTest {
@Test
void testGetModulusError() {

View File

@@ -4,10 +4,8 @@
package edu.wpi.first.wpilibj.controller;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.wpilibj.geometry.Pose2d;
import edu.wpi.first.wpilibj.geometry.Rotation2d;
@@ -18,9 +16,9 @@ import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig;
import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator;
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
import edu.wpi.first.wpiutil.math.MathUtil;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
class HolonomicDriveControllerTest {
private static final double kTolerance = 1 / 12.0;
@@ -29,12 +27,11 @@ class HolonomicDriveControllerTest {
@Test
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
void testReachesReference() {
HolonomicDriveController controller = new HolonomicDriveController(
new PIDController(1.0, 0.0, 0.0),
new PIDController(1.0, 0.0, 0.0),
new ProfiledPIDController(1.0, 0.0, 0.0,
new TrapezoidProfile.Constraints(6.28, 3.14))
);
HolonomicDriveController controller =
new HolonomicDriveController(
new PIDController(1.0, 0.0, 0.0),
new PIDController(1.0, 0.0, 0.0),
new ProfiledPIDController(1.0, 0.0, 0.0, new TrapezoidProfile.Constraints(6.28, 3.14)));
Pose2d robotPose = new Pose2d(2.7, 23.0, Rotation2d.fromDegrees(0.0));
List<Pose2d> waypoints = new ArrayList<>();
@@ -51,8 +48,12 @@ class HolonomicDriveControllerTest {
Trajectory.State state = trajectory.sample(kDt * i);
ChassisSpeeds output = controller.calculate(robotPose, state, new Rotation2d());
robotPose = robotPose.exp(new Twist2d(output.vxMetersPerSecond * kDt,
output.vyMetersPerSecond * kDt, output.omegaRadiansPerSecond * kDt));
robotPose =
robotPose.exp(
new Twist2d(
output.vxMetersPerSecond * kDt,
output.vyMetersPerSecond * kDt,
output.omegaRadiansPerSecond * kDt));
}
final List<Trajectory.State> states = trajectory.getStates();
@@ -63,13 +64,12 @@ class HolonomicDriveControllerTest {
final Pose2d finalRobotPose = robotPose;
assertAll(
() -> assertEquals(endPose.getX(), finalRobotPose.getX(),
kTolerance),
() -> assertEquals(endPose.getY(), finalRobotPose.getY(),
kTolerance),
() -> assertEquals(0.0,
MathUtil.normalizeAngle(finalRobotPose.getRotation().getRadians()),
kAngularTolerance)
);
() -> assertEquals(endPose.getX(), finalRobotPose.getX(), kTolerance),
() -> assertEquals(endPose.getY(), finalRobotPose.getY(), kTolerance),
() ->
assertEquals(
0.0,
MathUtil.normalizeAngle(finalRobotPose.getRotation().getRadians()),
kAngularTolerance));
}
}

View File

@@ -4,12 +4,12 @@
package edu.wpi.first.wpilibj.controller;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class PIDInputOutputTest {
private PIDController m_controller;

View File

@@ -4,11 +4,11 @@
package edu.wpi.first.wpilibj.controller;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class PIDToleranceTest {
private static final double kSetpoint = 50.0;
private static final double kTolerance = 10.0;
@@ -28,34 +28,39 @@ class PIDToleranceTest {
try (var controller = new PIDController(0.05, 0.0, 0.0)) {
controller.enableContinuousInput(-kRange / 2, kRange / 2);
assertTrue(controller.atSetpoint(),
assertTrue(
controller.atSetpoint(),
"Error was not in tolerance when it should have been. Error was "
+ controller.getPositionError());
+ controller.getPositionError());
controller.setTolerance(kTolerance);
controller.setSetpoint(kSetpoint);
assertFalse(controller.atSetpoint(),
assertFalse(
controller.atSetpoint(),
"Error was in tolerance when it should not have been. Error was "
+ controller.getPositionError());
+ controller.getPositionError());
controller.calculate(0.0);
assertFalse(controller.atSetpoint(),
assertFalse(
controller.atSetpoint(),
"Error was in tolerance when it should not have been. Error was "
+ controller.getPositionError());
+ controller.getPositionError());
controller.calculate(kSetpoint + kTolerance / 2);
assertTrue(controller.atSetpoint(),
assertTrue(
controller.atSetpoint(),
"Error was not in tolerance when it should have been. Error was "
+ controller.getPositionError());
+ controller.getPositionError());
controller.calculate(kSetpoint + 10 * kTolerance);
assertFalse(controller.atSetpoint(),
assertFalse(
controller.atSetpoint(),
"Error was in tolerance when it should not have been. Error was "
+ controller.getPositionError());
+ controller.getPositionError());
}
}
}

View File

@@ -4,17 +4,16 @@
package edu.wpi.first.wpilibj.controller;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class ProfiledPIDControllerTest {
@Test
void testStartFromNonZeroPosition() {
ProfiledPIDController controller = new ProfiledPIDController(1.0, 0.0, 0.0,
new TrapezoidProfile.Constraints(1.0, 1.0));
ProfiledPIDController controller =
new ProfiledPIDController(1.0, 0.0, 0.0, new TrapezoidProfile.Constraints(1.0, 1.0));
controller.reset(20);

View File

@@ -4,21 +4,19 @@
package edu.wpi.first.wpilibj.controller;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class ProfiledPIDInputOutputTest {
private ProfiledPIDController m_controller;
@BeforeEach
void setUp() {
m_controller = new ProfiledPIDController(0, 0, 0,
new TrapezoidProfile.Constraints(360, 180));
m_controller = new ProfiledPIDController(0, 0, 0, new TrapezoidProfile.Constraints(360, 180));
}
@Test

View File

@@ -4,9 +4,8 @@
package edu.wpi.first.wpilibj.controller;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.wpilibj.geometry.Pose2d;
import edu.wpi.first.wpilibj.geometry.Rotation2d;
@@ -14,9 +13,8 @@ import edu.wpi.first.wpilibj.geometry.Twist2d;
import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig;
import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator;
import edu.wpi.first.wpiutil.math.MathUtil;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
class RamseteControllerTest {
private static final double kTolerance = 1 / 12.0;
@@ -40,8 +38,9 @@ class RamseteControllerTest {
var state = trajectory.sample(kDt * i);
var output = controller.calculate(robotPose, state);
robotPose = robotPose.exp(new Twist2d(output.vxMetersPerSecond * kDt, 0,
output.omegaRadiansPerSecond * kDt));
robotPose =
robotPose.exp(
new Twist2d(output.vxMetersPerSecond * kDt, 0, output.omegaRadiansPerSecond * kDt));
}
final var states = trajectory.getStates();
@@ -51,14 +50,13 @@ class RamseteControllerTest {
// must be final or effectively final.
final var finalRobotPose = robotPose;
assertAll(
() -> assertEquals(endPose.getX(), finalRobotPose.getX(),
kTolerance),
() -> assertEquals(endPose.getY(), finalRobotPose.getY(),
kTolerance),
() -> assertEquals(0.0,
MathUtil.normalizeAngle(endPose.getRotation().getRadians()
- finalRobotPose.getRotation().getRadians()),
kAngularTolerance)
);
() -> assertEquals(endPose.getX(), finalRobotPose.getX(), kTolerance),
() -> assertEquals(endPose.getY(), finalRobotPose.getY(), kTolerance),
() ->
assertEquals(
0.0,
MathUtil.normalizeAngle(
endPose.getRotation().getRadians() - finalRobotPose.getRotation().getRadians()),
kAngularTolerance));
}
}

View File

@@ -4,17 +4,14 @@
package edu.wpi.first.wpilibj.drive;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.wpilibj.MockSpeedController;
import edu.wpi.first.wpilibj.RobotDrive;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests DifferentialDrive and MecanumDrive.
*/
/** Tests DifferentialDrive and MecanumDrive. */
public class DriveTest {
private final MockSpeedController m_rdFrontLeft = new MockSpeedController();
private final MockSpeedController m_rdRearLeft = new MockSpeedController();
@@ -31,10 +28,11 @@ public class DriveTest {
private final MecanumDrive m_mecanumDrive =
new MecanumDrive(m_frontLeft, m_rearLeft, m_frontRight, m_rearRight);
private final double[] m_testJoystickValues = {1.0, 0.9, 0.5, 0.01, 0.0, -0.01, -0.5, -0.9,
-1.0};
private final double[] m_testGyroValues = {0, 30, 45, 90, 135, 180, 225, 270, 305, 360, 540,
-45, -90, -135, -180, -225, -270, -305, -360, -540};
private final double[] m_testJoystickValues = {1.0, 0.9, 0.5, 0.01, 0.0, -0.01, -0.5, -0.9, -1.0};
private final double[] m_testGyroValues = {
0, 30, 45, 90, 135, 180, 225, 270, 305, 360, 540, -45, -90, -135, -180, -225, -270, -305, -360,
-540
};
@BeforeEach
void setUp() {
@@ -51,12 +49,22 @@ public class DriveTest {
for (double rightJoystick : m_testJoystickValues) {
m_robotDrive.tankDrive(leftJoystick, rightJoystick);
m_differentialDrive.tankDrive(leftJoystick, rightJoystick);
assertEquals(m_rdFrontLeft.get(), m_frontLeft.get(), 0.01,
"Left Motor squared didn't match. Left Joystick: " + leftJoystick + " Right Joystick: "
+ rightJoystick);
assertEquals(m_rdFrontRight.get(), m_frontRight.get(), 0.01,
"Right Motor squared didn't match. Left Joystick: " + leftJoystick + " Right Joystick: "
+ rightJoystick);
assertEquals(
m_rdFrontLeft.get(),
m_frontLeft.get(),
0.01,
"Left Motor squared didn't match. Left Joystick: "
+ leftJoystick
+ " Right Joystick: "
+ rightJoystick);
assertEquals(
m_rdFrontRight.get(),
m_frontRight.get(),
0.01,
"Right Motor squared didn't match. Left Joystick: "
+ leftJoystick
+ " Right Joystick: "
+ rightJoystick);
}
}
}
@@ -67,12 +75,22 @@ public class DriveTest {
for (double rightJoystick : m_testJoystickValues) {
m_robotDrive.tankDrive(leftJoystick, rightJoystick, false);
m_differentialDrive.tankDrive(leftJoystick, rightJoystick, false);
assertEquals(m_rdFrontLeft.get(), m_frontLeft.get(), 0.01,
"Left Motor didn't match. Left Joystick: " + leftJoystick + " Right Joystick: "
+ rightJoystick);
assertEquals(m_rdFrontRight.get(), m_frontRight.get(), 0.01,
"Right Motor didn't match. Left Joystick: " + leftJoystick + " Right Joystick: "
+ rightJoystick);
assertEquals(
m_rdFrontLeft.get(),
m_frontLeft.get(),
0.01,
"Left Motor didn't match. Left Joystick: "
+ leftJoystick
+ " Right Joystick: "
+ rightJoystick);
assertEquals(
m_rdFrontRight.get(),
m_frontRight.get(),
0.01,
"Right Motor didn't match. Left Joystick: "
+ leftJoystick
+ " Right Joystick: "
+ rightJoystick);
}
}
}
@@ -83,12 +101,22 @@ public class DriveTest {
for (double rotateJoystick : m_testJoystickValues) {
m_robotDrive.arcadeDrive(moveJoystick, rotateJoystick);
m_differentialDrive.arcadeDrive(moveJoystick, -rotateJoystick);
assertEquals(m_rdFrontLeft.get(), m_frontLeft.get(), 0.01,
"Left Motor squared didn't match. Move Joystick: " + moveJoystick + " Rotate Joystick: "
+ rotateJoystick);
assertEquals(m_rdFrontRight.get(), m_frontRight.get(), 0.01,
"Right Motor squared didn't match. Move Joystick: " + moveJoystick
+ " Rotate Joystick: " + rotateJoystick);
assertEquals(
m_rdFrontLeft.get(),
m_frontLeft.get(),
0.01,
"Left Motor squared didn't match. Move Joystick: "
+ moveJoystick
+ " Rotate Joystick: "
+ rotateJoystick);
assertEquals(
m_rdFrontRight.get(),
m_frontRight.get(),
0.01,
"Right Motor squared didn't match. Move Joystick: "
+ moveJoystick
+ " Rotate Joystick: "
+ rotateJoystick);
}
}
}
@@ -99,12 +127,22 @@ public class DriveTest {
for (double rotateJoystick : m_testJoystickValues) {
m_robotDrive.arcadeDrive(moveJoystick, rotateJoystick, false);
m_differentialDrive.arcadeDrive(moveJoystick, -rotateJoystick, false);
assertEquals(m_rdFrontLeft.get(), m_frontLeft.get(), 0.01,
"Left Motor didn't match. Move Joystick: " + moveJoystick + " Rotate Joystick: "
+ rotateJoystick);
assertEquals(m_rdFrontRight.get(), m_frontRight.get(), 0.01,
"Right Motor didn't match. Move Joystick: " + moveJoystick + " Rotate Joystick: "
+ rotateJoystick);
assertEquals(
m_rdFrontLeft.get(),
m_frontLeft.get(),
0.01,
"Left Motor didn't match. Move Joystick: "
+ moveJoystick
+ " Rotate Joystick: "
+ rotateJoystick);
assertEquals(
m_rdFrontRight.get(),
m_frontRight.get(),
0.01,
"Right Motor didn't match. Move Joystick: "
+ moveJoystick
+ " Rotate Joystick: "
+ rotateJoystick);
}
}
}
@@ -116,22 +154,46 @@ public class DriveTest {
for (double rotationJoystick : m_testJoystickValues) {
m_robotDrive.mecanumDrive_Polar(magnitudeJoystick, directionJoystick, rotationJoystick);
m_mecanumDrive.drivePolar(magnitudeJoystick, directionJoystick, rotationJoystick);
assertEquals(m_rdFrontLeft.get(), m_frontLeft.get(), 0.01,
"Left Front Motor didn't match. Magnitude Joystick: " + magnitudeJoystick
+ " Direction Joystick: " + directionJoystick + " RotationJoystick: "
+ rotationJoystick);
assertEquals(m_rdFrontRight.get(), -m_frontRight.get(), 0.01,
"Right Front Motor didn't match. Magnitude Joystick: " + magnitudeJoystick
+ " Direction Joystick: " + directionJoystick + " RotationJoystick: "
+ rotationJoystick);
assertEquals(m_rdRearLeft.get(), m_rearLeft.get(), 0.01,
"Left Rear Motor didn't match. Magnitude Joystick: " + magnitudeJoystick
+ " Direction Joystick: " + directionJoystick + " RotationJoystick: "
+ rotationJoystick);
assertEquals(m_rdRearRight.get(), -m_rearRight.get(), 0.01,
"Right Rear Motor didn't match. Magnitude Joystick: " + magnitudeJoystick
+ " Direction Joystick: " + directionJoystick + " RotationJoystick: "
+ rotationJoystick);
assertEquals(
m_rdFrontLeft.get(),
m_frontLeft.get(),
0.01,
"Left Front Motor didn't match. Magnitude Joystick: "
+ magnitudeJoystick
+ " Direction Joystick: "
+ directionJoystick
+ " RotationJoystick: "
+ rotationJoystick);
assertEquals(
m_rdFrontRight.get(),
-m_frontRight.get(),
0.01,
"Right Front Motor didn't match. Magnitude Joystick: "
+ magnitudeJoystick
+ " Direction Joystick: "
+ directionJoystick
+ " RotationJoystick: "
+ rotationJoystick);
assertEquals(
m_rdRearLeft.get(),
m_rearLeft.get(),
0.01,
"Left Rear Motor didn't match. Magnitude Joystick: "
+ magnitudeJoystick
+ " Direction Joystick: "
+ directionJoystick
+ " RotationJoystick: "
+ rotationJoystick);
assertEquals(
m_rdRearRight.get(),
-m_rearRight.get(),
0.01,
"Right Rear Motor didn't match. Magnitude Joystick: "
+ magnitudeJoystick
+ " Direction Joystick: "
+ directionJoystick
+ " RotationJoystick: "
+ rotationJoystick);
}
}
}
@@ -144,21 +206,57 @@ public class DriveTest {
for (double y_Joystick : m_testJoystickValues) {
for (double rotationJoystick : m_testJoystickValues) {
for (double gyroValue : m_testGyroValues) {
m_robotDrive.mecanumDrive_Cartesian(x_Joystick, y_Joystick, rotationJoystick,
gyroValue);
m_robotDrive.mecanumDrive_Cartesian(
x_Joystick, y_Joystick, rotationJoystick, gyroValue);
m_mecanumDrive.driveCartesian(x_Joystick, -y_Joystick, rotationJoystick, -gyroValue);
assertEquals(m_rdFrontLeft.get(), m_frontLeft.get(), 0.01,
"Left Front Motor didn't match. X Joystick: " + x_Joystick + " Y Joystick: "
+ y_Joystick + " RotationJoystick: " + rotationJoystick + " Gyro: " + gyroValue);
assertEquals(m_rdFrontRight.get(), -m_frontRight.get(), 0.01,
"Right Front Motor didn't match. X Joystick: " + x_Joystick + " Y Joystick: "
+ y_Joystick + " RotationJoystick: " + rotationJoystick + " Gyro: " + gyroValue);
assertEquals(m_rdRearLeft.get(), m_rearLeft.get(), 0.01,
"Left Rear Motor didn't match. X Joystick: " + x_Joystick + " Y Joystick: "
+ y_Joystick + " RotationJoystick: " + rotationJoystick + " Gyro: " + gyroValue);
assertEquals(m_rdRearRight.get(), -m_rearRight.get(), 0.01,
"Right Rear Motor didn't match. X Joystick: " + x_Joystick + " Y Joystick: "
+ y_Joystick + " RotationJoystick: " + rotationJoystick + " Gyro: " + gyroValue);
assertEquals(
m_rdFrontLeft.get(),
m_frontLeft.get(),
0.01,
"Left Front Motor didn't match. X Joystick: "
+ x_Joystick
+ " Y Joystick: "
+ y_Joystick
+ " RotationJoystick: "
+ rotationJoystick
+ " Gyro: "
+ gyroValue);
assertEquals(
m_rdFrontRight.get(),
-m_frontRight.get(),
0.01,
"Right Front Motor didn't match. X Joystick: "
+ x_Joystick
+ " Y Joystick: "
+ y_Joystick
+ " RotationJoystick: "
+ rotationJoystick
+ " Gyro: "
+ gyroValue);
assertEquals(
m_rdRearLeft.get(),
m_rearLeft.get(),
0.01,
"Left Rear Motor didn't match. X Joystick: "
+ x_Joystick
+ " Y Joystick: "
+ y_Joystick
+ " RotationJoystick: "
+ rotationJoystick
+ " Gyro: "
+ gyroValue);
assertEquals(
m_rdRearRight.get(),
-m_rearRight.get(),
0.01,
"Right Rear Motor didn't match. X Joystick: "
+ x_Joystick
+ " Y Joystick: "
+ y_Joystick
+ " RotationJoystick: "
+ rotationJoystick
+ " Gyro: "
+ gyroValue);
}
}
}

View File

@@ -4,11 +4,10 @@
package edu.wpi.first.wpilibj.hal;
import org.junit.jupiter.api.Test;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.HALUtil;
import edu.wpi.first.networktables.NetworkTablesJNI;
import org.junit.jupiter.api.Test;
class JNITest {
@Test

View File

@@ -4,15 +4,14 @@
package edu.wpi.first.wpilibj.hal;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.hal.MatchInfoData;
import edu.wpi.first.hal.simulation.DriverStationDataJNI;
import edu.wpi.first.wpilibj.DriverStation.MatchType;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class MatchInfoDataTest {
@Test
@@ -29,7 +28,6 @@ class MatchInfoDataTest {
() -> assertEquals(matchType.ordinal(), outMatchInfo.matchType),
() -> assertEquals(174, outMatchInfo.matchNumber),
() -> assertEquals(191, outMatchInfo.replayNumber),
() -> assertEquals("Game Message", outMatchInfo.gameSpecificMessage)
);
() -> assertEquals("Game Message", outMatchInfo.gameSpecificMessage));
}
}

View File

@@ -8,9 +8,7 @@ import edu.wpi.first.wpilibj.Sendable;
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
/**
* A mock sendable that marks itself as an actuator.
*/
/** A mock sendable that marks itself as an actuator. */
public class MockActuatorSendable implements Sendable {
public MockActuatorSendable(String name) {
SendableRegistry.add(this, name);

View File

@@ -4,18 +4,17 @@
package edu.wpi.first.wpilibj.shuffleboard;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class ShuffleboardInstanceTest {
private NetworkTableInstance m_ntInstance;
private ShuffleboardInstance m_shuffleboardInstance;
@@ -33,32 +32,42 @@ public class ShuffleboardInstanceTest {
@Test
void testPathFluent() {
NetworkTableEntry entry = m_shuffleboardInstance.getTab("Tab Title")
.getLayout("Layout Title", "List Layout")
.add("Data", "string")
.withWidget("Text View")
.getEntry();
NetworkTableEntry entry =
m_shuffleboardInstance
.getTab("Tab Title")
.getLayout("Layout Title", "List Layout")
.add("Data", "string")
.withWidget("Text View")
.getEntry();
assertAll(
() -> assertEquals("string", entry.getString(null), "Wrong entry value"),
() -> assertEquals("/Shuffleboard/Tab Title/Layout Title/Data", entry.getName(),
"Entry path generated incorrectly"));
() ->
assertEquals(
"/Shuffleboard/Tab Title/Layout Title/Data",
entry.getName(),
"Entry path generated incorrectly"));
}
@Test
void testNestedLayoutsFluent() {
NetworkTableEntry entry = m_shuffleboardInstance.getTab("Tab")
.getLayout("First", "List")
.getLayout("Second", "List")
.getLayout("Third", "List")
.getLayout("Fourth", "List")
.add("Value", "string")
.getEntry();
NetworkTableEntry entry =
m_shuffleboardInstance
.getTab("Tab")
.getLayout("First", "List")
.getLayout("Second", "List")
.getLayout("Third", "List")
.getLayout("Fourth", "List")
.add("Value", "string")
.getEntry();
assertAll(
() -> assertEquals("string", entry.getString(null), "Wrong entry value"),
() -> assertEquals("/Shuffleboard/Tab/First/Second/Third/Fourth/Value", entry.getName(),
"Entry path generated incorrectly"));
() ->
assertEquals(
"/Shuffleboard/Tab/First/Second/Third/Fourth/Value",
entry.getName(),
"Entry path generated incorrectly"));
}
@Test
@@ -73,26 +82,29 @@ public class ShuffleboardInstanceTest {
assertAll(
() -> assertEquals("string", entry.getString(null), "Wrong entry value"),
() -> assertEquals("/Shuffleboard/Tab/First/Second/Third/Fourth/Value", entry.getName(),
"Entry path generated incorrectly"));
() ->
assertEquals(
"/Shuffleboard/Tab/First/Second/Third/Fourth/Value",
entry.getName(),
"Entry path generated incorrectly"));
}
@Test
void testLayoutTypeIsSet() {
String layoutType = "Type";
m_shuffleboardInstance.getTab("Tab")
.getLayout("Title", layoutType);
m_shuffleboardInstance.getTab("Tab").getLayout("Title", layoutType);
m_shuffleboardInstance.update();
NetworkTableEntry entry = m_ntInstance.getEntry(
"/Shuffleboard/.metadata/Tab/Title/PreferredComponent");
NetworkTableEntry entry =
m_ntInstance.getEntry("/Shuffleboard/.metadata/Tab/Title/PreferredComponent");
assertEquals(layoutType, entry.getString("Not Set"), "Layout type not set");
}
@Test
void testNestedActuatorWidgetsAreDisabled() {
m_shuffleboardInstance.getTab("Tab")
.getLayout("Title", "Layout")
.add(new MockActuatorSendable("Actuator"));
m_shuffleboardInstance
.getTab("Tab")
.getLayout("Title", "Layout")
.add(new MockActuatorSendable("Actuator"));
NetworkTableEntry controllableEntry =
m_ntInstance.getEntry("/Shuffleboard/Tab/Title/Actuator/.controllable");
@@ -108,5 +120,4 @@ public class ShuffleboardInstanceTest {
controllable = controllableEntry.getValue().getBoolean();
assertFalse(controllable, "The nested actuator widget should have been disabled");
}
}

View File

@@ -4,11 +4,10 @@
package edu.wpi.first.wpilibj.shuffleboard;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertSame;
import edu.wpi.first.wpilibj.UtilityClassTest;
import static org.junit.jupiter.api.Assertions.assertSame;
import org.junit.jupiter.api.Test;
public class ShuffleboardTest extends UtilityClassTest<Shuffleboard> {
public ShuffleboardTest() {
@@ -23,5 +22,4 @@ public class ShuffleboardTest extends UtilityClassTest<Shuffleboard> {
ShuffleboardTab tab2 = Shuffleboard.getTab("testTabObjectsCached");
assertSame(tab1, tab2, "Tab objects were not cached");
}
}

View File

@@ -4,19 +4,17 @@
package edu.wpi.first.wpilibj.shuffleboard;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.networktables.NetworkTableEntry;
import edu.wpi.first.networktables.NetworkTableInstance;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class SuppliedValueWidgetTest {
private NetworkTableInstance m_ntInstance;
private ShuffleboardInstance m_instance;
@@ -30,8 +28,7 @@ class SuppliedValueWidgetTest {
@Test
void testAddString() {
AtomicInteger count = new AtomicInteger(0);
m_instance.getTab("Tab")
.addString("Title", () -> Integer.toString(count.incrementAndGet()));
m_instance.getTab("Tab").addString("Title", () -> Integer.toString(count.incrementAndGet()));
NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title");
m_instance.update();
@@ -44,8 +41,7 @@ class SuppliedValueWidgetTest {
@Test
void testAddDouble() {
AtomicInteger num = new AtomicInteger(0);
m_instance.getTab("Tab")
.addNumber("Title", num::incrementAndGet);
m_instance.getTab("Tab").addNumber("Title", num::incrementAndGet);
NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title");
m_instance.update();
@@ -58,8 +54,7 @@ class SuppliedValueWidgetTest {
@Test
void testAddBoolean() {
boolean[] bool = {false};
m_instance.getTab("Tab")
.addBoolean("Title", () -> bool[0] = !bool[0]);
m_instance.getTab("Tab").addBoolean("Title", () -> bool[0] = !bool[0]);
NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title");
m_instance.update();
@@ -72,8 +67,7 @@ class SuppliedValueWidgetTest {
@Test
void testAddStringArray() {
String[] arr = {"foo", "bar"};
m_instance.getTab("Tab")
.addStringArray("Title", () -> arr);
m_instance.getTab("Tab").addStringArray("Title", () -> arr);
NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title");
m_instance.update();
@@ -83,8 +77,7 @@ class SuppliedValueWidgetTest {
@Test
void testAddDoubleArray() {
double[] arr = {0, 1};
m_instance.getTab("Tab")
.addDoubleArray("Title", () -> arr);
m_instance.getTab("Tab").addDoubleArray("Title", () -> arr);
NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title");
m_instance.update();
@@ -94,8 +87,7 @@ class SuppliedValueWidgetTest {
@Test
void testAddBooleanArray() {
boolean[] arr = {true, false};
m_instance.getTab("Tab")
.addBooleanArray("Title", () -> arr);
m_instance.getTab("Tab").addBooleanArray("Title", () -> arr);
NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title");
m_instance.update();
@@ -105,12 +97,10 @@ class SuppliedValueWidgetTest {
@Test
void testAddRawBytes() {
byte[] arr = {0, 1, 2, 3};
m_instance.getTab("Tab")
.addRaw("Title", () -> arr);
m_instance.getTab("Tab").addRaw("Title", () -> arr);
NetworkTableEntry entry = m_ntInstance.getEntry("/Shuffleboard/Tab/Title");
m_instance.update();
assertArrayEquals(arr, entry.getRaw(new byte[0]));
}
}

View File

@@ -4,13 +4,12 @@
package edu.wpi.first.wpilibj.simulation;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.hal.AccelerometerJNI;
import edu.wpi.first.hal.HAL;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class AccelerometerSimTest {
static class TriggeredStore {
@@ -26,10 +25,13 @@ class AccelerometerSimTest {
TriggeredStore store = new TriggeredStore();
try (CallbackStore cb = sim.registerActiveCallback((s, v) -> {
store.m_wasTriggered = true;
store.m_setValue = v.getBoolean();
}, false)) {
try (CallbackStore cb =
sim.registerActiveCallback(
(s, v) -> {
store.m_wasTriggered = true;
store.m_setValue = v.getBoolean();
},
false)) {
assertFalse(store.m_wasTriggered);
AccelerometerJNI.setAccelerometerActive(true);
assertTrue(store.m_wasTriggered);

View File

@@ -4,13 +4,13 @@
package edu.wpi.first.wpilibj.simulation;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.wpilibj.AnalogEncoder;
import edu.wpi.first.wpilibj.AnalogInput;
import edu.wpi.first.wpilibj.geometry.Rotation2d;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class AnalogEncoderSimTest {
@Test
public void testBasic() {

View File

@@ -4,13 +4,12 @@
package edu.wpi.first.wpilibj.simulation;
import org.junit.jupiter.api.Test;
import edu.wpi.first.wpilibj.AnalogInput;
import edu.wpi.first.hal.HAL;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.AnalogInput;
import org.junit.jupiter.api.Test;
class AnalogInputSimTest {
static class DoubleStore {
public boolean m_wasTriggered;

View File

@@ -4,13 +4,12 @@
package edu.wpi.first.wpilibj.simulation;
import edu.wpi.first.wpilibj.AnalogOutput;
import edu.wpi.first.hal.HAL;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.AnalogOutput;
import org.junit.jupiter.api.Test;
class AnalogOutputSimTest {
@@ -30,7 +29,6 @@ class AnalogOutputSimTest {
void setCallbackTest() {
HAL.initialize(500, 0);
try (AnalogOutput output = new AnalogOutput(0)) {
output.setVoltage(0.5);
@@ -38,11 +36,14 @@ class AnalogOutputSimTest {
DoubleStore store = new DoubleStore();
try (CallbackStore cb = outputSim.registerVoltageCallback((name, value) -> {
store.m_wasTriggered = true;
store.m_wasCorrectType = true;
store.m_setValue = value.getDouble();
}, false)) {
try (CallbackStore cb =
outputSim.registerVoltageCallback(
(name, value) -> {
store.m_wasTriggered = true;
store.m_wasCorrectType = true;
store.m_setValue = value.getDouble();
},
false)) {
assertFalse(store.m_wasTriggered);
for (double i = 0.1; i < 5.0; i += 0.1) {

View File

@@ -4,6 +4,9 @@
package edu.wpi.first.wpilibj.simulation;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.wpilibj.controller.LinearPlantInversionFeedforward;
import edu.wpi.first.wpilibj.controller.RamseteController;
import edu.wpi.first.wpilibj.geometry.Pose2d;
@@ -22,29 +25,26 @@ import edu.wpi.first.wpiutil.math.VecBuilder;
import edu.wpi.first.wpiutil.math.Vector;
import edu.wpi.first.wpiutil.math.numbers.N1;
import edu.wpi.first.wpiutil.math.numbers.N7;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class DifferentialDrivetrainSimTest {
@Test
public void testConvergence() {
var motor = DCMotor.getNEO(2);
var plant = LinearSystemId.createDrivetrainVelocitySystem(
motor,
50,
Units.inchesToMeters(2),
Units.inchesToMeters(12),
0.5,
1.0);
var plant =
LinearSystemId.createDrivetrainVelocitySystem(
motor, 50, Units.inchesToMeters(2), Units.inchesToMeters(12), 0.5, 1.0);
var kinematics = new DifferentialDriveKinematics(Units.inchesToMeters(24));
var sim = new DifferentialDrivetrainSim(plant,
motor, 1, kinematics.trackWidthMeters, Units.inchesToMeters(2), VecBuilder.fill(0, 0, 0.0001, 0.1, 0.1, 0.005, 0.005));
var sim =
new DifferentialDrivetrainSim(
plant,
motor,
1,
kinematics.trackWidthMeters,
Units.inchesToMeters(2),
VecBuilder.fill(0, 0, 0.0001, 0.1, 0.1, 0.005, 0.005));
var feedforward = new LinearPlantInversionFeedforward<>(plant, 0.020);
var ramsete = new RamseteController();
@@ -53,12 +53,13 @@ class DifferentialDrivetrainSimTest {
// ground truth
Matrix<N7, N1> groundTruthX = new Vector<>(Nat.N7());
var traj = TrajectoryGenerator.generateTrajectory(
new Pose2d(),
List.of(),
new Pose2d(2, 2, new Rotation2d()),
new TrajectoryConfig(1, 1)
.addConstraint(new DifferentialDriveKinematicsConstraint(kinematics, 1)));
var traj =
TrajectoryGenerator.generateTrajectory(
new Pose2d(),
List.of(),
new Pose2d(2, 2, new Rotation2d()),
new TrajectoryConfig(1, 1)
.addConstraint(new DifferentialDriveKinematicsConstraint(kinematics, 1)));
for (double t = 0; t < traj.getTotalTimeSeconds(); t += 0.020) {
var state = traj.sample(0.020);
@@ -66,8 +67,9 @@ class DifferentialDrivetrainSimTest {
var wheelSpeeds = kinematics.toWheelSpeeds(ramseteOut);
var voltages = feedforward.calculate(
VecBuilder.fill(wheelSpeeds.leftMetersPerSecond, wheelSpeeds.rightMetersPerSecond));
var voltages =
feedforward.calculate(
VecBuilder.fill(wheelSpeeds.leftMetersPerSecond, wheelSpeeds.rightMetersPerSecond));
// Sim periodic code
sim.setInputs(voltages.get(0, 0), voltages.get(1, 0));
@@ -77,26 +79,27 @@ class DifferentialDrivetrainSimTest {
groundTruthX = RungeKutta.rungeKutta(sim::getDynamics, groundTruthX, voltages, 0.020);
}
assertEquals(groundTruthX.get(DifferentialDrivetrainSim.State.kX.value, 0),
assertEquals(
groundTruthX.get(DifferentialDrivetrainSim.State.kX.value, 0),
sim.getState(DifferentialDrivetrainSim.State.kX));
assertEquals(groundTruthX.get(DifferentialDrivetrainSim.State.kY.value, 0),
assertEquals(
groundTruthX.get(DifferentialDrivetrainSim.State.kY.value, 0),
sim.getState(DifferentialDrivetrainSim.State.kY));
assertEquals(groundTruthX.get(DifferentialDrivetrainSim.State.kHeading.value, 0),
assertEquals(
groundTruthX.get(DifferentialDrivetrainSim.State.kHeading.value, 0),
sim.getState(DifferentialDrivetrainSim.State.kHeading));
}
@Test
public void testCurrent() {
var motor = DCMotor.getNEO(2);
var plant = LinearSystemId.createDrivetrainVelocitySystem(
motor,
50,
Units.inchesToMeters(2),
Units.inchesToMeters(12),
0.5,
1.0);
var plant =
LinearSystemId.createDrivetrainVelocitySystem(
motor, 50, Units.inchesToMeters(2), Units.inchesToMeters(12), 0.5, 1.0);
var kinematics = new DifferentialDriveKinematics(Units.inchesToMeters(24));
var sim = new DifferentialDrivetrainSim(plant, motor, 1, kinematics.trackWidthMeters, Units.inchesToMeters(2), null);
var sim =
new DifferentialDrivetrainSim(
plant, motor, 1, kinematics.trackWidthMeters, Units.inchesToMeters(2), null);
sim.setInputs(-12, -12);
for (int i = 0; i < 10; i++) {
@@ -120,16 +123,19 @@ class DifferentialDrivetrainSimTest {
@Test
public void testModelStability() {
var motor = DCMotor.getNEO(2);
var plant = LinearSystemId.createDrivetrainVelocitySystem(
motor,
50,
Units.inchesToMeters(2),
Units.inchesToMeters(12),
2.0,
5.0);
var plant =
LinearSystemId.createDrivetrainVelocitySystem(
motor, 50, Units.inchesToMeters(2), Units.inchesToMeters(12), 2.0, 5.0);
var kinematics = new DifferentialDriveKinematics(Units.inchesToMeters(24));
var sim = new DifferentialDrivetrainSim(plant, motor, 5, kinematics.trackWidthMeters, Units.inchesToMeters(2), VecBuilder.fill(0, 0, 0.0001, 0.1, 0.1, 0.005, 0.005));
var sim =
new DifferentialDrivetrainSim(
plant,
motor,
5,
kinematics.trackWidthMeters,
Units.inchesToMeters(2),
VecBuilder.fill(0, 0, 0.0001, 0.1, 0.1, 0.005, 0.005));
sim.setInputs(2, 4);

View File

@@ -4,7 +4,8 @@
package edu.wpi.first.wpilibj.simulation;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.PWMVictorSPX;
@@ -13,9 +14,7 @@ import edu.wpi.first.wpilibj.controller.PIDController;
import edu.wpi.first.wpilibj.system.plant.DCMotor;
import edu.wpi.first.wpilibj.system.plant.LinearSystemId;
import edu.wpi.first.wpiutil.math.VecBuilder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
public class ElevatorSimTest {
@Test
@@ -24,8 +23,15 @@ public class ElevatorSimTest {
var controller = new PIDController(10, 0, 0);
var sim = new ElevatorSim(DCMotor.getVex775Pro(4), 14.67, 8, 0.75 * 25.4 / 1000.0,
0.0, 3.0, VecBuilder.fill(0.01));
var sim =
new ElevatorSim(
DCMotor.getVex775Pro(4),
14.67,
8,
0.75 * 25.4 / 1000.0,
0.0,
3.0,
VecBuilder.fill(0.01));
var motor = new PWMVictorSPX(0);
var encoder = new Encoder(0, 1);
@@ -53,15 +59,19 @@ public class ElevatorSimTest {
@Test
public void testMinMax() {
var plant = LinearSystemId.createElevatorSystem(
DCMotor.getVex775Pro(4),
8.0,
0.75 * 25.4 / 1000.0,
14.67);
var plant =
LinearSystemId.createElevatorSystem(
DCMotor.getVex775Pro(4), 8.0, 0.75 * 25.4 / 1000.0, 14.67);
var sim = new ElevatorSim(plant,
DCMotor.getVex775Pro(4),
14.67, 0.75 * 25.4 / 1000.0, 0.0, 1.0, VecBuilder.fill(0.01));
var sim =
new ElevatorSim(
plant,
DCMotor.getVex775Pro(4),
14.67,
0.75 * 25.4 / 1000.0,
0.0,
1.0,
VecBuilder.fill(0.01));
for (int i = 0; i < 100; i++) {
sim.setInput(VecBuilder.fill(0));

View File

@@ -4,17 +4,15 @@
package edu.wpi.first.wpilibj.simulation;
import org.junit.jupiter.api.Test;
import edu.wpi.first.hal.SimBoolean;
import edu.wpi.first.hal.SimDevice;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.hal.SimBoolean;
import edu.wpi.first.hal.SimDevice;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
class SimDeviceSimTest {
@Test
void testBasic() {
@@ -37,20 +35,31 @@ class SimDeviceSimTest {
try (SimDevice otherdev = SimDevice.create("testnotDC");
SimDevice dev1 = SimDevice.create("testDC1")) {
try (
CallbackStore callback1 = SimDeviceSim.registerDeviceCreatedCallback("testDC", (name, handle) -> {
callback1Counter.addAndGet(1);
}, false);
CallbackStore callback2 = SimDeviceSim.registerDeviceCreatedCallback("testDC", (name, handle) -> {
callback2Counter.addAndGet(1);
}, true)) {
try (CallbackStore callback1 =
SimDeviceSim.registerDeviceCreatedCallback(
"testDC",
(name, handle) -> {
callback1Counter.addAndGet(1);
},
false);
CallbackStore callback2 =
SimDeviceSim.registerDeviceCreatedCallback(
"testDC",
(name, handle) -> {
callback2Counter.addAndGet(1);
},
true)) {
assertEquals(0, callback1Counter.get(), "Callback 1 called early");
assertEquals(1, callback2Counter.get(), "Callback 2 called early or not initialized with existing devices");
assertEquals(
1,
callback2Counter.get(),
"Callback 2 called early or not initialized with existing devices");
SimDevice dev2 = SimDevice.create("testDC2");
dev2.close();
assertEquals(1, callback1Counter.get(), "Callback 1 called either more than once or not at all");
assertEquals(
1, callback1Counter.get(), "Callback 1 called either more than once or not at all");
assertEquals(2, callback2Counter.get(), "Callback 2 called either more or less than twice");
}
@@ -67,9 +76,13 @@ class SimDeviceSimTest {
AtomicInteger counter = new AtomicInteger(0);
SimDevice dev1 = SimDevice.create("testDF1");
try (CallbackStore callback = SimDeviceSim.registerDeviceFreedCallback("testDF", (name, handle) -> {
counter.addAndGet(1);
}, false)) {
try (CallbackStore callback =
SimDeviceSim.registerDeviceFreedCallback(
"testDF",
(name, handle) -> {
counter.addAndGet(1);
},
false)) {
assertEquals(0, counter.get(), "Callback called early");
dev1.close();
assertEquals(1, counter.get(), "Callback called either more than once or not at all");
@@ -89,19 +102,28 @@ class SimDeviceSimTest {
try (SimDevice dev1 = SimDevice.create("testVM1")) {
dev1.createBoolean("v1", false, false);
SimDeviceSim sim = new SimDeviceSim("testVM1");
try (
CallbackStore callback1 = sim.registerValueCreatedCallback((name, handle, readonly, value) -> {
callback1Counter.addAndGet(1);
}, false);
CallbackStore callback2 = sim.registerValueCreatedCallback((name, handle, readonly, value) -> {
callback2Counter.addAndGet(1);
}, true)) {
try (CallbackStore callback1 =
sim.registerValueCreatedCallback(
(name, handle, readonly, value) -> {
callback1Counter.addAndGet(1);
},
false);
CallbackStore callback2 =
sim.registerValueCreatedCallback(
(name, handle, readonly, value) -> {
callback2Counter.addAndGet(1);
},
true)) {
assertEquals(0, callback1Counter.get(), "Callback 1 called early");
assertEquals(1, callback2Counter.get(), "Callback 2 called early or not initialized with existing devices");
assertEquals(
1,
callback2Counter.get(),
"Callback 2 called early or not initialized with existing devices");
dev1.createDouble("v2", false, 0);
assertEquals(1, callback1Counter.get(), "Callback 1 called either more than once or not at all");
assertEquals(
1, callback1Counter.get(), "Callback 1 called either more than once or not at all");
assertEquals(2, callback2Counter.get(), "Callback 2 called either more or less than twice");
}
dev1.createBoolean("v3", false, false);
@@ -119,19 +141,30 @@ class SimDeviceSimTest {
try (SimDevice dev1 = SimDevice.create("testVC1")) {
SimBoolean val = dev1.createBoolean("v1", false, false);
SimDeviceSim sim = new SimDeviceSim("testVM1");
try (
CallbackStore callback1 = sim.registerValueChangedCallback(val, (name, handle, readonly, value) -> {
callback1Counter.addAndGet(1);
}, false);
CallbackStore callback2 = sim.registerValueChangedCallback(val, (name, handle, readonly, value) -> {
callback2Counter.addAndGet(1);
}, true)) {
try (CallbackStore callback1 =
sim.registerValueChangedCallback(
val,
(name, handle, readonly, value) -> {
callback1Counter.addAndGet(1);
},
false);
CallbackStore callback2 =
sim.registerValueChangedCallback(
val,
(name, handle, readonly, value) -> {
callback2Counter.addAndGet(1);
},
true)) {
assertEquals(0, callback1Counter.get(), "Callback 1 called early");
assertEquals(1, callback2Counter.get(), "Callback 2 called early or not initialized with existing devices");
assertEquals(
1,
callback2Counter.get(),
"Callback 2 called early or not initialized with existing devices");
val.set(true);
assertEquals(1, callback1Counter.get(), "Callback 1 called either more than once or not at all");
assertEquals(
1, callback1Counter.get(), "Callback 1 called either more than once or not at all");
assertEquals(2, callback2Counter.get(), "Callback 2 called either more or less than twice");
}
val.set(false);

View File

@@ -4,22 +4,24 @@
package edu.wpi.first.wpilibj.simulation;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.wpilibj.system.plant.DCMotor;
import edu.wpi.first.wpilibj.util.Units;
import edu.wpi.first.wpiutil.math.VecBuilder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class SingleJointedArmSimTest {
SingleJointedArmSim m_sim = new SingleJointedArmSim(
DCMotor.getVex775Pro(2),
100,
3.0,
Units.inchesToMeters(19.0 / 2.0),
-Math.PI,
0.0, 10.0 / 2.2, true);
SingleJointedArmSim m_sim =
new SingleJointedArmSim(
DCMotor.getVex775Pro(2),
100,
3.0,
Units.inchesToMeters(19.0 / 2.0),
-Math.PI,
0.0,
10.0 / 2.2,
true);
@Test
public void testArmDisabled() {

View File

@@ -4,15 +4,14 @@
package edu.wpi.first.wpilibj.smartdashboard;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.UtilityClassTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class SmartDashboardTest extends UtilityClassTest<SmartDashboard> {
private final NetworkTable m_table = NetworkTableInstance.getDefault().getTable("SmartDashboard");
@@ -104,13 +103,14 @@ class SmartDashboardTest extends UtilityClassTest<SmartDashboard> {
@Test
void putStringNullKeyTest() {
assertThrows(NullPointerException.class,
() -> SmartDashboard.putString(null, "This should not work"));
assertThrows(
NullPointerException.class, () -> SmartDashboard.putString(null, "This should not work"));
}
@Test
void putStringNullValueTest() {
assertThrows(NullPointerException.class,
assertThrows(
NullPointerException.class,
() -> SmartDashboard.putString("KEY_SHOULD_NOT_BE_STORED", null));
}
}

View File

@@ -4,16 +4,15 @@
package edu.wpi.first.wpilibj.util;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class ColorTest {
private static final double kEpsilon = 1e-3;
@@ -21,8 +20,7 @@ class ColorTest {
assertAll(
() -> assertEquals(red, color.red, kEpsilon),
() -> assertEquals(green, color.green, kEpsilon),
() -> assertEquals(blue, color.blue, kEpsilon)
);
() -> assertEquals(blue, color.blue, kEpsilon));
}
@ParameterizedTest
@@ -39,9 +37,8 @@ class ColorTest {
static Stream<Arguments> staticColorProvider() {
return Stream.of(
arguments(0.0823529412, 0.376470589, 0.7411764706, Color.kDenim),
arguments(0.0, 0.4, 0.7019607844, Color.kFirstBlue),
arguments(0.9294117648, 0.1098039216, 0.1411764706, Color.kFirstRed)
);
arguments(0.0823529412, 0.376470589, 0.7411764706, Color.kDenim),
arguments(0.0, 0.4, 0.7019607844, Color.kFirstBlue),
arguments(0.9294117648, 0.1098039216, 0.1411764706, Color.kFirstRed));
}
}

View File

@@ -4,14 +4,13 @@
package edu.wpi.first.wpilibj.util;
import org.junit.jupiter.api.Test;
import edu.wpi.first.wpilibj.UtilityClassTest;
import static edu.wpi.first.wpilibj.util.ErrorMessages.requireNonNullParam;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import edu.wpi.first.wpilibj.UtilityClassTest;
import org.junit.jupiter.api.Test;
class ErrorMessagesTest extends UtilityClassTest<ErrorMessages> {
ErrorMessagesTest() {
super(ErrorMessages.class);
@@ -19,8 +18,8 @@ class ErrorMessagesTest extends UtilityClassTest<ErrorMessages> {
@Test
void requireNonNullParamNullTest() {
assertThrows(NullPointerException.class, () -> requireNonNullParam(null, "testParam",
"testMethod"));
assertThrows(
NullPointerException.class, () -> requireNonNullParam(null, "testParam", "testMethod"));
}
@Test