mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilib] Add IsJoystickConnected method (#2847)
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
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")
|
||||
void testIsConnected(int axisCount, int buttonCount, int povCount, boolean expected) {
|
||||
DriverStationSim.setJoystickAxisCount(1, axisCount);
|
||||
DriverStationSim.setJoystickButtonCount(1, buttonCount);
|
||||
DriverStationSim.setJoystickPOVCount(1, povCount);
|
||||
|
||||
DriverStationSim.notifyNewData();
|
||||
|
||||
assertEquals(expected, DriverStation.getInstance().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)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user