TypeClass.Property.Generator protocol (TypeClass v1.2.11-blazing) View Source

Data generator protocol for property checks. The more variation the better.

Link to this section Summary

Functions

Generate a random example of datatype.

Link to this section Types

Link to this section Functions

Generate a random example of datatype.

Examples

defimpl TypeClass.Property.Generator, for: Integer do
  def generate(_), do: :rand.uniform(1000) * Enum.random([1, 1, 1, -1])
end

defimpl TypeClass.Property.Generator, for: BitString do
  def generate(_) do
    Stream.unfold("", &({&1, :rand.uniform(90)}))
    |> Stream.drop(1)
    |> Stream.take(:rand.uniform(4))
    |> Enum.to_list()
    |> List.to_string()
  end
end