Commit 576d828b authored by schuegra's avatar schuegra
Browse files

[TraCI] Implement more tests

parent 71b4e2be
Pipeline #200373 passed with stages
in 118 minutes and 35 seconds
......@@ -262,7 +262,8 @@ public class PersonCommandHandler extends CommandHandler<PersonVar> {
.getElement(Integer.parseInt(cmd.getElementIdentifier()));
if (checkIfPedestrianExists(ped, cmd)) {
cmd.setResponse(responseOK(PersonVar.POS_3D.type, new Vector3D(ped.getPosition().x, ped.getPosition().y, 0.0)));
VPoint pos2d = ped.getPosition();
cmd.setResponse(responseOK(PersonVar.POS_3D.type, new Vector3D(pos2d.x, pos2d.y, 0.0)));
logger.debugf("time: %f Pedestrian: %s Position: %s",
state.getSimTimeInSec(),
cmd.getElementIdentifier(),
......
......@@ -22,6 +22,7 @@ import org.vadere.state.scenario.DynamicElementContainer;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.state.util.StateJsonConverter;
import org.vadere.util.geometry.Vector3D;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.Vector2D;
import org.vadere.util.io.IOUtils;
......@@ -50,13 +51,16 @@ public class PersonCommandHandlerTest extends CommandHandlerTest {
@Test
public void process_getHasNextTarget() {
PersonVar var = PersonVar.NEXT_TARGET_LIST_INDEX;
int varID = var.id;
TraCIDataType varType = var.type;
String elementID = "1";
int retVal = 1;
TraCIGetCommand cmd = (TraCIGetCommand) getFirstCommand(TraCIGetCommand.build(
TraCICmd.GET_PERSON_VALUE, varID, elementID));
// Return 1
int retVal = 1;
RemoteManager rm = new TestRemoteManager() {
@Override
protected void mockIt() {
......@@ -68,6 +72,20 @@ public class PersonCommandHandlerTest extends CommandHandlerTest {
testTraCICommand(ret, TraCICmd.GET_PERSON_VALUE, CmdType.VALUE_GET);
checkGET_OK(ret);
testGetValue(ret, varID, varType, elementID, retVal);
// Return 0
int retVal2 = 0;
RemoteManager rm2 = new TestRemoteManager() {
@Override
protected void mockIt() {
when(simState.getTopography().getPedestrianDynamicElements().getElement(Integer.parseInt(elementID)).hasNextTarget())
.thenReturn(false);
}
};
TraCICommand ret2 = persCmdHandler.process_getHasNextTarget(cmd, rm2);
testTraCICommand(ret2, TraCICmd.GET_PERSON_VALUE, CmdType.VALUE_GET);
checkGET_OK(ret2);
testGetValue(ret2, varID, varType, elementID, retVal2);
}
@Test
......@@ -250,6 +268,31 @@ public class PersonCommandHandlerTest extends CommandHandlerTest {
testGetValue(ret, varID, null, elementID, null);
}
@Test
public void process_getPosition3D() {
PersonVar var = PersonVar.POS_3D;
int varID = var.id;
TraCIDataType varType = var.type;;
String elementID = "1";
Vector3D retVal = new Vector3D(1.0, 1.0, 0.0);
VPoint retVal2D = new VPoint(retVal.x, retVal.y);
TraCIGetCommand cmd = (TraCIGetCommand) getFirstCommand(TraCIGetCommand.build(
TraCICmd.GET_PERSON_VALUE, varID, elementID));
RemoteManager rm = new TestRemoteManager() {
@Override
protected void mockIt() {
Pedestrian ped = mock(Pedestrian.class, Mockito.RETURNS_DEEP_STUBS);
when(ped.getPosition()).thenReturn(retVal2D);
when(simState.getTopography().getPedestrianDynamicElements().getElement(Integer.parseInt(elementID)))
.thenReturn(ped);
}
};
TraCICommand ret = persCmdHandler.process_getPosition3D(cmd, rm);
testTraCICommand(ret, TraCICmd.GET_PERSON_VALUE, CmdType.VALUE_GET);
checkGET_OK(ret);
testGetValue(ret, varID, varType, elementID, retVal);
}
@Test
public void process_getPosition2D() {
PersonVar var = PersonVar.POS_2D;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment