luc-tielen / lua-quickcheck

Property based testing in Lua, inspired by the original QuickCheck.
MIT License
38 stars 1 forks source link

Add functions to test properties of default Lua metamethods #33

Open ligurio opened 3 years ago

ligurio commented 3 years ago

Lua has a number of default metamethods (Lua 5.3 Manual -> 2.4 – Metatables and Metamethods) that defines an object behaviour for example for default Lua operators. Most of these metamethods can be covered by general properties. For example if a and b have metamethod __eq then (a == b) == (b == a) and (a == b) ~= (a ~= b), for metamethod __lt - (a > b) == (b < a) and so on. I believe it would simplify testing a bit if lua-quickcheck will discover available metamethods and them with such properties.

What do you think, @luc-tielen? I'm ready to spend some time implementing this.

General methods

Mathematic Operators

Bitwise Operators

Equivalence Comparison Operators

luc-tielen commented 3 years ago

Hi @ligurio , thanks for the suggestion.

I'm not so sure about the general methods, but I think the rest could be interesting to provide. I wouldn't automatically do it though, since most of these operations might not make sense, and how would users fix it then? But maybe we could provide some functions that take X generators, and then set up a default property that is often used? For example: property_commutative_addition(generator1, generator2)?