Live data from Hacker News

Hegel, a universal property-based testing protocol and family of PBT libraries

hegel.dev

41–42 of 42 posts

Re: Hegel, a universal property-based testing protocol and family of PBT libraries

#41
post #33

How does this compare to https://academy.fpblock.com/blog/quickcheck-hedgehog-validit... ? As far as I understand, Validity also has free generators and shrinking for types by having them implement various typeclasses that represent invariants and also has pre-made combinators to test properties with.

So with the caveat that I'm not super familiar with Validity...

The biggest thing that leaps out at me looking at it is that Hegel is very built around flexible user-specified data generation (using the library's base generators and combinators) mixed freely with test execution. Validity in contrast looks extremely type-based, which is convenient when you're only testing fairly general properties of built-in types, but I've never found flexible enough to be a really good basis for property-based testing once your testing needs get even a bit more complicated. e.g. a lot of tests want some sort of upper and lower bounds on their numbers, and I don't want to define a type for each.

For an only slightly more involved example of this, suppose you've got, say, a Project type, and Projects have an owner that is a User. You might want a test that is about a single user that has some number of projects. In a generator-based approach, this is easy: You just generate a User object, then you generate a bunch of Project objects that have to have that User as their owner. Just works.

In contrast, in a type based approach, there's basically no way to express this without e.g. defining a new ProjectsOwnedByASingleUser type and defining what it means to be a valid instance of that type... It's a lot of machinery for what is IMO a strictly worse user experience.

Re: Hegel, a universal property-based testing protocol and family of PBT libraries

#42
post #37

This is the first time I hear of property-based testing, and I am intrigued. What is the difference between this and a sufficiently expressive structural type system?

Given some system under test (SUT) with inputs (T, G...) and expected outputs derived from the inputs T', G' etc., a property based testing framework attempts to exercise the entire domain of values assignable to T, G, etc. against the SUT. The generators of T, typically called an Arbitrary can be constrained, e.g Arbitrary could generate any float or just non-negative integers. Ideally we would define an Arbitrary o…

I am sorry, I am not a real computer scientist and I find it difficult to find the right term. With "sufficiently expressive", I mean things like dependent types and refinement types, that can express the constraint on a unit vector.

It seems to me that this is more or less the same thing, but Monte Carlo. Like MCMC vs symbolic Bayesian inference.

Post reply on HN