From a378bd4cf67347172d7c63790b9e0abeaf1036c5 Mon Sep 17 00:00:00 2001 From: Jeffrey Mello Date: Tue, 24 Feb 2026 19:08:43 -0500 Subject: [PATCH 1/3] add unit tests for sorter still incomplete --- .../ftc/teamcode/LimeLightAutoBlue.java | 2 +- .../ftc/teamcode/LimeLightAutoBlueTEST.java | 2 +- .../ftc/teamcode/LimeLightAutoRed.java | 2 +- .../ftc/teamcode/TeleOpMain.java | 2 +- .../teamcode/Utils_13233/SorterControls.java | 9 +- .../ftc/teamcode/SorterControlsTest.java | 128 ++++++++++++++++++ 6 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoBlue.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoBlue.java index 327032e..9963c1d 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoBlue.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoBlue.java @@ -38,7 +38,7 @@ public void runOpMode() { launch = new LaunchControls(hardwareMap); motors = new MotorConstructor(hardwareMap); limelightCont = new LimelightControls(hardwareMap); - sorter = new SorterControls(motors); + sorter = new SorterControls(hardwareMap); waitForStart(); diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoBlueTEST.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoBlueTEST.java index ae0e13c..4b433dd 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoBlueTEST.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoBlueTEST.java @@ -36,7 +36,7 @@ public void runOpMode() { launch = new LaunchControls(hardwareMap); motors = new MotorConstructor(hardwareMap); limelightCont = new LimelightControls(hardwareMap); - sorter = new SorterControls(motors); + sorter = new SorterControls(hardwareMap); telemetry.addLine("Initialized. Waiting for start..."); telemetry.update(); diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoRed.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoRed.java index c688960..9e00750 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoRed.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/LimeLightAutoRed.java @@ -36,7 +36,7 @@ public void runOpMode() { launch = new LaunchControls(hardwareMap); motors = new MotorConstructor(hardwareMap); limelightCont = new LimelightControls(hardwareMap); - sorter = new SorterControls(motors); + sorter = new SorterControls(hardwareMap); telemetry.addLine("Initialized. Waiting for start..."); telemetry.update(); diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOpMain.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOpMain.java index 3202d0d..a544162 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOpMain.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/TeleOpMain.java @@ -54,7 +54,7 @@ public void runOpMode() { drive = new DriveControls(hardwareMap); launch = new LaunchControls(hardwareMap); motors = new MotorConstructor(hardwareMap); - sorter = new SorterControls(motors); + sorter = new SorterControls(hardwareMap); intake = new IntakeControls(hardwareMap); diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils_13233/SorterControls.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils_13233/SorterControls.java index 0675c6c..07aaa62 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils_13233/SorterControls.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils_13233/SorterControls.java @@ -1,6 +1,7 @@ package org.firstinspires.ftc.teamcode.Utils_13233; import com.qualcomm.robotcore.hardware.DcMotor; +import com.qualcomm.robotcore.hardware.HardwareMap; public class SorterControls { @@ -24,8 +25,8 @@ public class SorterControls { // Motor Speed float motorSpeed = 1.0f; - public SorterControls(MotorConstructor motors) { - this.motors = motors; + public SorterControls(HardwareMap hardwareMap) { + this.motors = new MotorConstructor(hardwareMap); } /** @@ -33,7 +34,7 @@ public SorterControls(MotorConstructor motors) { * * @param pos Enum to determine what positon to move to */ - private void moveToIntakePos(intakePos pos) { + public void moveToIntakePos(intakePos pos) { switch (pos) { case INTAKE_POS_1: motors.Sorter.setTargetPosition(intakePos1); @@ -59,7 +60,7 @@ private void moveToIntakePos(intakePos pos) { * * @param pos Enum to determine what positon to move to */ - private void moveToLaunchPos(launchPos pos) { + public void moveToLaunchPos(launchPos pos) { switch (pos) { case LAUNCH_POS_1: motors.Sorter.setTargetPosition(LaunchPos1); diff --git a/TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java b/TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java new file mode 100644 index 0000000..d0c4ac5 --- /dev/null +++ b/TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java @@ -0,0 +1,128 @@ +package org.firstinspires.ftc.teamcode; + +import static org.mockito.Mockito.verify; + +import com.qualcomm.robotcore.hardware.DcMotor; + +import org.firstinspires.ftc.teamcode.Utils_13233.SorterControls; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class SorterControlsTest { + public SorterControls sorter; + + MockMotorUtil mockMotor = new MockMotorUtil(); + + @BeforeEach + void motorSetup() { + mockMotor.setUp(); + sorter = new SorterControls(mockMotor.hardwareMap); + } + + + // Test Move to intake position + @DisplayName("should set the sorter to the intake position 1") + @Test + void testMoveToIntakePos_pos1() { + sorter.moveToIntakePos(SorterControls.intakePos.INTAKE_POS_1); + + verify(mockMotor.Sorter).setTargetPosition(sorter.intakePos1); + } + + @DisplayName("should set the sorter to the intake position 2") + @Test + void testMoveToIntakePos_pos2() { + sorter.moveToIntakePos(SorterControls.intakePos.INTAKE_POS_2); + + verify(mockMotor.Sorter).setTargetPosition(sorter.intakePos2); + } + + @DisplayName("should set the sorter to the intake position 3") + @Test + void testMoveToIntakePos_pos3() { + sorter.moveToIntakePos(SorterControls.intakePos.INTAKE_POS_3); + + verify(mockMotor.Sorter).setTargetPosition(sorter.intakePos3); + } + + + // Test Move to launch position + @DisplayName("should set the sorter to the launch position 1") + @Test + void testMoveToLaunchPos_pos1() { + sorter.moveToLaunchPos(SorterControls.launchPos.LAUNCH_POS_1); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos1); + } + + @DisplayName("should set the sorter to the launch position 2") + @Test + void testMoveToLaunchPos_pos2() { + sorter.moveToLaunchPos(SorterControls.launchPos.LAUNCH_POS_2); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos2); + } + + @DisplayName("should set the sorter to the launch position 3") + @Test + void testMoveToLaunchPos_pos3() { + sorter.moveToLaunchPos(SorterControls.launchPos.LAUNCH_POS_3); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos3); + } + + // Test Move to sorter position + @DisplayName("should set the sorter to the intake position 1") + @Test + void testMoveSorterToPos_intake_pos1() { + sorter.moveSorterToPos(SorterControls.sorterModes.INTAKE, 1); + + verify(mockMotor.Sorter).setTargetPosition(sorter.intakePos1); + } + + // Test Move to sorter position + @DisplayName("should set the sorter to the intake position 2") + @Test + void testMoveSorterToPos_intake_pos2() { + sorter.moveSorterToPos(SorterControls.sorterModes.INTAKE, 2); + + verify(mockMotor.Sorter).setTargetPosition(sorter.intakePos2); + } + + // Test Move to sorter position + @DisplayName("should set the sorter to the intake position 3") + @Test + void testMoveSorterToPos_intake_pos3() { + sorter.moveSorterToPos(SorterControls.sorterModes.INTAKE, 3); + + verify(mockMotor.Sorter).setTargetPosition(sorter.intakePos3); + } + + @DisplayName("should set the sorter to the intake position 1") + @Test + void testMoveSorterToPos_launch_pos1() { + sorter.moveSorterToPos(SorterControls.sorterModes.LAUNCH, 1); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos1); + } + + // Test Move to sorter position + @DisplayName("should set the sorter to the intake position 2") + @Test + void testMoveSorterToPos_launch_pos2() { + sorter.moveSorterToPos(SorterControls.sorterModes.LAUNCH, 2); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos2); + } + + // Test Move to sorter position + @DisplayName("should set the sorter to the intake position 3") + @Test + void testMoveSorterToPos_launch_pos3() { + sorter.moveSorterToPos(SorterControls.sorterModes.LAUNCH, 3); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos3); + } +} + From 5115b73aa7318a5237dc2d69a26edb2c58e48238 Mon Sep 17 00:00:00 2001 From: Jeffrey Mello Date: Mon, 2 Mar 2026 11:47:21 -0500 Subject: [PATCH 2/3] created unit tests for ```simpleSorterPosition``` --- .../ftc/teamcode/SorterControlsTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java b/TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java index d0c4ac5..92fae2b 100644 --- a/TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java +++ b/TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java @@ -124,5 +124,59 @@ void testMoveSorterToPos_launch_pos3() { verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos3); } + + @DisplayName("should set the sorter to the intake position 1") + @Test + void testMoveSimpleSorterToPos_intake_pos1() { + sorter.simpleSorterPosition(true, false, + false, SorterControls.sorterModes.INTAKE); + + verify(mockMotor.Sorter).setTargetPosition(sorter.intakePos1); + } + + @DisplayName("should set the sorter to the intake position 1") + @Test + void testMoveSimpleSorterToPos_intake_pos2() { + sorter.simpleSorterPosition(false, true, + false, SorterControls.sorterModes.INTAKE); + + verify(mockMotor.Sorter).setTargetPosition(sorter.intakePos2); + } + + @DisplayName("should set the sorter to the intake position 1") + @Test + void testMoveSimpleSorterToPos_intake_pos3() { + sorter.simpleSorterPosition(false, false, + true, SorterControls.sorterModes.INTAKE); + + verify(mockMotor.Sorter).setTargetPosition(sorter.intakePos3); + } + + @DisplayName("should set the sorter to the intake position 1") + @Test + void testMoveSimpleSorterToPos_launch_pos1() { + sorter.simpleSorterPosition(true, false, + false, SorterControls.sorterModes.LAUNCH); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos1); + } + + @DisplayName("should set the sorter to the intake position 1") + @Test + void testMoveSimpleSorterToPos_launch_pos2() { + sorter.simpleSorterPosition(false, true, + false, SorterControls.sorterModes.LAUNCH); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos2); + } + + @DisplayName("should set the sorter to the intake position 1") + @Test + void testMoveSimpleSorterToPos_launch_pos3() { + sorter.simpleSorterPosition(false, false, + true, SorterControls.sorterModes.LAUNCH); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos3); + } } From 032e32f7083825805395e4349252bf317d7f1b70 Mon Sep 17 00:00:00 2001 From: Jeffrey Mello Date: Mon, 2 Mar 2026 12:07:45 -0500 Subject: [PATCH 3/3] created unit test for the move to color methods sorterControls now has 100% test coverage --- .../ftc/teamcode/SorterControlsTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java b/TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java index 92fae2b..df4438d 100644 --- a/TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java +++ b/TeamCode/src/test/java/org/firstinspires/ftc/teamcode/SorterControlsTest.java @@ -1,5 +1,6 @@ package org.firstinspires.ftc.teamcode; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.verify; import com.qualcomm.robotcore.hardware.DcMotor; @@ -72,6 +73,7 @@ void testMoveToLaunchPos_pos3() { verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos3); } + // Test Move to sorter position @DisplayName("should set the sorter to the intake position 1") @Test @@ -99,6 +101,14 @@ void testMoveSorterToPos_intake_pos3() { verify(mockMotor.Sorter).setTargetPosition(sorter.intakePos3); } + @DisplayName("should throw a runtime exception") + @Test + void testMoveSorterToPos_intake_runtimeException() { + assertThrows(RuntimeException.class, () -> { + sorter.moveSorterToPos(SorterControls.sorterModes.INTAKE, 4); + }); + } + @DisplayName("should set the sorter to the intake position 1") @Test void testMoveSorterToPos_launch_pos1() { @@ -125,6 +135,14 @@ void testMoveSorterToPos_launch_pos3() { verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos3); } + @DisplayName("should throw a runtime exception") + @Test + void testMoveSorterToPos_launch_runtimeException() { + assertThrows(RuntimeException.class, () -> { + sorter.moveSorterToPos(SorterControls.sorterModes.LAUNCH, 4); + }); + } + @DisplayName("should set the sorter to the intake position 1") @Test void testMoveSimpleSorterToPos_intake_pos1() { @@ -178,5 +196,67 @@ void testMoveSimpleSorterToPos_launch_pos3() { verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos3); } + + @DisplayName("should set the sorter to the launch position 1") + @Test + void testMoveGreenToLaunchPos_1() { + sorter.currentSorterStates[0] = SorterControls.ballColors.GREEN; + + sorter.moveGreenToLaunchPos(); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos1); + } + + @DisplayName("should set the sorter to the launch position 1") + @Test + void testMoveGreenToLaunchPos_2() { + sorter.currentSorterStates[1] = SorterControls.ballColors.GREEN; + + sorter.moveGreenToLaunchPos(); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos2); + } + + @DisplayName("should set the sorter to the launch position 1") + @Test + void testMoveGreenToLaunchPos_3() { + sorter.currentSorterStates[2] = SorterControls.ballColors.GREEN; + + sorter.moveGreenToLaunchPos(); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos3); + } + + @DisplayName("should set the sorter to the launch position 1") + @Test + void testMovePurpleToLaunchPos_1() { + sorter.currentSorterStates[0] = SorterControls.ballColors.PURPLE; + + sorter.moveToPurpleLaunchPos(); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos1); + } + + @DisplayName("should set the sorter to the launch position 1") + @Test + void testMovePurpleToLaunchPos_2() { + sorter.currentSorterStates[1] = SorterControls.ballColors.PURPLE; + + sorter.moveToPurpleLaunchPos(); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos2); + } + + @DisplayName("should set the sorter to the launch position 1") + @Test + void testMovePurpleToLaunchPos_3() { + sorter.currentSorterStates[0] = SorterControls.ballColors.NULL; + sorter.currentSorterStates[1] = SorterControls.ballColors.NULL; + sorter.currentSorterStates[2] = SorterControls.ballColors.PURPLE; + + sorter.moveToPurpleLaunchPos(); + + verify(mockMotor.Sorter).setTargetPosition(sorter.LaunchPos3); + } }