QuickCheck-like Framework for C++
I just published a preliminary version of QuickCheck++, an attempt at bringing some of the benefits of Haskell's QuickCheck to C++.
As already said, I quite like the QuickCheck concept of specifying properties rather than a few ad-hoc test cases.
In the past, I sometimes missed QuickCheck when I was coding in some language other than Haskell. It won't be the case anymore for C++ as I just published QuickCheck++, a QuickCheck-like framework for C++.
It is a mix between imperative unit testing approaches à la JUnit, and an approach à la QuickCheck, using property specifications and randomly-generated test cases.
Yet another stupid framework or useful stuff? I have not used it seriously yet so I couldn't say. I'll keep you informed. In the meantime, why not try it for yourself and let me know what you think?
Discussion
Hi, thanks for great library.
It checked by VC++2005, and since there was a bug by conversion of unsigned/signed, it corrected.
http://cid-8361f69420bd2fb3.skydrive.live.com/self.aspx/public/C++/QuickCheck++/generate.hh
Thanks.
I checked your code, but could not include it for two reasons:
However, while checking signedness problems (with
g++ -Wsign-compare -Wsign-conversion, I found (and corrected) another bug inoneOf(). Two more warnings to add to my list!Hello,
Have you every tried to extract theorems from the types of a C++ function or method and see if the actual method holds. Read the paper Theorems for Free!. I think that it would be cool to see if you could get some methods that are not purely functional to hold fro some of these theorems. What I am getting at is the function signature can be used to extract properties that can then be used to check it non-functional C++ counter part – and all for Free!
I am afraid this is not possible for C++ as it is in Haskell. As I understand it, the Theorems for free approach heavily depends on parametricity. However, parametricity in Haskell offers much more stronger guarantees than templating in C++. Let me go through an example.
Given the Haskell function signatures
I can deduce the theorem
rtakes a list of fully parametric arguments. These are not equipped with any operation (theatype is not qualified with any type class).rmust then manipulate the list elements polymorphically (e.g.rcould beid,rev, … but notsortwhich would requireOrd a).On the contrary, C++ templates do not guarantee that. Put boldly, one could say that C++ templates are just advanced macros. If I know that
rhas signature:I do not know whether or not
rinspects its elements. For example,rcould return a sorted version of its input list. There is no equivalent of theOrd aqualification in C++. Calling arthat compares its elements on a list of uncomparable elements is not a type error. It will trigger an instantiation error (the compiler will not know how to compile the comparisons), but this is harder to use as it requires to inspect the function body and not just its signature. I think that C++ types are just not rich enough to allow free theorems.