SCRIPT Move java files

This commit is contained in:
PJ Reiniger
2025-11-07 19:55:40 -05:00
committed by Peter Johnson
parent 7ca1be9bae
commit c350c5f112
1486 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj;
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;
class DriverStationTest {
@ParameterizedTest
@MethodSource("isConnectedProvider")
void testIsConnected(int axisCount, int buttonCount, int povCount, boolean expected) {
DriverStationSim.setJoystickAxesMaximumIndex(1, axisCount);
DriverStationSim.setJoystickButtonsMaximumIndex(1, buttonCount);
DriverStationSim.setJoystickPOVsMaximumIndex(1, povCount);
DriverStationSim.notifyNewData();
assertEquals(expected, DriverStation.isJoystickConnected(1));
}
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));
}
@MethodSource("connectionWarningProvider")
void testConnectionWarnings(boolean fms, boolean silence, boolean expected) {
DriverStationSim.setFmsAttached(fms);
DriverStationSim.notifyNewData();
DriverStation.silenceJoystickConnectionWarning(silence);
assertEquals(expected, DriverStation.isJoystickConnectionWarningSilenced());
}
static Stream<Arguments> connectionWarningProvider() {
return Stream.of(
arguments(false, true, true),
arguments(false, false, false),
arguments(true, true, false),
arguments(true, false, false));
}
}

View File

@@ -0,0 +1,56 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.wpilibj.GenericHID.RumbleType;
import edu.wpi.first.wpilibj.simulation.GenericHIDSim;
import org.junit.jupiter.api.Test;
class GenericHIDTest {
private static final double kEpsilon = 0.0001;
@Test
void testRumbleRange() {
GenericHID hid = new GenericHID(0);
GenericHIDSim sim = new GenericHIDSim(0);
for (int i = 0; i <= 100; i++) {
double rumbleValue = i / 100.0;
hid.setRumble(RumbleType.kBothRumble, rumbleValue);
assertEquals(rumbleValue, sim.getRumble(RumbleType.kLeftRumble), kEpsilon);
assertEquals(rumbleValue, sim.getRumble(RumbleType.kRightRumble), kEpsilon);
}
}
@Test
void testRumbleTypes() {
GenericHID hid = new GenericHID(0);
GenericHIDSim sim = new GenericHIDSim(0);
// Make sure both are off
hid.setRumble(RumbleType.kBothRumble, 0);
assertEquals(0, sim.getRumble(RumbleType.kBothRumble), kEpsilon);
// test both
hid.setRumble(RumbleType.kBothRumble, 1);
assertEquals(1, sim.getRumble(RumbleType.kLeftRumble), kEpsilon);
assertEquals(1, sim.getRumble(RumbleType.kRightRumble), kEpsilon);
hid.setRumble(RumbleType.kBothRumble, 0);
// test left only
hid.setRumble(RumbleType.kLeftRumble, 1);
assertEquals(1, sim.getRumble(RumbleType.kLeftRumble), kEpsilon);
assertEquals(0, sim.getRumble(RumbleType.kRightRumble), kEpsilon);
hid.setRumble(RumbleType.kLeftRumble, 0);
// test right only
hid.setRumble(RumbleType.kRightRumble, 1);
assertEquals(0, sim.getRumble(RumbleType.kLeftRumble), kEpsilon);
assertEquals(1, sim.getRumble(RumbleType.kRightRumble), kEpsilon);
hid.setRumble(RumbleType.kRightRumble, 0);
}
}

View File

