8
$\begingroup$

Is there QuickCheck-like testing framework variant for Mathematica?

We could analyse function argument patterns and generating arbitrary values matching patterns. The idea of generating values, testing rewriting rules and validating that the result match the required pattern seem very natural to pattern rewriting system.

$\endgroup$
3
  • 2
    $\begingroup$ Take a look at VerificationTest and TestReportObject and TestReport. You will have to do some of the work yourself when compared with some other testing frameworks, but there is a lot of capability there. $\endgroup$ Commented May 21, 2020 at 20:19
  • $\begingroup$ thanks @MikeColacino I'm aware of MUnit, but the whole idea of QuickCheck is an automatic test case generation (from types in languages like Haskel or Scala) and property-based testing. In case of Wolfram language we could use automatic generation of test data from patterns. $\endgroup$ Commented May 22, 2020 at 8:22
  • $\begingroup$ Hi @PavelPerikov! I just published this, hope it helps! community.wolfram.com/groups/-/m/t/2309649 $\endgroup$
    – Cabral
    Commented Jul 11, 2021 at 3:07

1 Answer 1

5
$\begingroup$

I've created a pretty cool package for automated property-based testing called quickcheck.wl, you pass three arguments to the function: the name of you property, the actual property (must be an equation, inequation or anything that yields a boolean value like a logical operator) and some assumptions.

QuickCheck[
  "Conjugating a complex flips the imaginary sign",
  Conjugate[a] == Re[b] + -1 Im[b] I,
  "Assume" -> {a -> \[CapitalTau]ComplexInteger}
];

enter image description here

It will test the property by fuzzing the property symbolically. You can specify many types, currently, there are 18 types..

enter image description here

The function can have a few useful options, such as the exponent range of decimals and integers, and minimum-maximum sizes for lists and strings.

enter image description here

$\endgroup$
1
  • $\begingroup$ Wow, that's cool! I will give it a try. Thank you! $\endgroup$ Commented Jul 12, 2021 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.