quick_chex v0.4.0 QuickChex.Generators
a module to generate data to be used in properties
Summary
Functions
generates a binary of random size, between 0 and 100
generates a binary of the given size
generates a binary of size between min_size
and max_size
generate a binary sequence with a pattern
a boolean value
returns an alphabet letter in binary format
generates a list of random size (0..1_000) and fill it with the supplied generator
generates a list of size size
and fill it with the supplied generator
same as list/2, but generate it with a size between min_size
and max_size
returns a lowercase letter
generates a non negative integer number between 0 and 1_000_000
generates a non negative integer bound to a min and a max value
generates a non negative rational bound to a min and a max value using :rand.uniform for the decimal representation
generates a non negative rational of a given precision bound to a min and a max value, using :rand.uniform for the decimal representation
returns a number from 0 to 9
returns one of the given values
generates a random list of randomly generated values. The size is between 0 and 10
generates a random list of randomly generated values with the provided size
generates a random list of randomly generated values with a size between the min and max sizes provided
returns an uppercase letter
Types
generator :: {atom, list} | atom
Functions
Specs
binary :: binary
generates a binary of random size, between 0 and 100
How to use
check :the_property,
with: [binary]
Specs
binary(integer) :: binary
generates a binary of the given size
How to use
check :the_property,
with: [binary(10)]
Specs
binary(integer, integer) :: binary
generates a binary of size between min_size
and max_size
How to use
check :the_property,
with: [binary(1,1_000)]
Specs
binary_sequence([generator]) :: binary
generate a binary sequence with a pattern
with this function you can generate a sequence of characters by invoking other generators
How to use
check :the_property,
with: [binary_sequence([number: 1, lowercase_letter: 2, number: 2])]
Examples
iex> v = QuickChex.Generators.binary_sequence([letter: 2, number: 3])
...> Regex.match?(~r/[A-Za-z]{2}\d{3}/, v)
true
iex> v = QuickChex.Generators.binary_sequence([lowercase_letter: 10,
...> number: 3])
...> Regex.match?(~r/[a-z]{10}\d{3}/, v)
true
iex> v = QuickChex.Generators.binary_sequence([lowercase_letter: 3,
...> uppercase_letter: 3])
...> Regex.match?(~r/[a-z]{3}[A-Z]{3}/, v)
true
Specs
letter :: binary
returns an alphabet letter in binary format
only letters from A to Z uppercase and lowercase
How to use
check :the_property,
with: [letter]
Examples
iex> Regex.match?(~r/[a-zA-Z]{1}/, QuickChex.Generators.letter)
true
Specs
list_of(generator) :: list
generates a list of random size (0..1_000) and fill it with the supplied generator
How to use
check :the_property,
with: [list_of(:binary)]
check :another_property,
with: [list_of({:non_neg_integer, [1, 4]})]
Specs
list_of(generator, integer) :: list
generates a list of size size
and fill it with the supplied generator
How to use
check :the_property,
with: [list_of(:binary, 10)]
Examples
iex> import QuickChex.Generators
...> list = list_of(:non_neg_integer, 10)
...> length(list) === 10
true
iex> import QuickChex.Generators
...> list = list_of({:non_neg_integer, [1, 2]}, 10)
...> Enum.all?(list, &is_number/1)
true
Specs
list_of(generator, integer, integer) :: list
same as list/2, but generate it with a size between min_size
and max_size
How to use
check :the_property,
with: [list_of(:binary, 10, 20)]
Specs
lowercase_letter :: binary
returns a lowercase letter
How to use
check :the_property,
with: [lowercase_letter]
Examples
iex> Regex.match?(~r/[a-z]{1}/, QuickChex.Generators.lowercase_letter)
true
Specs
non_neg_integer :: integer
generates a non negative integer number between 0 and 1_000_000
How to use
check :the_property,
with: [non_neg_integer]
Examples
iex> num = QuickChex.Generators.non_neg_integer
...> is_number(num) and num >= 0 and num <= 1_000_000
true
Specs
non_neg_integer(integer, integer) :: integer
generates a non negative integer bound to a min and a max value
How to use
check :the_property,
with: [non_neg_integer(1,20)]
Examples
iex> num = QuickChex.Generators.non_neg_integer(1, 2)
...> is_number(num) and num >= 1 and num <= 2
true
Specs
non_neg_rational :: float
generates a non negative rational bound to a min and a max value using :rand.uniform for the decimal representation
How to use
check :the_property,
with: [non_neg_rational]
Examples
iex> num = QuickChex.Generators.non_neg_rational …> is_number(num) and num >= 0 and num <= 1_000_000 true
Specs
non_neg_rational(integer, integer, integer) :: float
generates a non negative rational of a given precision bound to a min and a max value, using :rand.uniform for the decimal representation
How to use
check :the_property,
with: [non_neg_rational(1, 20)] # from 1 to 20
check :another_property,
with: [non_neg_rational(1, 20, 5)] # from 1 to 20 with precision of 5
Examples
iex> num = QuickChex.Generators.non_neg_rational(1, 5, 2) …> is_number(num) and num >= 0 and num <= 1_000_000 true
Specs
number :: integer
returns a number from 0 to 9
How to use
check :the_property,
with: [number]
Examples
iex> Regex.match?(~r/\d{1}/, QuickChex.Generators.number |> to_string)
true
Specs
one_of(list) :: any
returns one of the given values
How to use
check :the_property,
with: [one_of(1, 2, 3)] # exactly 1, 2 or 3
Examples
iex> QuickChex.Generators.one_of([1])
1
iex> r = QuickChex.Generators.one_of([1, 2])
...> r === 1 or r === 2
true
Specs
random_list :: list
generates a random list of randomly generated values. The size is between 0 and 10
How to use
check :the_property,
with: [random_list]
Specs
random_list(integer) :: list
generates a random list of randomly generated values with the provided size
How to use
check :the_property,
with: [random_list(2)]
Specs
random_list(integer, integer) :: list
generates a random list of randomly generated values with a size between the min and max sizes provided
How to use
check :the_property,
with: [random_list(2, 10)]