private Drone CreateDrone(int id, int x, int y, int direction, char[] cmds) { // drone creation var drone = new Drone(id: id, x: x, y: y, direction: direction); var boundry = new MissionBoundary(new Region(0, 0, 0, 5, 5)); drone.MissionBoundary = boundry; // command creation var commandList = new List <Command>(); foreach (var cmd in cmds) { var command = new Command(cmd, id); command.BroadcastingSignal += drone.OnBroadcastingSignal; commandList.Add(command); } // mission creation var firstMission = new Mission(0, commandList); firstMission.TerminatedMission += drone.OnTerminatedMission; Missions.Add(firstMission); return(drone); }
public void ExecuteNextTestOneCommandsShoulBeExecuted() { //Arrange var drone = new Drone(id: 0, x: 1, y: 3, direction: 90); var boundry = new MissionBoundary(new Region(0, 0, 0, 5, 5)); drone.MissionBoundary = boundry; var commands = new List <Command>(); var command = new Command('*', 0); command.BroadcastingSignal += drone.OnBroadcastingSignal; commands.Add(command); command = new Command('>', 0); command.BroadcastingSignal += drone.OnBroadcastingSignal; commands.Add(command); var mission = new Mission(0, commands); mission.TerminatedMission += drone.OnTerminatedMission; //Act mission.ExecuteNext(); //Assert Assert.AreEqual(drone.Position, new Position(1, 4)); }
public void MissionBoundryConstructorTestMinXAssignment() { //Arrange int x = 1; //Act var boundry = new MissionBoundary(minX: x, minY: 1, maxX: 5, maxY: 6); //Assert Assert.AreEqual(boundry.MinX, x); }
public void MissionBoundryConstructorTestMaxYAssignment() { //Arrange int y = 8; //Act var boundry = new MissionBoundary(minX: 1, minY: 1, maxX: 5, maxY: y); //Assert Assert.AreEqual(boundry.MaxY, y); }
public void MissionBoundryConstructorTestAssignmentByRegion() { //Arrange var reg = new Region(id: 1, x: 2, y: 1, width: 5, height: 5); //Act var boundry = new MissionBoundary(reg); //Assert Assert.AreEqual(boundry.MinX, reg.X); Assert.AreEqual(boundry.MinY, reg.Y); Assert.AreEqual(boundry.MaxX, reg.X + reg.Width); Assert.AreEqual(boundry.MaxY, reg.X + reg.Height); }
public void DroneExecuteCommandTestMoveToNorthDoesNotChangeDirection() { //Arrange var drone = new Drone(id: 0, x: 1, y: 3, direction: 90); var boundry = new MissionBoundary(new Region(0, 0, 0, 5, 5)); drone.MissionBoundary = boundry; var command = new Command('*', 0); command.BroadcastingSignal += drone.OnBroadcastingSignal; //Act command.BroadcastCommand(); //Assert Assert.AreEqual(drone.Direction, 90); }
public void DroneExecuteCommandTestRotateToLeftDoesNotChangePosition() { //Arrange var drone = new Drone(id: 0, x: 1, y: 4, direction: 90); var boundry = new MissionBoundary(new Region(0, 0, 0, 5, 5)); drone.MissionBoundary = boundry; var command = new Command('<', 0); command.BroadcastingSignal += drone.OnBroadcastingSignal; //Act command.BroadcastCommand(); //Assert Assert.AreEqual(drone.Position, new Position(1, 4)); }
public void DroneExecuteCommandTestMoveSouthAtTheBeginingOfBoundry() { //Arrange var drone = new Drone(id: 0, x: 1, y: 5, direction: 270); var boundry = new MissionBoundary(new Region(0, 0, 0, 5, 5)); drone.MissionBoundary = boundry; var command = new Command('*', 0); command.BroadcastingSignal += drone.OnBroadcastingSignal; //Act command.BroadcastCommand(); //Assert Assert.AreEqual(drone.Position, new Position(1, 4)); }
public void DroneExecuteCommandTestDoesNotMoveEastAtTheEndOfBoundry() { //Arrange var drone = new Drone(id: 0, x: 5, y: 1, direction: 0); var boundry = new MissionBoundary(new Region(0, 0, 0, 5, 5)); drone.MissionBoundary = boundry; var command = new Command('*', 0); command.BroadcastingSignal += drone.OnBroadcastingSignal; //Act command.BroadcastCommand(); //Assert Assert.AreEqual(drone.Position, new Position(5, 1)); }
public void ExecuteTestTestEventShouldBeRaised() { //Arrange var drone = new Drone(id: 0, x: 1, y: 3, direction: 90); var boundry = new MissionBoundary(new Region(0, 0, 0, 5, 5)); drone.MissionBoundary = boundry; var commands = new List <Command>(); var command = new Command('*', 0); command.BroadcastingSignal += drone.OnBroadcastingSignal; commands.Add(command); command = new Command('>', 0); command.BroadcastingSignal += drone.OnBroadcastingSignal; commands.Add(command); var mission = new Mission(0, commands); mission.TerminatedMission += drone.OnTerminatedMission; mission.DroneId = 0; List <int> receivedEvents = new List <int>(); mission.TerminatedMission += delegate(object sender, MissionEventArgs e) { receivedEvents.Add(e.DroneId); }; //Act mission.ExecuteAllCommands(); //Assert Assert.AreEqual(1, receivedEvents.Count); Assert.AreEqual(0, receivedEvents[0]); }
private void SetMissionBoundaryForAllDrones(Region field, List <Drone> droneList) { MissionBoundary boundry = new MissionBoundary(field); droneList.ForEach(d => d.MissionBoundary = boundry); }