public void Test_Execute_Method_ON_Environment_With_Input_X3Y4OrientationNorthAndControlInputSequenceLMLMLMLMMAnd_With_Input_X2Y4OrientationEastAndControlInputSequenceMMRMMRMRRM() { //This Test Can't be Executed due to the fact that Streams are multi-read, and can't be faked easily unless //the dynamic execution, is counting number of reads which could be possible, but not reliable, and therefore too complex to test. /*Entry For Robot 1: * 10 10 * 1 2 N * MMRMMRMRRM */ var plane = new Plane(10, 10, new Location { X = 0, Y = 0 }); var controller = new RobotController(plane); var robots = new List <Robot>(); var inputOutputInstance = new StreamReadWriteInstance(); inputOutputInstance.TextReader = new FakeStreamReader(); inputOutputInstance.TextWriter = new FakeStreamWriter(); var environmentSetup = new Mock <EnvironmentSetup>(); environmentSetup.SetupProperty(mq => mq.Robots, robots); environmentSetup.SetupProperty(mq => mq.Controller, controller); environmentSetup.SetupProperty(mq => mq.Plane, plane); environmentSetup.SetupProperty(mq => mq.IInputOutputStream, inputOutputInstance); environmentSetup.Setup(mq => mq.ReadPlaneCordinates()).Returns("10 10"); environmentSetup.Setup(mq => mq.ReadControlSequence()).Returns("LMLMLMLMM"); environmentSetup.Setup(mq => mq.GetLocationArray(It.IsAny <string>())).Returns("3 4 N".Split()); environmentSetup.Setup(mq => mq.Write1stLineOfOutput()).CallBase(); environmentSetup.Setup(mq => mq.Write2ndLineOfOutput()).CallBase(); environmentSetup.Setup(mq => mq.Write3rdLineOfOutput()).CallBase(); environmentSetup.Setup(mq => mq.Write4thLineOfOutput()).CallBase(); environmentSetup.Setup(mq => mq.ReadToAddAnotherRobot()).Returns("N"); environmentSetup.Setup(mq => mq.MoveRobotSequence(It.IsAny <string>(), It.IsAny <RobotController>(), It.IsAny <Robot>())).CallBase(); environmentSetup.Setup(mq => mq.Execute()).CallBase(); environmentSetup.Object.Execute(); Assert.AreEqual(robots[0].Location.X, 3); Assert.AreEqual(robots[0].Location.Y, 5); Assert.AreEqual(robots[0].Orientation, OrientationPosition.Orientation.N); var robots2 = new List <Robot>(); environmentSetup.SetupProperty(mq => mq.Robots, robots2); environmentSetup.Setup(mq => mq.ReadPlaneCordinates()).Returns("7 6"); environmentSetup.Setup(mq => mq.ReadControlSequence()).Returns("MMRMMRMRRM"); environmentSetup.Setup(mq => mq.GetLocationArray(It.IsAny <string>())).Returns("2 4 E".Split()); environmentSetup.Object.Execute(); Assert.AreEqual(robots2[0].Location.X, 4); Assert.AreEqual(robots2[0].Location.Y, 2); Assert.AreEqual(robots2[0].Orientation, OrientationPosition.Orientation.E); }
public void SetUp() { var plane = new Plane(10, 10, new Location { X = 0, Y = 0 }); var robot1 = new Robot(plane); robot1.Location = new Location { X = 1, Y = 2 }; robot1.Orientation = OrientationPosition.Orientation.N; var robot2 = new Robot(plane); robot2.Location = new Location { X = 3, Y = 3 }; robot2.Orientation = OrientationPosition.Orientation.E; var robot3 = new Robot(plane); robot3.Location = new Location { X = 1, Y = 2 }; robot3.Orientation = OrientationPosition.Orientation.W; var robot4 = new Robot(plane); robot4.Location = new Location { X = 5, Y = 3 }; robot4.Orientation = OrientationPosition.Orientation.S; _controller = new RobotController(plane); var Robots = new List <Robot>(); Robots.Add(robot1); Robots.Add(robot2); Robots.Add(robot3); Robots.Add(robot4); _controller.Robots = Robots.ToArray(); _streamInstance = new StreamReadWriteInstance(); _streamInstance.TextReader = new FakeStreamReader(); _streamInstance.TextWriter = new FakeStreamWriter(); _environment = new EnvironmentSetup(_controller, plane, Robots, _streamInstance); }
//Assumptions: Robots are entered dynamically during run time. //Otherwise I would need to read all input from a File. //This is a decision I made as there is no mention of how the input would stream into the program, so I can //assume it is coming from the keyboard dynamically. That is at Runtime. static void Main(string[] args) { Console.Out.WriteLine("Enter the X and Y cordinates of the Plane"); var xyCord = Console.In.ReadLine(); var xyStrings = xyCord.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (xyStrings.Length != 2) { throw new ArgumentException("You need to enter 2 integers"); } var x = 0; var y = 0; Int32.TryParse(xyStrings[0], out x); Int32.TryParse(xyStrings[1], out y); if (x < 1 || y < 1) { throw new ArgumentException("Plane should have positive greater than 0 values"); } var plane = new Plane(x, y, new Location { X = 0, Y = 0 }); var controller = new RobotController(plane); var robots = new List <Robot>(); var inputOutputInstance = new StreamReadWriteInstance(); inputOutputInstance.TextReader = Console.In; inputOutputInstance.TextWriter = Console.Out; var environmentSetup = new EnvironmentSetup(controller, plane, robots, inputOutputInstance); environmentSetup.Execute(); }