@@ -0,0 +1,173 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj;
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.JoystickSim;
import org.junit.jupiter.api.Test;
class JoystickTest {
@Test
void testGetX() {
HAL.initialize(500, 0);
Joystick joy = new Joystick(1);
JoystickSim joysim = new JoystickSim(joy);
joysim.setX(0.25);
joysim.notifyNewData();
assertEquals(0.25, joy.getX(), 0.001);
joysim.setX(0);
joysim.notifyNewData();
assertEquals(0.0, joy.getX(), 0.001);
}
@Test
void testGetY() {
HAL.initialize(500, 0);
Joystick joy = new Joystick(1);
JoystickSim joysim = new JoystickSim(joy);
joysim.setY(0.25);
joysim.notifyNewData();
assertEquals(0.25, joy.getY(), 0.001);
joysim.setY(0);
joysim.notifyNewData();
assertEquals(0.0, joy.getY(), 0.001);
}
@Test
void testGetZ() {
HAL.initialize(500, 0);
Joystick joy = new Joystick(1);
JoystickSim joysim = new JoystickSim(joy);
joysim.setZ(0.25);
joysim.notifyNewData();
assertEquals(0.25, joy.getZ(), 0.001);
joysim.setZ(0);
joysim.notifyNewData();
assertEquals(0.0, joy.getZ(), 0.001);
}
@Test
void testGetTwist() {
HAL.initialize(500, 0);
Joystick joy = new Joystick(1);
JoystickSim joysim = new JoystickSim(joy);
joysim.setTwist(0.25);
joysim.notifyNewData();
assertEquals(0.25, joy.getTwist(), 0.001);
joysim.setTwist(0);
joysim.notifyNewData();
assertEquals(0.0, joy.getTwist(), 0.001);
}
@Test
void testGetThrottle() {
HAL.initialize(500, 0);
Joystick joy = new Joystick(1);
JoystickSim joysim = new JoystickSim(joy);
joysim.setThrottle(0.25);
joysim.notifyNewData();
assertEquals(0.25, joy.getThrottle(), 0.001);
joysim.setThrottle(0);
joysim.notifyNewData();
assertEquals(0.0, joy.getThrottle(), 0.001);
}
@Test
void testGetTrigger() {
HAL.initialize(500, 0);
Joystick joy = new Joystick(1);
JoystickSim joysim = new JoystickSim(joy);
joysim.setTrigger(true);
joysim.notifyNewData();
assertTrue(joy.getTrigger());
joysim.setTrigger(false);
joysim.notifyNewData();
assertFalse(joy.getTrigger());
}
@Test
void testGetTop() {
HAL.initialize(500, 0);
Joystick joy = new Joystick(1);
JoystickSim joysim = new JoystickSim(joy);
joysim.setTop(true);
joysim.notifyNewData();
assertTrue(joy.getTop());
joysim.setTop(false);
joysim.notifyNewData();
assertFalse(joy.getTop());
}
@Test
void testGetMagnitude() {
HAL.initialize(500, 0);
Joystick joy = new Joystick(1);
JoystickSim joysim = new JoystickSim(joy);
// X Only
joysim.setX(0.5);
joysim.setY(0.0);
joysim.notifyNewData();
assertEquals(0.5, joy.getMagnitude(), 0.001);
// Y Only
joysim.setX(0.0);
joysim.setY(-0.5);
joysim.notifyNewData();
assertEquals(0.5, joy.getMagnitude(), 0.001);
// Both
joysim.setX(0.5);
joysim.setY(-0.5);
joysim.notifyNewData();
assertEquals(0.70710678118, joy.getMagnitude(), 0.001);
}
@Test
void testGetDirection() {
HAL.initialize(500, 0);
Joystick joy = new Joystick(1);
JoystickSim joysim = new JoystickSim(joy);
// X Only
joysim.setX(0.5);
joysim.setY(0.0);
joysim.notifyNewData();
assertEquals(90, joy.getDirectionDegrees(), 0.001);
assertEquals(Math.toRadians(90), joy.getDirectionRadians(), 0.001);
// Y Only
joysim.setX(0.0);
joysim.setY(-0.5);
joysim.notifyNewData();
assertEquals(0, joy.getDirectionDegrees(), 0.001);
assertEquals(Math.toRadians(0), joy.getDirectionRadians(), 0.001);
// Both
joysim.setX(0.5);
joysim.setY(-0.5);
joysim.notifyNewData();
assertEquals(45, joy.getDirectionDegrees(), 0.001);
assertEquals(Math.toRadians(45), joy.getDirectionRadians(), 0.001);
}
}

