Пример #1
0
        private void ArrayHasNoDuplicates(List <ValidationResult> errors, SortingInput input)
        {
            long[] arr = input.GetNumbers();

            if (arr.GroupBy(f => f).Any(g => g.Count() > 1))
            {
                errors.Add(new ValidationResult($"Sequence cannot have duplicate numbers.", new[] { "Line" }));
            }
        }
Пример #2
0
        private void ArrayIsCorrectLength(List <ValidationResult> errors, SortingInput input, int maxArrLength)
        {
            long[] arr = input.GetNumbers();

            if (arr.Length > maxArrLength)
            {
                errors.Add(new ValidationResult($"Max of {maxArrLength} numbers is allowed.", new[] { "Line" }));
            }
        }
Пример #3
0
        private void ArrayValuesBetweenMinMax(List <ValidationResult> errors, SortingInput input, int min, int max)
        {
            long[] arr = input.GetNumbers();
            Array.Sort(arr);

            if (arr.Any(f => f < min) || arr.Any(f => f > max))
            {
                errors.Add(new ValidationResult($"Numbers must be between {min} and {max}.", new[] { "Line" }));
            }
        }
Пример #4
0
        private bool OnlyNumbersAndSpaces(List <ValidationResult> errors, SortingInput input)
        {
            string pattern = @"^([1-9][0-9]*[ ])*[1-9][0-9]*[ ]*$";

            Regex regex = new Regex(pattern);

            if (!regex.IsMatch(input.Line))
            {
                errors.Add(new ValidationResult($"Only numbers separated by space are allowed. Ex: \"4 2 3 8\"."));
                return(false);
            }

            return(true);
        }