/// <summary> /// Constrains the generator so that it only produces strings with lengths within the supplied range /// (inclusive). /// </summary> /// <param name="x">The first bound of the range.</param> /// <param name="y">The second bound of the range.</param> /// <returns>A new generator with the constraint applied.</returns> public static IStringGen WithLengthBetween(this IStringGen gen, int x, int y) { var minLength = x > y ? y : x; var maxLength = x > y ? x : y; return(gen.WithLengthGreaterThanEqual(minLength).WithLengthLessThanEqual(maxLength)); }
void ShouldError(IStringGen gen) { Action action = () => gen.SampleOne(seed: seed, size: size); action.Should() .Throw <GalaxyCheck.Exceptions.GenErrorException>() .WithMessage("Error while running generator StringGen: 'minLength' cannot be greater than 'maxLength'"); }
/// <summary> /// Constrains the generator so that it only produces strings less than the given Length. /// </summary> /// <param name="exclusiveMaxLength">The maximum length that generated strings should be constrained to.</param> /// <returns>A new generator with the constraint applied.</returns> public static IStringGen WithLengthLessThan(this IStringGen gen, int exclusiveMaxLength) => gen.WithLengthLessThanEqual(exclusiveMaxLength - 1);
/// <summary> /// Constrains the generator so that it only produces strings with greater than the given Length. /// </summary> /// <param name="exclusiveMinLength">The minimum length that generated strings should be constrained to.</param> /// <returns>A new generator with the constraint applied.</returns> public static IStringGen WithLengthGreaterThan(this IStringGen gen, int exclusiveMinLength) => gen.WithLengthGreaterThanEqual(exclusiveMinLength + 1);