View File

@@ -0,0 +1,79 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj;
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.PS4ControllerSim;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
class PS4ControllerTest {
@ParameterizedTest
@EnumSource(value = PS4Controller.Button.class)
void testButtons(PS4Controller.Button button)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
HAL.initialize(500, 0);
PS4Controller joy = new PS4Controller(2);
PS4ControllerSim joysim = new PS4ControllerSim(joy);
var buttonName = button.toString();
String simSetMethodName = "set" + buttonName;
String joyGetMethodName = "get" + buttonName;
String joyPressedMethodName = "get" + buttonName + "Pressed";
String joyReleasedMethodName = "get" + buttonName + "Released";
final Method simSetMethod = joysim.getClass().getMethod(simSetMethodName, boolean.class);
final Method joyGetMethod = joy.getClass().getMethod(joyGetMethodName);
final Method joyPressedMethod = joy.getClass().getMethod(joyPressedMethodName);
final Method joyReleasedMethod = joy.getClass().getMethod(joyReleasedMethodName);
simSetMethod.invoke(joysim, false);
joysim.notifyNewData();
assertFalse((Boolean) joyGetMethod.invoke(joy));
// need to call pressed and released to clear flags
joyPressedMethod.invoke(joy);
joyReleasedMethod.invoke(joy);
simSetMethod.invoke(joysim, true);
joysim.notifyNewData();
assertTrue((Boolean) joyGetMethod.invoke(joy));
assertTrue((Boolean) joyPressedMethod.invoke(joy));
assertFalse((Boolean) joyReleasedMethod.invoke(joy));
simSetMethod.invoke(joysim, false);
joysim.notifyNewData();
assertFalse((Boolean) joyGetMethod.invoke(joy));
assertFalse((Boolean) joyPressedMethod.invoke(joy));
assertTrue((Boolean) joyReleasedMethod.invoke(joy));
}
@ParameterizedTest
@EnumSource(value = PS4Controller.Axis.class)
void testAxes(PS4Controller.Axis axis)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
HAL.initialize(500, 0);
PS4Controller joy = new PS4Controller(2);
PS4ControllerSim joysim = new PS4ControllerSim(joy);
var axisName = axis.toString();
String simSetMethodName = "set" + axisName;
String joyGetMethodName = "get" + axisName;
Method simSetMethod = joysim.getClass().getMethod(simSetMethodName, double.class);
Method joyGetMethod = joy.getClass().getMethod(joyGetMethodName);
simSetMethod.invoke(joysim, 0.35);
joysim.notifyNewData();
assertEquals(0.35, (Double) joyGetMethod.invoke(joy), 0.001);
}
}

View File

