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,99 @@
// 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.smartdashboard;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.util.Color8Bit;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class Mechanism2dTest {
private NetworkTableInstance m_inst;
@BeforeEach
void setUp() {
m_inst = NetworkTableInstance.create();
SmartDashboard.setNetworkTableInstance(m_inst);
}
@Test
void testCanvas() {
try (var mechanism = new Mechanism2d(5, 10);
var dimsEntry = m_inst.getEntry("/SmartDashboard/mechanism/dims");
var colorEntry = m_inst.getEntry("/SmartDashboard/mechanism/backgroundColor")) {
SmartDashboard.putData("mechanism", mechanism);
SmartDashboard.updateValues();
assertArrayEquals(new double[] {5, 10}, dimsEntry.getDoubleArray(new double[0]));
assertEquals("#000020", colorEntry.getString(""));
mechanism.setBackgroundColor(new Color8Bit(255, 255, 255));
SmartDashboard.updateValues();
assertEquals("#FFFFFF", colorEntry.getString(""));
}
}
@Test
void testRoot() {
try (var mechanism = new Mechanism2d(5, 10);
var xEntry = m_inst.getEntry("/SmartDashboard/mechanism/root/x");
var yEntry = m_inst.getEntry("/SmartDashboard/mechanism/root/y")) {
final var root = mechanism.getRoot("root", 1, 2);
SmartDashboard.putData("mechanism", mechanism);
SmartDashboard.updateValues();
assertEquals(1, xEntry.getDouble(0));
assertEquals(2, yEntry.getDouble(0));
root.setPosition(2, 4);
SmartDashboard.updateValues();
assertEquals(2, xEntry.getDouble(0));
assertEquals(4, yEntry.getDouble(0));
}
}
@Test
void testLigament() {
try (var mechanism = new Mechanism2d(5, 10);
var angleEntry = m_inst.getEntry("/SmartDashboard/mechanism/root/ligament/angle");
var colorEntry = m_inst.getEntry("/SmartDashboard/mechanism/root/ligament/color");
var lengthEntry = m_inst.getEntry("/SmartDashboard/mechanism/root/ligament/length");
var weightEntry = m_inst.getEntry("/SmartDashboard/mechanism/root/ligament/weight")) {
var root = mechanism.getRoot("root", 1, 2);
var ligament =
root.append(new MechanismLigament2d("ligament", 3, 90, 1, new Color8Bit(255, 255, 255)));
SmartDashboard.putData("mechanism", mechanism);
SmartDashboard.updateValues();
assertEquals(ligament.getAngle(), angleEntry.getDouble(0));
assertEquals(ligament.getColor().toHexString(), colorEntry.getString(""));
assertEquals(ligament.getLength(), lengthEntry.getDouble(0));
assertEquals(ligament.getLineWeight(), weightEntry.getDouble(0));
ligament.setAngle(45);
ligament.setColor(new Color8Bit(0, 0, 0));
ligament.setLength(2);
ligament.setLineWeight(4);
SmartDashboard.updateValues();
assertEquals(ligament.getAngle(), angleEntry.getDouble(0));
assertEquals(ligament.getColor().toHexString(), colorEntry.getString(""));
assertEquals(ligament.getLength(), lengthEntry.getDouble(0));
assertEquals(ligament.getLineWeight(), weightEntry.getDouble(0));
angleEntry.setDouble(22.5);
colorEntry.setString("#FF00FF");
lengthEntry.setDouble(4);
weightEntry.setDouble(6);
SmartDashboard.updateValues();
assertEquals(ligament.getAngle(), angleEntry.getDouble(0));
assertEquals(ligament.getColor().toHexString(), colorEntry.getString(""));
assertEquals(ligament.getLength(), lengthEntry.getDouble(0));
assertEquals(ligament.getLineWeight(), weightEntry.getDouble(0));
}
}
@AfterEach
void tearDown() {
m_inst.close();
SmartDashboard.setNetworkTableInstance(NetworkTableInstance.getDefault());
}
}

View File

@@ -0,0 +1,94 @@
// 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.smartdashboard;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.simulation.SendableChooserSim;
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.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
class SendableChooserTest {
private NetworkTableInstance m_inst;
@BeforeEach
void setUp() {
m_inst = NetworkTableInstance.create();
SmartDashboard.setNetworkTableInstance(m_inst);
}
@ValueSource(ints = {0, 1, 2, 3})
@ParameterizedTest
void returnsSelected(int toSelect) {
try (var chooser = new SendableChooser<Integer>();
var chooserSim =
new SendableChooserSim(
m_inst, "/SmartDashboard/returnsSelectedChooser" + toSelect + "/")) {
for (int i = 1; i <= 3; i++) {
chooser.addOption(String.valueOf(i), i);
}
chooser.setDefaultOption(String.valueOf(0), 0);
SmartDashboard.putData("returnsSelectedChooser" + toSelect, chooser);
SmartDashboard.updateValues();
chooserSim.setSelected(String.valueOf(toSelect));
SmartDashboard.updateValues();
assertEquals(toSelect, chooser.getSelected());
}
}
@Test
void defaultIsReturnedOnNoSelect() {
try (var chooser = new SendableChooser<Integer>()) {
for (int i = 1; i <= 3; i++) {
chooser.addOption(String.valueOf(i), i);
}
chooser.setDefaultOption(String.valueOf(0), 0);
assertEquals(0, chooser.getSelected());
}
}
@Test
void nullIsReturnedOnNoSelectAndNoDefault() {
try (var chooser = new SendableChooser<Integer>()) {
for (int i = 1; i <= 3; i++) {
chooser.addOption(String.valueOf(i), i);
}
assertNull(chooser.getSelected());
}
}
@Test
void testChangeListener() {
try (var chooser = new SendableChooser<Integer>();
var chooserSim = new SendableChooserSim(m_inst, "/SmartDashboard/changeListenerChooser/")) {
for (int i = 1; i <= 3; i++) {
chooser.addOption(String.valueOf(i), i);
}
AtomicInteger currentVal = new AtomicInteger();
chooser.onChange(currentVal::set);
SmartDashboard.putData("changeListenerChooser", chooser);
SmartDashboard.updateValues();
chooserSim.setSelected("3");
SmartDashboard.updateValues();
assertEquals(3, currentVal.get());
}
}
@AfterEach
void tearDown() {
m_inst.close();
SmartDashboard.setNetworkTableInstance(NetworkTableInstance.getDefault());
}
}

View File

@@ -0,0 +1,125 @@
// 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.smartdashboard;
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 org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class SmartDashboardTest extends UtilityClassTest<SmartDashboard> {
private NetworkTableInstance m_inst;
private NetworkTable m_table;
SmartDashboardTest() {
super(SmartDashboard.class);
}
@BeforeEach
void beforeEach() {
m_inst = NetworkTableInstance.create();
m_table = m_inst.getTable("SmartDashboard");
SmartDashboard.setNetworkTableInstance(m_inst);
}
@AfterEach
void afterEach() {
m_inst.close();
}
@Test
void getBadValueTest() {
assertEquals("Expected", SmartDashboard.getString("KEY_SHOULD_NOT_BE_FOUND", "Expected"));
}
@Test
void putStringTest() {
final String key = "putString";
final String value = "thisIsAValue";
SmartDashboard.putString(key, value);
assertEquals(value, m_table.getEntry(key).getString(""));
}
@Test
void getStringTest() {
final String key = "getString";
final String value = "thisIsAValue";
m_table.getEntry(key).setString(value);
assertEquals(value, SmartDashboard.getString(key, ""));
}
@Test
void putNumberTest() {
final String key = "PutNumber";
final int value = 2147483647;
SmartDashboard.putNumber(key, value);
assertEquals(value, m_table.getEntry(key).getNumber(0).intValue());
}
@Test
void getNumberTest() {
final String key = "GetNumber";
final int value = 2147483647;
m_table.getEntry(key).setNumber(value);
assertEquals(value, SmartDashboard.getNumber(key, 0), 0.01);
}
@Test
void putBooleanTest() {
final String key = "PutBoolean";
final boolean value = true;
SmartDashboard.putBoolean(key, value);
assertEquals(value, m_table.getEntry(key).getBoolean(!value));
}
@Test
void getBooleanTest() {
final String key = "GetBoolean";
final boolean value = true;
m_table.getEntry(key).setBoolean(value);
assertEquals(value, SmartDashboard.getBoolean(key, !value));
}
@Test
void testReplaceString() {
final String key = "testReplaceString";
final String valueNew = "newValue";
m_table.getEntry(key).setString("oldValue");
SmartDashboard.putString(key, valueNew);
assertEquals(valueNew, m_table.getEntry(key).getString(""));
}
@Test
void putStringNullKeyTest() {
assertThrows(
NullPointerException.class, () -> SmartDashboard.putString(null, "This should not work"));
}
@Test
void putStringNullValueTest() {
assertThrows(
NullPointerException.class,
() -> SmartDashboard.putString("KEY_SHOULD_NOT_BE_STORED", null));
}
}