Class JsGens


  • public class JsGens
    extends Object
    Class with different kind of generators
    • Field Detail

      • character

        public static JsGen<JsStr> character
        Generates character from 0-255
      • characterAlpha

        public static JsGen<JsStr> characterAlpha
        Generates character from 65-122
      • digit

        public static JsGen<JsStr> digit
        Generates a digit from 0-9
      • letter

        public static JsGen<JsStr> letter
        Generates a letter from a-z
      • natural

        public static JsGen<JsInt> natural
        Generates a positive integer (zero included)
      • str

        public static JsGen<JsStr> str
        Generates a string where the length is between [0-10]
      • alphabetic

        public static JsGen<JsStr> alphabetic
        Generates a alphabetic string where the length is between [0-10]
      • alphanumeric

        public static JsGen<JsStr> alphanumeric
        Generates a alphanumeric string where the length is between [0-10]
      • bool

        public static JsGen<JsBool> bool
        Generates a boolean
      • longInteger

        public static JsGen<JsLong> longInteger
        Generates a long number
      • integer

        public static JsGen<JsInt> integer
        Generates an integer number
      • decimal

        public static JsGen<JsDouble> decimal
        Generates a decimal number
    • Constructor Detail

      • JsGens

        public JsGens()
    • Method Detail

      • digits

        public static JsGen<JsStr> digits​(int length)
        Generates a seq of digits of the given length
        Parameters:
        length - the length of the string
        Returns:
        a string generator
      • str

        public static JsGen<JsStr> str​(int length)
        Generates an alphabetic string of the given length
        Parameters:
        length - the length of the generated string
        Returns:
        a generator
      • alphabetic

        public static JsGen<JsStr> alphabetic​(int length)
        Generates an alphabetic string of the given length
        Parameters:
        length - the length of the string
        Returns:
        a string generator
      • alphanumeric

        public static JsGen<JsStr> alphanumeric​(int length)
        Generates an alphanumeric string of the given length
        Parameters:
        length - the length of the string
        Returns:
        a string generator
      • single

        public static JsGen<JsValue> single​(JsValue value)
        lift a constant value up into a generator
        Parameters:
        value - the value
        Returns:
        a generator that always produce the same value
      • oneOf

        public static JsGen<JsValue> oneOf​(JsValue a,
                                           JsValue... others)
        Creates a generator that randomly chooses a value from the given as parameters
        Parameters:
        a - a value
        others - the others values
        Returns:
        a generator
      • oneOf

        public static JsGen<?> oneOf​(JsGen<?> gen,
                                     JsGen<?>... others)
        Creates a generator that randomly chooses a value from the provided generators
        Parameters:
        gen - a generator
        others - the others generators
        Returns:
        a generator
      • oneOf

        public static <O extends JsValueJsGen<O> oneOf​(List<O> list)
        Creates a generator that randomly chooses a value from the given list
        Type Parameters:
        O - the type of the generated value
        Parameters:
        list - the list of values
        Returns:
        a generator
      • tuple

        public static JsGen<JsArray> tuple​(JsGen<?> gen,
                                           JsGen<?>... others)
        Creates a tuple generator from the given generators. The nth-generator generates the nth-element of the tuple
        Parameters:
        gen - the head generator
        others - the rest of generators
        Returns:
        an array generator
      • array

        public static JsGen<JsArray> array​(JsGen<?> gen,
                                           int size)
        Creates an array generator of the given size, whose elements are chosen from the given generator
        Parameters:
        gen - the generator that elements are chosen from
        size - the size of the generated array
        Returns:
        an array generator
      • arrayDistinct

        public static JsGen<JsArray> arrayDistinct​(JsGen<?> gen,
                                                   int size)
        Generates an array of values from the given generator, with the guarantee that the elements will be distinct. If the generator cannot or is unlikely to produce enough distinct elements after 100 tries, this generator will fail with a RuntimeException
        Parameters:
        gen - the given generator
        size - the size of the array
        Returns:
        a json generator
      • arrayDistinct

        public static JsGen<JsArray> arrayDistinct​(JsGen<?> gen,
                                                   int size,
                                                   int maxTries)
        Generates an array of values from the given generator, with the guarantee that the elements will be distinct. If the generator cannot or is unlikely to produce enough distinct elements after the given number of tries, this generator will fail with a RuntimeException
        Parameters:
        gen - the given generator
        size - the size of the array
        maxTries - the max number of tries to produce distinct values
        Returns:
        a json generator
      • frequency

        @SafeVarargs
        public static JsGen<?> frequency​(io.vavr.Tuple2<Integer,​JsGen<?>> freq,
                                         io.vavr.Tuple2<Integer,​JsGen<?>>... others)
        Creates a generator that chooses a generator from `pairs` based on the provided likelihoods. The likelihood of a given generator being chosen is its likelihood divided by the sum of all likelihoods. Shrinks toward choosing an earlier generator, as well as shrinking the value generated by the chosen generator.
        Parameters:
        freq - a frequency pair
        others - the rests of pairs
        Returns:
        a json generator
      • choose

        public static JsGen<JsInt> choose​(int min,
                                          int max)
        Creates a generator that generates integers in the range`min` to `max`, inclusive.
        Parameters:
        min - the minimum value
        max - the maximum value
        Returns:
        an integer generator
      • dateBetween

        public static JsGen<JsStr> dateBetween​(ZonedDateTime min,
                                               ZonedDateTime max)
        generates an instant in UTC formatted with the ISO instant formatter (such as '2011-12-03T10:15:30Z'), between an interval given by two date-time with a time-zone.
        Parameters:
        min - the origin of the interval (inclusive)
        max - the bound of the interval (inclusive)
        Returns:
        an instant generator
      • dateBetween

        public static JsGen<JsStr> dateBetween​(long min,
                                               long max)
        generates an instant in UTC formatted with the ISO instant formatter (such as '2011-12-03T10:15:30Z'), between an interval given by two instants converted to the number of seconds from the epoch of 1970-01-01T00:00:00Z.
        Parameters:
        min - the origin of the interval (inclusive)
        max - the bound of the interval (inclusive)
        Returns:
        an instant generator