/// <summary> /// Constrains the generator so that it only produces values between 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 IIntGen <short> Between(this IIntGen <short> gen, short x, short y) { var min = x > y ? y : x; var max = x > y ? x : y; return(gen.GreaterThanEqual(min).LessThanEqual(max)); }
/// <summary> /// Constrains the generator so that it only produces values between 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 IIntGen <long> Between(this IIntGen <long> gen, long x, long y) { var min = x > y ? y : x; var max = x > y ? x : y; return(gen.GreaterThanEqual(min).LessThanEqual(max)); }
/// <summary> /// Constrains the generator so that it only produces values between 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 IIntGen <byte> Between(this IIntGen <byte> gen, byte x, byte y) { var min = x > y ? y : x; var max = x > y ? x : y; return(gen.GreaterThanEqual(min).LessThanEqual(max)); }
/// <summary> /// Constrains the generator so that it only produces values greater than the supplied minimum. /// </summary> /// <param name="minExclusive">The minimum integer to generate (exclusive).</param> /// <returns>A new generator with the constraint applied.</returns> public static IIntGen <long> GreaterThan(this IIntGen <long> gen, long minExclusive) { try { checked { return(gen.GreaterThanEqual((long)(minExclusive + 1))); } } catch (OverflowException ex) { return(new FatalIntGen <long>($"{nameof(Gen.Int64)}().{nameof(GreaterThan)}({minExclusive})", ex)); } }
/// <summary> /// Constrains the generator so that it only produces values less than the supplied maximum. /// </summary> /// <param name="maxExclusive">The maximum int to generate (exclusive).</param> /// <returns>A new generator with the constraint applied.</returns> public static IIntGen <long> LessThan(this IIntGen <long> gen, long maxExclusive) { try { checked { return(gen.LessThanEqual((long)(maxExclusive - 1))); } } catch (OverflowException ex) { return(new FatalIntGen <long>($"{nameof(Gen.Int64)}().{nameof(LessThan)}({maxExclusive})", ex)); } }
/// <summary> /// Constrains the generator so that it only produces values greater than the supplied minimum. /// </summary> /// <param name="minExclusive">The minimum integer to generate (exclusive).</param> /// <returns>A new generator with the constraint applied.</returns> public static IIntGen <short> GreaterThan(this IIntGen <short> gen, short minExclusive) { try { checked { return(gen.GreaterThanEqual((short)(minExclusive + 1))); } } catch (OverflowException ex) { return(new FatalIntGen <short>($"{nameof(Gen.Int16)}().{nameof(GreaterThan)}({minExclusive})", ex)); } }
/// <summary> /// Constrains the generator so that it only produces values greater than the supplied minimum. /// </summary> /// <param name="minExclusive">The minimum byte to generate (exclusive).</param> /// <returns>A new generator with the constraint applied.</returns> public static IIntGen <byte> GreaterThan(this IIntGen <byte> gen, byte minExclusive) { try { checked { return(gen.GreaterThanEqual((byte)(minExclusive + 1))); } } catch (OverflowException ex) { return(new FatalIntGen <byte>($"{nameof(Gen.Byte)}().{nameof(GreaterThan)}({minExclusive})", ex)); } }
/// <summary> /// Constrains the generator so that it only produces values less than the supplied maximum. /// </summary> /// <param name="maxExclusive">The maximum byte to generate (exclusive).</param> /// <returns>A new generator with the constraint applied.</returns> public static IIntGen <byte> LessThan(this IIntGen <byte> gen, byte maxExclusive) { try { checked { return(gen.LessThanEqual((byte)(maxExclusive - 1))); } } catch (OverflowException ex) { return(new FatalIntGen <byte>($"{nameof(Gen.Byte)}().{nameof(LessThan)}({maxExclusive})", ex)); } }
/// <summary> /// Constrains the generator so that it only produces values less than the supplied maximum. /// </summary> /// <param name="maxExclusive">The maximum int to generate (exclusive).</param> /// <returns>A new generator with the constraint applied.</returns> public static IIntGen <int> LessThan(this IIntGen <int> gen, int maxExclusive) { try { checked { return(gen.LessThanEqual(maxExclusive - 1)); } } catch (OverflowException ex) { return(new FatalIntGen <int>($"{nameof(Gen.Int32)}().{nameof(LessThan)}({maxExclusive})", ex)); } }