Class JsGens


  • public class JsGens
    extends java.lang.Object
    Class with different kind of generators
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static JsGen<JsStr> alphabetic​(int length)
      Generates an alphabetic string of the given length
      static JsGen<JsStr> alphanumeric​(int length)
      Generates an alphanumeric string of the given length
      static JsGen<JsArray> array​(JsGen<?> gen, int size)
      Creates an array generator of the given size, whose elements are chosen from the given generator
      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.
      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.
      static JsGen<JsBinary> binary​(int length)
      Generates an array of bytes of the given length
      static JsGen<JsInt> choose​(int min, int max)
      Creates a generator that generates integers in the range`min` to `max`, inclusive.
      static JsGen<JsValue> cons​(JsValue value)
      generates a constant
      static JsGen<JsInstant> 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.
      static JsGen<JsInstant> dateBetween​(java.time.ZonedDateTime min, java.time.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.
      static JsGen<JsStr> digits​(int length)
      Generates a seq of digits of the given length
      static JsGen<?> frequency​(io.vavr.Tuple2<java.lang.Integer,​JsGen<?>> freq, io.vavr.Tuple2<java.lang.Integer,​JsGen<?>>... others)
      Creates a generator that chooses a generator from `pairs` based on the provided likelihoods.
      static <O extends JsValue>
      JsGen<O>
      oneOf​(java.util.List<O> list)
      Creates a generator that randomly chooses a value from the given list
      static JsGen<?> oneOf​(JsGen<?> gen, JsGen<?>... others)
      Creates a generator that randomly chooses a value from the provided generators
      static JsGen<JsValue> oneOf​(JsValue a, JsValue... others)
      Creates a generator that randomly chooses a value from the given as parameters
      static JsGen<JsValue> single​(JsValue value)
      lift a constant value up into a generator
      static JsGen<JsStr> str​(int length)
      Generates an alphabetic string of the given length
      static JsGen<JsArray> tuple​(JsGen<?> gen, JsGen<?>... others)
      Creates a tuple generator from the given generators.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • character

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

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

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

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

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

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

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

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

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

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

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

        public static final JsGen<JsDouble> decimal
        Generates a decimal number
      • date

        public static final JsGen<JsInstant> date
        Generates an instant between y Instant#MAX
      • binary

        public static final JsGen<JsBinary> binary
        Generates an array of 1024 bytes
    • 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
      • binary

        public static JsGen<JsBinary> binary​(int length)
        Generates an array of bytes of the given length
        Parameters:
        length - the number of bytes generated
        Returns:
        an array of bytes 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​(java.util.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<java.lang.Integer,​JsGen<?>> freq,
                                         io.vavr.Tuple2<java.lang.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<JsInstant> dateBetween​(java.time.ZonedDateTime min,
                                                   java.time.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<JsInstant> 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
      • cons

        public static JsGen<JsValue> cons​(JsValue value)
        generates a constant
        Parameters:
        value - the constant
        Returns:
        a generator