-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generated arbitrary list from fixed inputs #450
Comments
drobert
changed the title
generated fixed-list arbitrary list?
generated fixed-size arbitrary list?
Jan 9, 2023
drobert
changed the title
generated fixed-size arbitrary list?
generated arbitrary list from fixed inputs
Jan 9, 2023
I haven't gone through your problem in detail (yet). Have you looked at |
A somewhat simpler example using @Property(tries = 10)
void addAgesToFixedListOfUsers(@ForAll("users") List<User> users) {
System.out.println(users);
// Assertions.assertThat(users).hasSize(1);
}
@Provide
Arbitrary<List<User>> users() {
Arbitrary<String> names = Arbitraries.strings().alpha().ofLength(5);
ListArbitrary<User> users = names.map(User::new).list().ofMinSize(1).ofMaxSize(5);
return users.flatMapEach((allUsers, user) -> {
IntegerArbitrary ages = Arbitraries.integers().between(0, 100);
return ages.map(age -> {
user.age = age;
return user;
});
});
}
static class User {
String name;
int age = -1;
public User(String name) {
this.name = name;
}
@Override
public String toString() {
return "User{name='" + name + '\'' + ", age=" + age + '}';
}
} One could argue that there should be a simpler form for return users.flatMapEach((allUsers, user) -> {
IntegerArbitrary ages = Arbitraries.integers().between(0, 100);
return ages.map(age -> {
user.age = age;
return user;
});
}); Especially since IntegerArbitrary ages = Arbitraries.integers().between(0, 100);
return users.combineEach(ages, (user, age) -> {
user.age = age;
return user;
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Testing Problem
In complicated data sets (e.g. for spark or similar) we often need to establish the 'bounds' or 'universe of allowed IDs' or similar such that we can produce a semi-arbitrary data set that still has high likelihood (or perfect likelihood) of joining together safely.
Consider testing a system that combines ad clicks with ad campaigns, with data types looking something like this (note this is an intentionally simplistic example):
Processing might join all ad clicks against all ads against campaigns to produce the total cost (clicks * costs per click) vs the budget for each campaign at some point in time. One important test case is the 'happy path' where all ad clicks correspond to an ad and all ads correspond to a campaign.
Mechanically, I think the approach would generally be to:
Arbitrary<List<Campaign>>
(some arbitrary list of campaigns, comprising the 'universe' of known campaigns)Ad
for eachCampaign
AdClick
for eachAd
(alternatively, produce all known campaign ids and all known ad ids up-front and then generate the full objects from there).
In either case, there would at some point be within a flatMap operation
List<Campaign>
and we need to create at least oneAdGroup
for eachCampaign
. I don't see an approach that looks much different than this:Suggested Solution
I think it would be useful to have a built-in mechanism to go from
List<Arbitrary<T>>
toArbitrary<List<T>>
. (And/orStream<Arbitrary<T>>
). Something like:The above example would then look something like:
The text was updated successfully, but these errors were encountered: