Skip to content

Give fc.statistics a return value #4342

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

Open
ewinslow opened this issue Oct 20, 2023 · 3 comments
Open

Give fc.statistics a return value #4342

ewinslow opened this issue Oct 20, 2023 · 3 comments
Labels
💡 Idea to investigate Non straightforward features that seems great but need to be assessed and designed carefully.

Comments

@ewinslow
Copy link

💡 Idea

If fc.statistics returned the distribution of classifications in addition to printing it, I'd have a straightforward way to property test my arbitraries. Would be nice to also have the number of skipped generated values.

Motivation

I've been trying my hand at building custom arbitraries, and noting that bugs can definitely sneak into those. In particular, I'm concerned that the arbitraries might not be well distributed across the input space, and manually printing out statistics is a bit of a pain. So my property tests could be passing but not really finding edge cases (e.g. imagine if my custom X generator just always returns empty X for some reason). Even if I get it right, someone else could introduce a regression and we could silently lose coverage that we thought we had. So I'm looking for ways to property test the arbitraries themselves.

Example

fc.assert(fc.property(_, () => {
  const results = fc.statistics(
    fc.string(), // source arbitrary
    (v) => `${v.length} characters`, // classifier
    { numRuns: 100_000 }, // extra parameters
  );

  return results.classes['1 characters'] > 0;
}));

Thanks for considering!

@dubzzz dubzzz added 💡 Idea 💡 Idea to investigate Non straightforward features that seems great but need to be assessed and designed carefully. 🚀 Feature Request ✔️ Feature Accepted and removed 💡 Idea 💡 Idea to investigate Non straightforward features that seems great but need to be assessed and designed carefully. labels Oct 21, 2023
@dubzzz
Copy link
Owner

dubzzz commented Oct 30, 2023

What you are suggesting is close to the feature request: #342 🤔

@ewinslow
Copy link
Author

ewinslow commented Nov 7, 2023

It is related but I think my request is more focused. Just return the data that is already there :). No need for you to come up with any new APIs for labeling properties or asserting on statistical significance. Others can experiment with those using the data returned from this existing API.

@dubzzz dubzzz added 💡 Idea to investigate Non straightforward features that seems great but need to be assessed and designed carefully. and removed 🚀 Feature Request ✔️ Feature Accepted labels Mar 1, 2025
Copy link

stale bot commented Apr 30, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 30, 2025
@dubzzz dubzzz removed the stale label May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 Idea to investigate Non straightforward features that seems great but need to be assessed and designed carefully.
Projects
None yet
Development

No branches or pull requests

2 participants