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

more prior art #8

Open
michaelficarra opened this issue May 14, 2024 · 5 comments
Open

more prior art #8

michaelficarra opened this issue May 14, 2024 · 5 comments

Comments

@michaelficarra
Copy link

michaelficarra commented May 14, 2024

JSVerify is another property-based (generative) testing library for JavaScript. Its documentation lists its Arbitrary instances starting here: https://github.com/jsverify/jsverify#primitive-arbitraries

I think it would be a good (necessary but not sufficient) evaluation criteria to ensure that the Arbitrary instances provided by these generative testing libraries could be relatively easily defined in terms of the functions provided in this proposal.

edit: here's another one: fast-check

@tabatkins
Copy link
Collaborator

tabatkins commented May 15, 2024

Yup, between "random number in a range", "random int in a range", and "random value from a list", it looks like all the jsverify primitives are covered. And same with fast-check.

@michaelficarra
Copy link
Author

I dunno about that. For example, it's non-trivial to get a good distribution of BigInts. You'd have to write something like this today:

BigInt(function(){
  let s = '';
  do { s += Math.floor(Math.random()*10); } while(Math.random() < 0.9);
  return s;
}())

There's plenty of ways we could make this better:

  • a built-in random BigInt generator with non-linear distributions (obviously)
  • random Boolean with given probability
  • random Numbers/integers with non-linear distributions
  • random String given a code point generator

And there's plenty of other tricky things. There's lots of design choices to be made with random strings. It's hard to pick a Date (or Temporal.PlainDateTime in modern code) that's bounded by a year/month/day. While the web platform has crypto.randomUUID(), it doesn't have one that would work with a seeded PRNG.

@bakkot
Copy link

bakkot commented May 15, 2024

I don't think those are problems this proposal should aim to solve, personally.

@tabatkins
Copy link
Collaborator

There is no uniform distribution over the integers, but as long as you have a range that you do care about, you can get one easily. For anything else, what distribution you want will depend on your use-case pretty severely.

@michaelficarra
Copy link
Author

Yes, use cases will vary quite a bit, but I think just a few very common (parameterisable) distributions will cover the large majority of non-uniform use cases. As you know, there's precedent for this in Java, Python, and probably others if I went looking.

This is getting a bit off-topic from the original post. Maybe I should move it to #6?

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

3 participants