예제 #1
0
        public void Report_NewRobotAt1X1YNorth_Returns1X1YNorth()
        {
            var board = new Toy.Robot.Board.Board();

            _coordinator = new Toy.Robot.Coordinator(board);

            _coordinator.InitializeBoard(5, 5);

            var robotId = Guid.NewGuid();

            _coordinator.Place(robotId, 1, 1, Direction.North);

            try
            {
                var report = _coordinator.Report();

                Assert.AreEqual(1, report.Count);

                var firstRobot = report.First();

                Assert.AreEqual(robotId, firstRobot.robotId);
                Assert.AreEqual(1, firstRobot.x);
                Assert.AreEqual(1, firstRobot.y);
                Assert.AreEqual(Direction.North, firstRobot.direction);
            }
            catch (Exception)
            {
                Assert.Fail("Exception Thrown");
            }
        }
예제 #2
0
        public void Report_RobotExistsInListNotOnBoard_ExceptionThrown()
        {
            var board = new Toy.Robot.Board.Board();

            _coordinator = new Toy.Robot.Coordinator(board);

            _coordinator.InitializeBoard(5, 5);

            _coordinator.Robots.Add(new Toy.Robot.Robot.Robot(Direction.North));

            var ex = Assert.Throws <Exception>(() =>
            {
                _coordinator.Report();
            });

            Assert.AreEqual("Cannot find robot on the board, place same robot on the board again", ex.Message);
        }
예제 #3
0
        public void Move_RobotDoesNotExistOnBoard_ExceptionThrown()
        {
            var board = new Toy.Robot.Board.Board();

            board.InitializePlayArea(5, 5);

            var robotId = Guid.NewGuid();

            _coordinator = new Toy.Robot.Coordinator(board);
            _coordinator.Robots.Add(new Toy.Robot.Robot.Robot(Direction.North, robotId));

            var ex = Assert.Throws <Exception>(() =>
            {
                _coordinator.Move(robotId);
            });

            Assert.AreEqual("Cannot find robot on the board, place same robot on the board again", ex.Message);
        }
예제 #4
0
        public void Report_MultipleRobots_NoExceptionsResultsValid()
        {
            var board = new Toy.Robot.Board.Board();

            _coordinator = new Toy.Robot.Coordinator(board);

            _coordinator.InitializeBoard(5, 5);
            _coordinator.NumberOfRobotsAllowed = 4;

            var expectedResults = new List <(Guid robotId, int x, int y, Direction direction)>
            {
                (Guid.NewGuid(), 0, 0, Direction.North),
                (Guid.NewGuid(), 0, 4, Direction.East),
                (Guid.NewGuid(), 4, 0, Direction.West),
                (Guid.NewGuid(), 4, 4, Direction.South)
            };

            _coordinator.Place(expectedResults[0].robotId, expectedResults[0].x, expectedResults[0].y, expectedResults[0].direction);
            _coordinator.Place(expectedResults[1].robotId, expectedResults[1].x, expectedResults[1].y, expectedResults[1].direction);
            _coordinator.Place(expectedResults[2].robotId, expectedResults[2].x, expectedResults[2].y, expectedResults[2].direction);
            _coordinator.Place(expectedResults[3].robotId, expectedResults[3].x, expectedResults[3].y, expectedResults[3].direction);

            try
            {
                var reportList = _coordinator.Report();

                Assert.AreEqual(4, reportList.Count);

                foreach (var expectedResult in expectedResults)
                {
                    var report = reportList.FirstOrDefault(r => r.robotId == expectedResult.robotId);
                    if (report == default)
                    {
                        Assert.Fail($"Robot {expectedResult.robotId} not included in report");
                    }

                    Assert.AreEqual(expectedResult, report);
                }
            }
            catch (Exception)
            {
                Assert.Fail("Exception Thrown");
            }
        }