📄 localcontrollertest.java.svn-base
字号:
package test;
import java.util.ArrayList;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
import mock.*;
import agents.*;
import world.Gate;
import world.Plane;
import world.Runway;
import world.Strip;
import world.Taxiway;
import world.Tower;
import base.World;
import base.WorldObject;
public class LocalControllerTest extends TestCase {
MockGroundController gc = null;
LocalControllerAgent lc = null;
MockPilot pilot = null;
Plane plane = null;
Strip strip = null;
Gate gate = null;
Tower tower = null;
Taxiway taxiway = null;
Runway runway = null;
ArrayList<Taxiway> directions = null;
public void testLanding()
{
tower = new Tower();
gc = new MockGroundController("gc1");
lc = new LocalControllerAgent("lc1", tower, gc);
pilot = new MockPilot("pilot");
plane = new MockPlane("swa111");
plane.ctrlAssumePilotRole(pilot);
taxiway = new Taxiway();
gate = new Gate(taxiway);
tower = new Tower();
runway = new Runway();
strip = new Strip("swa111");
lc.msgNewArrivingFlight("swa111", runway, gate);
lc.msgRequestToLand("swa111","visual",runway);
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message ClearanceToLand",
pilot.log.containsString("msgClearanceToLand"));
lc.msgConfirmClearanceToLand("swa111", runway);
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message LandingPath",
pilot.log.containsString("msgLandingPath"));
assertTrue("Ground controller received message New Arrival strip",
gc.log.containsString("msgNewArrivalStrip"));
}
public void testDeparting() {
tower = new Tower();
gc = new MockGroundController("gc2");
lc = new LocalControllerAgent("lc2", tower, gc);
pilot = new MockPilot("pilot2");
plane = new MockPlane("swa222");
plane.ctrlAssumePilotRole(pilot);
taxiway = new Taxiway();
gate = new Gate(taxiway);
tower = new Tower();
runway = new Runway();
strip = new Strip("swa222");
lc.msgNewDepartureStrip(strip);
lc.msgReadyForTakeoff("swa222", runway);
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message PositionAndHold",
pilot.log.containsString("msgPositionAndHold"));
lc.msgConfirmPositionAndHold("swa222");
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message ClearedForTakeoff",
pilot.log.containsString("msgClearedForTakeoff"));
lc.msgConfirmClearedForTakeoff("swa222", runway);
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message contactDepartureControl",
pilot.log.containsString("msgContactDepartureControl"));
}
// This test shows that two airplanes landing on different runways is passed
// for clearance by the local controller
public void test2planeslanding() {
taxiway = new Taxiway();
gate = new Gate(taxiway);
tower = new Tower();
runway = new Runway();
Runway runwaytwo = new Runway();
gc = new MockGroundController("gc2");
lc = new LocalControllerAgent("lc2", tower, gc);
MockPilot pilotone, pilottwo;
MockPlane planeone, planetwo;
Strip stripone, striptwo;
pilotone = new MockPilot("pilotone");
pilottwo = new MockPilot("pilottwo");
planeone = new MockPlane("swa333");
planeone.ctrlAssumePilotRole(pilotone);
planetwo = new MockPlane("swa444");
planetwo.ctrlAssumePilotRole(pilottwo);
stripone = new Strip("swa333");
striptwo = new Strip("swa444");
lc.msgNewArrivingFlight("swa333", runway, gate);
lc.msgRequestToLand("swa333","visual",runway);
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message ClearanceToLand",
pilotone.log.containsString("msgClearanceToLand"));
lc.msgConfirmClearanceToLand("swa333", runway);
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message LandingPath",
pilotone.log.containsString("msgLandingPath"));
assertTrue("Ground controller received message New Arrival strip",
gc.log.containsString("msgNewArrivalStrip"));
lc.msgNewArrivingFlight("swa444", runwaytwo, gate);
lc.msgRequestToLand("swa444","visual",runwaytwo);
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message ClearanceToLand",
pilottwo.log.containsString("msgClearanceToLand"));
lc.msgConfirmClearanceToLand("swa444", runway);
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message LandingPath",
pilottwo.log.containsString("msgLandingPath"));
assertTrue("Ground controller received message New Arrival strip",
gc.log.containsString("msgNewArrivalStrip"));
}
public void test2planeslandingatsamerunway() {
taxiway = new Taxiway();
gate = new Gate(taxiway);
tower = new Tower();
runway = new Runway();
gc = new MockGroundController("gc2");
lc = new LocalControllerAgent("lc2", tower, gc);
MockPilot pilotone, pilottwo;
MockPlane planeone, planetwo;
Strip stripone, striptwo;
pilotone = new MockPilot("pilotone");
pilottwo = new MockPilot("pilottwo");
planeone = new MockPlane("swa555");
planeone.ctrlAssumePilotRole(pilotone);
planetwo = new MockPlane("swa666");
planetwo.ctrlAssumePilotRole(pilottwo);
stripone = new Strip("swa555");
striptwo = new Strip("swa555");
lc.msgNewArrivingFlight("swa555", runway, gate);
lc.msgRequestToLand("swa555","visual",runway);
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message ClearanceToLand",
pilotone.log.containsString("msgClearanceToLand"));
lc.msgConfirmClearanceToLand("swa555", runway);
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message LandingPath",
pilotone.log.containsString("msgLandingPath"));
assertTrue("Ground controller received message New Arrival strip",
gc.log.containsString("msgNewArrivalStrip"));
lc.msgNewArrivingFlight("swa666", runway, gate);
lc.msgRequestToLand("swa666","visual",runway);
lc.pickAndExecuteAnAction();
// The pilot was not allowed to land on the same runway as the other pilot
assertFalse("Pilot received message ClearanceToLand",
pilottwo.log.containsString("msgClearanceToLand"));
assertTrue("Pilot received message NotClearedToLand",
pilottwo.log.containsString("msgNotClearedToLand"));
}
public void test2PlanesDepartingFromSameRunway() {
tower = new Tower();
gc = new MockGroundController("gc2");
lc = new LocalControllerAgent("lc2", tower, gc);
MockPilot pilotone, pilottwo;
MockPlane planeone, planetwo;
Strip stripone, striptwo;
pilotone = new MockPilot("pilot2");
planeone = new MockPlane("swa110");
planeone.ctrlAssumePilotRole(pilotone);
pilottwo = new MockPilot("pilot3");
planetwo = new MockPlane("swa101");
planetwo.ctrlAssumePilotRole(pilottwo);
taxiway = new Taxiway();
gate = new Gate(taxiway);
tower = new Tower();
runway = new Runway();
stripone = new Strip("swa110");
striptwo = new Strip("swa101");
lc.msgNewDepartureStrip(stripone);
lc.msgNewDepartureStrip(striptwo);
lc.msgReadyForTakeoff("swa110", runway);
lc.msgReadyForTakeoff("swa101", runway);
lc.pickAndExecuteAnAction();
assertTrue("Pilot received message PositionAndHold",
pilotone.log.containsString("msgPositionAndHold"));
lc.msgConfirmPositionAndHold("swa110");
lc.pickAndExecuteAnAction();
// Make sure that the pilot did not receive clearance to take off
assertFalse("Pilot received message ClearedForTakeoff",
pilotone.log.containsString("msgClearedForTakeoff"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -