Giter Club home page Giter Club logo

Comments (4)

jlink avatar jlink commented on July 20, 2024

I have two answers for you, a simple one and a right one.

Simple Answer

You can always combine arbitraries in several steps, e.g.

@Provide
Arbitrary<Customer> aCustomer() {
    Arbitrary<String> street1 = ...;
    Arbitrary<String> zip1 = ...;
    Arbitrary<String> city1 = ...;
    Arbitrary<String> street2 = ...;
    Arbitrary<String> zip2 = ...;
    Arbitrary<String> city2 = ...;
    Arbitrary<Tuple3> address1 = 
            Combinators.combine(street1, zip1, city1).as((s, z, c) -> Tuple.of(s, z, c);
    Arbitrary<Tuple3> address2 = 
            Combinators.combine(street2, zip2, city2).as((s, z, c) -> Tuple.of(s, z, c);
    return Combinators.combine(address1, address2)
            .as( (t1, t2) -> new  Customer(t1.get1(), t1.get2(), ... t2.get3());
}

I didn't compile the code but you get the idea.

Right Answer

With so many individual parts there are most certainly domain concepts hidden somewhere. Those domain concepts should be domain classes and then get their own arbitrary providers. In this case there's an Address class looming and having that in place I'd probably write an AddressArbitraryProvider and register it, so that I can generate arbitraries for it without any further effort.

Maybe if you post your concrete code, we can look for a good approach together.

from jqwik.

jpotecki avatar jpotecki commented on July 20, 2024

Hi,
thanks for the provided information. Indeed Tuple3 would solve my issue.
Regarding the Right Answer:
Let us stick to the case, where we want to create a Customer
I understand that creating a AddressArbitraryProvider and e.g. a BirthdayInformationArbitratryProvider would be the preferred way to handle these cases. It would be nice to be able to combine these providers if necessary.

from jqwik.

jlink avatar jlink commented on July 20, 2024

So you want to combine arbitraries that are already handled by registered arbitrary providers?
You can do this:

@Provide
Arbitrary<Customer> aCustomer() {
    Arbitrary<Address> address = Arbitraries.defaultFor(Address.class);
    Arbitrary<Birthday> birthday = Arbitraries.defaultFor(Birthday.class);
    return Combinators.combine(address, birthday).as(a, b -> new Customer(a, b));
}

from jqwik.

jlink avatar jlink commented on July 20, 2024

I'd like to close the issue. Any more problems with that or further questions?

from jqwik.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.