예제 #1
0
        public static InputData ParseArgs(string[] args)
        {
            if (!BaseValidator.IsNotEmptyArgs(args))
            {
                throw new NullReferenceException("Array of parameters is null"); //81
            }
            if (!BaseValidator.IsCorrectLength(args
                                               , InputData.MinCountParams, InputData.MaxCountParams))
            {
                throw new ArgumentException(
                          "The number of parameters is incorrect. " +
                          "There must be: " + InputData.MinCountParams + " " +
                          "or " + InputData.MaxCountParams);
            }

            if (BaseValidator.IsCorrectLength(args, InputData.MaxCountParams))
            {
                return(new InputData
                {
                    ProgramMode = InputData.Mode.Fibonacci,
                    StartFibonacciRange = Int32.Parse(args[0]),
                    EndFibonacciRange = Int32.Parse(args[1]),
                });
            }
            else
            {
                return(new InputData
                {
                    ProgramMode = InputData.Mode.Square,
                    SquaryValue = Int32.Parse(args[0]),
                });
            }
        }
예제 #2
0
        public static InputData Parse(string[] args)
        {
            if (!BaseValidator.IsNotEmptyArgs(args))
            {
                throw new NullReferenceException("Array of parameters is null"); //81
            }
            if (!BaseValidator.IsCorrectLength(args
                                               , InputData.MinCountParams, InputData.MaxCountParams))
            {
                throw new ArgumentException(
                          "The number of parameters is incorrect. " +
                          "There must be: " + InputData.MinCountParams + " " +
                          "or " + InputData.MaxCountParams);
            }
            if (BaseValidator.DoesFileExist(args[0]))
            {
                throw new FileNotFoundException();
            }

            return(new InputData
            {
                PathToFile = args[0],
                TargetStr = args[1],
                ReplaceStr = args.Length > InputData.MinCountParams ?
                             args[2] : null,
                Mode = args.Length == InputData.MaxCountParams ?
                       InputData.ProgramMode.ReplaceStr :
                       InputData.ProgramMode.SearchStr
            });
        }
 private bool IsValid(string[] args)
 {
     return(BaseValidator.IsEmptyArr(args) &&
            BaseValidator.IsCorrectLength(args
                                          , InputDTO.CountParams) &&
            BaseValidator.DoesNotContainNull(args) &&
            BaseValidator.CanParseToInt64(args[0], false) &&
            BaseValidator.DoesContainEnum(args[1]
                                          , typeof(InputDTO.Algorithms)));
 }
예제 #4
0
        public void IsCorrectLength_Length3Expected2_False()
        {
            //arrange
            string[] arr      = { "Test", "Test1", "Test2" };
            int      expected = 2;

            //act
            bool result = BaseValidator.IsCorrectLength(arr, expected);

            //assert
            Assert.False(result);
        }
예제 #5
0
        public void IsCorrectLength_NullLenght1_False()
        {
            //arrange
            string[] arr      = null;
            int      expected = 1;

            //act
            bool result = BaseValidator.IsCorrectLength(arr, expected);

            //assert
            Assert.False(result);
        }
예제 #6
0
        public void IsCorrectLength_NullRange4to2_False()
        {
            //arrange
            string[] arr   = null;
            int      start = 2;
            int      end   = 4;

            //act
            bool result = BaseValidator.IsCorrectLength(arr, start, end);

            //assert
            Assert.False(result);
        }
예제 #7
0
        public void IsCorrectLength_Length3Range4to2_False()
        {
            //arrange
            string[] arr   = { "Test", "Test1", "Test2" };
            int      start = 4;
            int      end   = 2;

            //act
            bool result = BaseValidator.IsCorrectLength(arr, start, end);

            //assert
            Assert.False(result);
        }
예제 #8
0
        public static InputData Parse(string[] args)
        {
            if (!BaseValidator.IsNotEmptyArgs(args))
            {
                throw new NullReferenceException("Array of parameters is null"); //81
            }
            if (!BaseValidator.IsCorrectLength(args, InputData.CountParams))
            {
                throw new ArgumentException(
                          "The number of parameters is incorrect. " +
                          "There must be: " + InputData.CountParams);
            }

            return(new InputData
            {
                NumberOfRows = Int32.Parse(args[0]),
                NumberOfColumns = Int32.Parse(args[1]),
            });
        }
예제 #9
0
        public static InputData Parse(string[] args)
        {
            if (!BaseValidator.IsNotEmptyArgs(args))
            {
                throw new NullReferenceException("Array of parameters is null"); //81
            }
            if (!BaseValidator.IsCorrectLength(args, InputData.CountParams))
            {
                throw new ArgumentException(
                          "The number of parameters is incorrect. " +
                          "There must be: " + InputData.CountParams);
            }

            return(new InputData {
                LengthFirst = Double.Parse(args[0]),
                HeightFirst = Double.Parse(args[1]),
                LengthSecond = Double.Parse(args[2]),
                HeightSecond = Double.Parse(args[3])
            });
        }
예제 #10
0
        public static InputDTO Parse(string[] args)
        {
            if (!BaseValidator.IsNotEmptyArgs(args))
            {
                throw new NullReferenceException("Array of parameters is null");
            }
            if (!BaseValidator.IsCorrectLength(args, InputDTO.CountParams))
            {
                throw new ArgumentException(
                          "The number of parameters is incorrect. "
                          + "There must be: " + InputDTO.CountParams);
            }

            return(new InputDTO()
            {
                Number = Int64.Parse(args[0]),
                Algorithm = (InputDTO.Algorithms)
                            Enum.Parse(typeof(InputDTO.Algorithms), args[1])
            });
        }