Comments (4)
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.
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.
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.
I'd like to close the issue. Any more problems with that or further questions?
from jqwik.
Related Issues (20)
- Consider supporting @UseType for sealed interfaces HOT 8
- Shrinking of large arrays uses a very large amount of memory HOT 11
- StackOverflowError when shrinking large arrays HOT 14
- question: any way to imperatively summon a pre-configured arbitrary? HOT 15
- Make nested groups work for JDK >= 18 HOT 31
- Combinators.combine.as nullability of arguments HOT 4
- Can't figure out how to create an Arbitrary I want HOT 10
- Bug: Arbitraries.strings().uniqueChars() will sometimes shrink to values with duplicate chars HOT 5
- Bug: Uniform Distribution of Integers does not work if range is >= Integer.MAX_VALUE HOT 2
- Kotlin K2 Support HOT 23
- Time Module: Support generating java.sql.Timestamp
- adding `jqwik-kotlin` causes existing tests written in java to fail with NPE HOT 18
- Potential idea for running `SAMPLE_FIRST`/`SAMPLE_ONLY` for stateful tests HOT 2
- Lifecycle method called twice when subclassing HOT 4
- Cannot use Arbitrary.generator() outside jqwik HOT 6
- Is Arbitrary<@Nullable T> correct/intended under JSpecify semantics? HOT 32
- TypeUsage example from user guide fails in 1.8.x HOT 8
- Right Way to Integrate jqwik with DataFaker HOT 23
- Generic @Provide methods are sensitive to the type variables' names HOT 3
- Allowing Sampling of Arbitraries with Injected Seed HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jqwik.