public void OperationNullOrEmptyExpectArgumentNullException(string operation) { Assert.Throws <ArgumentNullException>(() => { OperationArgumentsCheckHelper.CheckOperationArguments(new Dictionary <int, bool>(), ExpectedMinRange, ExpectedMaxRange, operation); }); }
public void MaxRangeLessThanMinRangeExpectArgumentException() { Assert.Throws <ArgumentException>(() => { OperationArgumentsCheckHelper.CheckOperationArguments(new Dictionary <int, bool>(), ExpectedMaxRange, ExpectedMinRange, ExpectedOperation); }); }
public void AllowedValuesNullExpectArgumentNullException() { Assert.Throws <ArgumentNullException>(() => { OperationArgumentsCheckHelper.CheckOperationArguments(null, ExpectedMinRange, ExpectedMaxRange, ExpectedOperation); }); }
public void Apply(Dictionary <int, bool> allowedValues, int minRange, int maxRange, string operation) { OperationArgumentsCheckHelper.CheckOperationArguments(allowedValues, minRange, maxRange, operation); if (operation != "*") { throw new ParserException("Everything operation is invalid"); } for (int i = minRange; i <= maxRange; i++) { allowedValues[i] = true; } }
public void Apply(Dictionary <int, bool> allowedValues, int minRange, int maxRange, string operation) { OperationArgumentsCheckHelper.CheckOperationArguments(allowedValues, minRange, maxRange, operation); if (!int.TryParse(operation, out var allowValue)) { throw new FormatException("Unable to parse number"); } if (allowValue < minRange || allowValue > maxRange) { throw new IndexOutOfRangeException("Value is out of expected range for single operation"); } allowedValues[allowValue] = true; }
public void Apply(Dictionary <int, bool> allowedValues, int minRange, int maxRange, string operation) { OperationArgumentsCheckHelper.CheckOperationArguments(allowedValues, minRange, maxRange, operation); var ranges = operation.Split('/'); if (ranges.Length != 2) { throw new FormatException("Invalid step"); } int start; if (ranges[0] == "*") { start = minRange; } else if (!int.TryParse(ranges[0], out start)) { throw new FormatException("Unable to parse start"); } if (!int.TryParse(ranges[1], out var step)) { throw new FormatException("Unable to parse step"); } if (start < minRange) { throw new IndexOutOfRangeException("start should be greater than overall minRange"); } if (start > maxRange) { throw new IndexOutOfRangeException("start should be less than maxRange"); } for (int i = start; i <= maxRange; i += step) { allowedValues[i] = true; } }
public void Apply(Dictionary <int, bool> allowedValues, int minRange, int maxRange, string operation) { OperationArgumentsCheckHelper.CheckOperationArguments(allowedValues, minRange, maxRange, operation); var ranges = operation.Split('-'); if (ranges.Length != 2) { throw new FormatException("Invalid range"); } if (!int.TryParse(ranges[0], out var minRangeToApply)) { throw new FormatException("Unable to parse minRange"); } if (!int.TryParse(ranges[1], out var maxRangeToApply)) { throw new FormatException("Unable to parse minRange"); } if (minRangeToApply > maxRangeToApply) { throw new IndexOutOfRangeException("minRange should be less than maxRange"); } if (minRangeToApply < minRange) { throw new IndexOutOfRangeException("minRange to apply should be greater than overall minRange"); } if (maxRangeToApply > maxRange) { throw new IndexOutOfRangeException("maxRange to apply should be less than maxRange"); } for (int i = minRangeToApply; i <= maxRangeToApply; i++) { allowedValues[i] = true; } }