public void TLocationConstructor() { MarsRover.Point point = new Point(2, 3); MarsRover.Direction direction = Direction.E; MarsRover.Location target = new MarsRover.Location(point, direction); Assert.AreEqual(target.ToString(), "2 3 E"); }
public void Rover_Which_Is_North_When_Asked_To_MoveForward_Should_Move_One_Unit_Vertically() { Orientation northOrientation = OrientationGenerator.GetOrientation (Direction.North); Location location = new Location (new Position (2, 3), northOrientation); Location expectedLocation = new Location (new Position (2, 4), northOrientation); Rover rover = new Rover (location); Location actualLocation = rover.MoveForward (); Assert.AreEqual (expectedLocation,actualLocation); }
public void Rover_Which_Is_East_When_Asked_To_MoveForward_Should_Move_One_Unit_Horizontally() { Orientation eastOrientation = OrientationGenerator.GetOrientation (Direction.East); Location location = new Location (new Position (2, 3), eastOrientation); Location expectedLocation = new Location (new Position (3, 3), eastOrientation); Rover rover = new Rover (location); Location actualLocation = rover.MoveForward (); Assert.AreEqual (expectedLocation,actualLocation); }
/// <summary> /// Move the rover as the directions. /// </summary> /// <param name="movements">Combination of L, M, and R that form the command for the rover to move.</param> public override void Move(string movements) { movements = movements.ToUpper().Trim(); Regex regex = new Regex(REGEX_MOVEMENT); Match match = regex.Match(movements); if (!match.Success) throw new ArgumentException(String.Format("Rover {0}: Movement can only be L, R or M", Name)); // Process all movements. char[] movement = movements.ToCharArray(); int currentX = CurrentLocation.Point.X; int currentY = CurrentLocation.Point.Y; Direction newDirection = CurrentLocation.Direction; for (int i = 0; i < movement.Length; i++) { switch (movement[i]) { case 'M': switch (newDirection) { case Direction.N: currentY++; break; case Direction.S: currentY--; break; case Direction.E: currentX++; break; case Direction.W: currentX--; break; } if (!Plateau.Contains(currentX, currentY)) throw new Exception(String.Format("Rover {0} : Incorrect movement as it exceeds bounds of plateau.", Name)); else CurrentLocation = new Location(new Point(currentX, currentY), newDirection); //Console.WriteLine(String.Format("\t{0} {1} {2}", CurrentLocation.Point.X, CurrentLocation.Point.Y, CurrentLocation.Direction)); break; default: newDirection = this.GetNewDirection(newDirection, movement[i]); //Console.WriteLine(String.Format("\t{0} {1} {2}", CurrentLocation.Point.X, CurrentLocation.Point.Y, CurrentLocation.Direction)); break; } } }
public void Rover_When_Facing_North_Should_Turn_To_West_When_Asked_To_TurnLeft() { Orientation northOrientation = OrientationGenerator.GetOrientation (Direction.North); Orientation westOrientation = OrientationGenerator.GetOrientation (Direction.West); Location location = new Location (new Position (2, 3), northOrientation); Location expectedLocation = new Location (new Position (2, 3), westOrientation); Rover rover = new Rover (location); Location actualLocation = rover.TurnLeft (); Assert.AreEqual (expectedLocation,actualLocation); }
public void TLocationConstructor3() { try { MarsRover.Point point = new Point(-1, -1); MarsRover.Location target = new MarsRover.Location(point); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void TLocationConstructor1() { try { MarsRover.Point point = null; MarsRover.Direction direction = Direction.E; MarsRover.Location target = new MarsRover.Location(point, direction); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public override void UpdateFromString(string updateString) { if (IsValidUpdateString(updateString)) { var updateArray = GetUpdateStringArrayWithoutIdentifier(updateString); this.X = float.Parse(updateArray[0], NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint); this.Y = float.Parse(updateArray[1], NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint); this.Z = float.Parse(updateArray[2], NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint); if (this.Location == null) { Location = new Location(); } this.Location.Latitude = nmeaToLatitude(this.Z); this.Location.Longitude = nmeaToLongitude(this.X, this.Y); } else { throw new InvalidUpdateStringException(updateString); } }
public Rover(Location location) { _location = location; }
public void TGetLocation() { string directionInput = "1 2 E"; MarsRover.Location expected = new Location(new Point(1, 2), Direction.E); MarsRover.Location actual; actual = MarsRover.Location.GetLocation(directionInput); Assert.AreEqual(expected.ToString(), actual.ToString()); }
public void TLocationConstructor2() { MarsRover.Point point = new Point(2,2); MarsRover.Location target = new MarsRover.Location(point); Assert.AreEqual(target.ToString(), "2 2 N"); }
public void TGetLocation2() { try { string directionInput = string.Empty; MarsRover.Location expected = new Location(new Point(1, 2), Direction.E); MarsRover.Location actual; actual = MarsRover.Location.GetLocation(directionInput); Assert.AreEqual(expected.ToString(), actual.ToString()); } catch (Exception ex) { Assert.Fail(ex.Message); } }
/// <summary> /// Get distance in kilometers between two locations /// </summary> /// <param name="latitude1"></param> /// <param name="longitude1"></param> /// <param name="latitude2"></param> /// <param name="longitude2"></param> /// <returns></returns> private double getDistance(Location location1, Location location2) { double latitude1 = location1.Latitude; double longitude1 = location1.Longitude; double latitude2 = location2.Latitude; double longitude2 = location2.Longitude; double radiusOfEarth = 6371; double lateralDistanceRadians = degreesToRadians(latitude2 - latitude1); double longitudinalDistanceRadians = degreesToRadians(longitude2 - longitude1); double a = Math.Sin(lateralDistanceRadians / 2) * Math.Sin(lateralDistanceRadians / 2) + Math.Cos(degreesToRadians(latitude1)) * Math.Cos(degreesToRadians(latitude2)) * Math.Sin(longitudinalDistanceRadians / 2) * Math.Sin(longitudinalDistanceRadians / 2); double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); double distance = radiusOfEarth * c; distance = Math.Round(distance, 4); return distance; }
/// <summary> /// Add the target pin to target list /// </summary> private void ExecuteAddTargetCommand() { Location targetLocation = new Location(); //add the target to the map addTarget(targetLocation); }
/// <summary> /// Add a target to the map (triggered by Add button) /// </summary> /// <param name="targetLocation"></param> private void addTarget(Location targetLocation) { //latitude ranges from -90 to 90 targetLocation.Latitude = latitude % 90; //longitude ranges from -180 to 180 targetLocation.Longitude = longitude % 180; //Initialize target list if (targetPins == null) { targetPins = new List<Pushpin>(); } // The pushpin to add to the map. Pushpin targetPin = new Pushpin(); targetPin.Location = targetLocation; //Style the target formatTargetPin(targetPin); targetPin.MouseRightButtonUp += targetPin_MouseRightButtonUp; //Initialize target list if (targetPins == null) { targetPins = new List<Pushpin>(); } targetPins.Add(targetPin); //Initialize the pushpin list if (pushPinCollection == null) { pushPinCollection = new ObservableCollection<Pushpin>(); } pushPinCollection.Add(targetPin); updateTargetDetails(); //reset values of the textboxes longitudeString = ""; latitudeString = ""; targetTitleString = ""; //reset the data values longitude = 0; latitude = 0; }