@@ -0,0 +1,79 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj;
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.PS5ControllerSim;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
class PS5ControllerTest {
@ParameterizedTest
@EnumSource(value = PS5Controller.Button.class)
void testButtons(PS5Controller.Button button)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
HAL.initialize(500, 0);
PS5Controller joy = new PS5Controller(2);
PS5ControllerSim joysim = new PS5ControllerSim(joy);
var buttonName = button.toString();
String simSetMethodName = "set" + buttonName;
String joyGetMethodName = "get" + buttonName;
String joyPressedMethodName = "get" + buttonName + "Pressed";
String joyReleasedMethodName = "get" + buttonName + "Released";
final Method simSetMethod = joysim.getClass().getMethod(simSetMethodName, boolean.class);
final Method joyGetMethod = joy.getClass().getMethod(joyGetMethodName);
final Method joyPressedMethod = joy.getClass().getMethod(joyPressedMethodName);
final Method joyReleasedMethod = joy.getClass().getMethod(joyReleasedMethodName);
simSetMethod.invoke(joysim, false);
joysim.notifyNewData();
assertFalse((Boolean) joyGetMethod.invoke(joy));
// need to call pressed and released to clear flags
joyPressedMethod.invoke(joy);
joyReleasedMethod.invoke(joy);
simSetMethod.invoke(joysim, true);
joysim.notifyNewData();
assertTrue((Boolean) joyGetMethod.invoke(joy));
assertTrue((Boolean) joyPressedMethod.invoke(joy));
assertFalse((Boolean) joyReleasedMethod.invoke(joy));
simSetMethod.invoke(joysim, false);
joysim.notifyNewData();
assertFalse((Boolean) joyGetMethod.invoke(joy));
assertFalse((Boolean) joyPressedMethod.invoke(joy));
assertTrue((Boolean) joyReleasedMethod.invoke(joy));
}
@ParameterizedTest
@EnumSource(value = PS5Controller.Axis.class)
void testAxes(PS5Controller.Axis axis)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
HAL.initialize(500, 0);
PS5Controller joy = new PS5Controller(2);
PS5ControllerSim joysim = new PS5ControllerSim(joy);
var axisName = axis.toString();
String simSetMethodName = "set" + axisName;
String joyGetMethodName = "get" + axisName;
Method simSetMethod = joysim.getClass().getMethod(simSetMethodName, double.class);
Method joyGetMethod = joy.getClass().getMethod(joyGetMethodName);
simSetMethod.invoke(joysim, 0.35);
joysim.notifyNewData();
assertEquals(0.35, (Double) joyGetMethod.invoke(joy), 0.001);
}
}

View File

@@ -0,0 +1,79 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj;
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 java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
class XboxControllerTest {
@ParameterizedTest
@EnumSource(value = XboxController.Button.class)
void testButtons(XboxController.Button button)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
HAL.initialize(500, 0);
XboxController joy = new XboxController(2);
XboxControllerSim joysim = new XboxControllerSim(joy);
var buttonName = button.toString();
String simSetMethodName = "set" + buttonName;
String joyGetMethodName = "get" + buttonName;
String joyPressedMethodName = "get" + buttonName + "Pressed";
String joyReleasedMethodName = "get" + buttonName + "Released";
final Method simSetMethod = joysim.getClass().getMethod(simSetMethodName, boolean.class);
final Method joyGetMethod = joy.getClass().getMethod(joyGetMethodName);
final Method joyPressedMethod = joy.getClass().getMethod(joyPressedMethodName);
final Method joyReleasedMethod = joy.getClass().getMethod(joyReleasedMethodName);
simSetMethod.invoke(joysim, false);
joysim.notifyNewData();
assertFalse((Boolean) joyGetMethod.invoke(joy));
// need to call pressed and released to clear flags
joyPressedMethod.invoke(joy);
joyReleasedMethod.invoke(joy);
simSetMethod.invoke(joysim, true);
joysim.notifyNewData();
assertTrue((Boolean) joyGetMethod.invoke(joy));
assertTrue((Boolean) joyPressedMethod.invoke(joy));
assertFalse((Boolean) joyReleasedMethod.invoke(joy));
simSetMethod.invoke(joysim, false);
joysim.notifyNewData();
assertFalse((Boolean) joyGetMethod.invoke(joy));
assertFalse((Boolean) joyPressedMethod.invoke(joy));
assertTrue((Boolean) joyReleasedMethod.invoke(joy));
}
@ParameterizedTest
@EnumSource(value = XboxController.Axis.class)
void testAxes(XboxController.Axis axis)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
HAL.initialize(500, 0);
XboxController joy = new XboxController(2);
XboxControllerSim joysim = new XboxControllerSim(joy);
var axisName = axis.toString();
String simSetMethodName = "set" + axisName;
String joyGetMethodName = "get" + axisName;
Method simSetMethod = joysim.getClass().getMethod(simSetMethodName, double.class);
Method joyGetMethod = joy.getClass().getMethod(joyGetMethodName);
simSetMethod.invoke(joysim, 0.35);
joysim.notifyNewData();
assertEquals(0.35, (Double) joyGetMethod.invoke(joy), 0.001);
}
}