What is a property?

10 points by ugur


Corbin

We can find Hoare logic here. Let pre and post be pre- and postconditions respectively for an arbitrary pure function f. Specifically,

f :: a -> b
pre :: a -> Bool
post :: b -> Bool

Also, let's generalize the pattern in the article where we put an implied precondition before the rest of the program:

type Property a = a -> Bool
(===>) :: Property a -> Property a -> Property a
p ===> q = \a -> p a `implies` q a

And now we can say that the triple (pre, f, post) is valid whenever the following composite is constantly true:

pre ===> post . f

This ought to give a comma category of triples with types given by f, but I haven't fully worked it out. (Obviously this can't be done over classic Hask).

YogurtGuy

Could proptest be adapted to use this approach?

proptest! {
    #[test]
    fn my_test(x in my_actual_property()) {
        // Where x is of type TestCaseResult, and my_actual_property returns a impl Strategy<Value=TestCaseResult>
        return x;
    }
}

Certainly rust lacks do notation, so it might be annoying to write, but at least Strategy is a monad.

fanf

The back-and-forth between generators and properties reminds me of another approach to randomized testing: rather than creating a random artefact and verifying that a property holds, instead create a random list of operations and when applying the operations verify that the invariants continue to hold. Previously.