Skip to content

API Suggestion: Creating Arbitraries of Fundamental Types #2

@jlink

Description

@jlink

In Jqwik 1 all fundamental type arbitraries were rooted in class Arbitraries.
Therefore, you create an arbitrary for Strings with Arbitraries.strings() and integers with Arbitraries.integers() and so on.
Also, more fundamental arbitrary types, like simply choosing one of several values or selecting one arbitraries from many,
started there.
This lead to many (43) static public methods in Arbitraries; too many to navigate easily.

In order to make navigation easier, I suggest to put those fundamental creation methods on several base classes:

  • Class Numbers will contain creation methods for all Java number types, e.g.

    • Numbers.integers()
    • Numbers.bigDecimals()
    • etc.
  • Class Strings, with

    • Strings.strings()
    • Strings.unicodCodepoints()
    • Strings.chars()
  • Class Values, with

    • Values.just(..)
    • Values.of(..)
    • Values.frequency(..)
    • Values.oneOf(..) for choosing among arbitraries
    • Values.lazy(..)
    • Values.defaultFor(..)
    • etc.

Other base classes - potentially located in modules outside the core - could be:

  • Maps for creating a map from one type to another
  • Dates, Times, ....

Design Questions

  • Does distributing static creation methods over several class help discoverability or harm it?
  • Are there other approaches with good discoverability, e.g. starting from one main arbitrary builder function and specializing from there. E.g.: Arbitraries.numbers().bigIntegers() ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions