Skip to content
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

Zip does not shrink when one value cannot shrink #686

Closed
blind-io opened this issue Dec 3, 2024 · 0 comments
Closed

Zip does not shrink when one value cannot shrink #686

blind-io opened this issue Dec 3, 2024 · 0 comments

Comments

@blind-io
Copy link

blind-io commented Dec 3, 2024

var shrinkable = Arb.From(
    Gen.Choose(0, 10),
    x=> new[]{ x-1 }.Where(x => x >= 0));
var notShrinkable = Arb.From(Gen.Choose(0, 10));
var zipped = shrinkable.Zip(notShrinkable);
zipped.Shrinker((10, 10)); // empty, expected (9, 10)

Actual behaviour:
The behaviour of shrinking using Zip is to shrink each independent variable together and to stop shrinking when one variable stops providing shrink values.

Expected behaviour:
Independent variables are shrunk independently. If one value cannot shrink then the other should be permitted to shrink.

public static Arbitrary<(T1, T2)> Zip<T1, T2>(
    this Arbitrary<T1> first,
    Arbitrary<T2> second) =>
    Arb.From(
        first.Generator.Zip(second.Generator),
        tuple => new[]
        {
            first.Shrinker(tuple.Item1).Select(x => (x, tuple.Item2)),
            second.Shrinker(tuple.Item2).Select(x => (tuple.Item1, x)),
        }.SelectMany());

This implementation provides the expected result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant