8

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.

Pavel Perikov
  • 1,345
  • 6
  • 14
  • 2
    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. – Mike Colacino May 21 '20 at 20:19
  • 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. – Pavel Perikov May 22 '20 at 08:22
  • Hi @PavelPerikov! I just published this, hope it helps! https://community.wolfram.com/groups/-/m/t/2309649 – Cabral Jul 11 '21 at 03:07

1 Answers1

5

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

Cabral
  • 138
  • 2
  • 8