Search⌘ K
AI Features

Modeling

Explore the concept of modeling in property-based testing and learn how to create simple and obviously correct models to validate complex implementations. Understand how modeling helps compare optimized code against straightforward reference versions, ensuring reliable and understandable tests even for stateful systems and side effects. This lesson guides you through practical examples and strategies to effectively apply modeling for robust software verification.

What is modeling?

Modeling essentially requires us to write a simple implementation of our code, even if it is algorithmically inefficient. The model should be so simple that it is obviously correct. We can then optimize the real system as much as we want. As long as both implementations behave the same way, the complex and the obviously correct implementation should work equally as well. The complex implementation, however, probably also works faster. So, for code that does a conceptually simple thing, modeling is useful.

Example

For our example let’s look at the function that we created in the previous chapter, the biggest/1 function which returns the largest value in a ...