-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from isl-org/thias15/gamecontroller-test
add test for game controller
- Loading branch information
Showing
2 changed files
with
52 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
android/app/src/test/java/org/openbot/env/GameControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.openbot.env; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
import org.openbot.utils.Enums; | ||
import org.openbot.vehicle.Control; | ||
|
||
public class GameControllerTest { | ||
@Test | ||
public void convertDualToControl_test() { | ||
GameController gameController = new GameController(Enums.DriveMode.DUAL); | ||
assertEquals(Enums.DriveMode.DUAL, gameController.getDriveMode()); | ||
Control control = gameController.convertDualToControl(0.5f, -0.5f); | ||
assertEquals(control.getLeft(), -0.5f, 0.0f); | ||
assertEquals(control.getRight(), 0.5f, 0.0f); | ||
} | ||
|
||
@Test | ||
public void convertGameToControl_test() { | ||
GameController gameController = new GameController(Enums.DriveMode.GAME); | ||
assertEquals(Enums.DriveMode.GAME, gameController.getDriveMode()); | ||
Control control; | ||
control = gameController.convertGameToControl(0.0f, 0.5f, 1.0f); | ||
assertEquals(control.getLeft(), 1.0f, 0.0f); | ||
assertEquals(control.getRight(), -0.5f, 0.0f); | ||
|
||
control = gameController.convertGameToControl(0.0f, 0.5f, -1.0f); | ||
assertEquals(control.getLeft(), -0.5f, 0.0f); | ||
assertEquals(control.getRight(), 1.0f, 0.0f); | ||
|
||
control = gameController.convertGameToControl(0.0f, 0.5f, 0.0f); | ||
assertEquals(control.getLeft(), 0.5f, 0.0f); | ||
assertEquals(control.getRight(), 0.5f, 0.0f); | ||
} | ||
|
||
@Test | ||
public void convertJoystickToControl_test() { | ||
GameController gameController = new GameController(Enums.DriveMode.JOYSTICK); | ||
assertEquals(Enums.DriveMode.JOYSTICK, gameController.getDriveMode()); | ||
Control control; | ||
control = gameController.convertJoystickToControl(0.5f, -0.5f); | ||
assertEquals(control.getLeft(), 1.0f, 0.0f); | ||
assertEquals(control.getRight(), 0.0f, 0.0f); | ||
|
||
control = gameController.convertJoystickToControl(-0.5f, -0.5f); | ||
assertEquals(control.getLeft(), 0.0f, 0.0f); | ||
assertEquals(control.getRight(), 1.0f, 0.0f); | ||
} | ||
} |