Ejemplo n.º 1
0
        public void RoverModelTest_CalculateNewPositions()
        {
            var rover = new RoverModel(Container);

            rover.StartRover(5, 5, "1 1 N", "MMRM");
            Assert.AreEqual("2 3 E", rover.CalculateNewPosition());

            rover.StartRover(5, 5, "3 5 S", "M");
            Assert.AreEqual("3 4 S", rover.CalculateNewPosition());

            // keep the same direction as previous when error occurs
            // 35S is a wrong position
            rover.StartRover(5, 5, "35S", "M");
            Assert.AreEqual("3 4 S", rover.CalculateNewPosition());

            rover.Dispose();

            rover.StartRover(54444444, 123456445, "54443444 123456425 S", "MML");
            Assert.AreEqual("54443444 123456423 E", rover.CalculateNewPosition());

            rover.Dispose();

            rover.StartRover(5, 5, "35S", "M");
            Assert.AreEqual("", rover.CalculateNewPosition());

            rover.Dispose();
        }
Ejemplo n.º 2
0
        public void RoverModelTest_CalculateNewPositions_Errors()
        {
            var rover = new RoverModel(Container);

            rover.StartRover(5, 5, "", "");
            Assert.AreEqual("", rover.CalculateNewPosition());

            rover.StartRover(5, 5, " - -", "-('");
            Assert.AreEqual("", rover.CalculateNewPosition());

            rover.StartRover(5, 5, "1 1", "MMRM");
            Assert.AreEqual("", rover.CalculateNewPosition());

            rover.StartRover(5, 5, "1 1 W", "MMRM");
            Assert.AreEqual("", rover.CalculateNewPosition());

            rover.StartRover(5, 5, "1   ", "M");
            Assert.AreEqual("", rover.CalculateNewPosition());

            rover.StartRover(0, 0, "1 1 S", "M");
            Assert.AreEqual("", rover.CalculateNewPosition());

            rover.StartRover(0, 0, "1 1 S", "M---");
            Assert.AreEqual("", rover.CalculateNewPosition());

            rover.StartRover(0, 0, "1 1111111( S", "M---");
            Assert.AreEqual("", rover.CalculateNewPosition());

            rover.StartRover('r', 'r', "1 1 W", "MMRM");
            Assert.AreEqual("", rover.CalculateNewPosition());

            rover.Dispose();
        }
Ejemplo n.º 3
0
        public void RoverModelTest_StartRover()
        {
            var rover = new RoverModel(Container);

            // true
            Assert.IsTrue(rover.StartRover(5, 5, "1 1 N", "MMRM"));
            Assert.IsTrue(rover.StartRover(5, 5, "1 1 N", "aze"));

            // false
            Assert.IsFalse(rover.StartRover(5, 5, "2 3N", "MMRM"));
            Assert.IsFalse(rover.StartRover(5, 5, "11N", "aze"));
            Assert.IsFalse(rover.StartRover(5, 5, "1 1 N", ""));
            Assert.IsFalse(rover.StartRover(5, 5, "", ""));
            Assert.IsFalse(rover.StartRover(5, 5, "1 1", ""));
            Assert.IsFalse(rover.StartRover(5, 5, "1", ""));

            rover.Dispose();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parse and register the data
        /// </summary>
        /// <param name="paramsToParse">Parameters to handle</param>
        /// <returns>True if everything is set, false otherwise</returns>
        public bool ParseData(string[] paramsToParse)
        {
            if (paramsToParse == null || paramsToParse.Length != 1)
            {
                return(false);
            }

            var fileUtilities = _container.Resolve <IFileUtilities>();

            if (fileUtilities == null)
            {
                return(false);
            }

            var data = fileUtilities.ParseFile(_container, paramsToParse[0]);

            if (data.Count == 0)
            {
                return(false);
            }

            var dimensionMap = data[0].Split(' ');

            if (dimensionMap.Length != 2)
            {
                return(false);
            }

            if (int.TryParse(dimensionMap[0], out int x))
            {
                _length_x = x;
            }

            if (int.TryParse(dimensionMap[1], out int y))
            {
                _length_y = y;
            }

            // if no lenght no need to go further
            if (_length_x < 0 || _length_y < 0)
            {
                ReleaseAttributes();
                return(false);
            }

            // build rovers
            _rovers = new List <RoverModel>();
            for (var i = 1; i < data.Count && i + 1 < data.Count; i += 1)
            {
                var newCar = new RoverModel(_container);
                if (newCar.StartRover(_length_x, _length_y, data[i], data[i + 1]))
                {
                    _rovers.Add(newCar);
                }
            }

            if (_rovers.Count == 0)
            {
                ReleaseAttributes();
                return(false);
            }

            return(true);
        }