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" })); } }
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" })); } }
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" })); } }