Cursos de diseño y programación de videojuegos

Quickcheck, a useful tool to avoid bugs

20 Feb 2017

We all know that writing a code free of bugs is very complicated  and unfortunately, in spite of the datamining and machine learning efectiveness, there are many programmers that continually write  the same codes so that they finally make the same mistakes. We can use a useful tool, Quickcheck, which it help us to find our mistakes analysing our analyse our algorithms

Analyses bugs, Quickcheck



How to find bugs

All of this could be easilier if we knew how many parameters produce the same result in our test to each algorithms. Why?, because in that way, we only would have to check a representative parameter of each type.

Now, we are going to see how bugs are hidden( always in a intuitive way). These are often divided in groups of different type of parameters in which our code is excluding or not.

For example, though  our code  worked with the aes prime numbers chain, it would be necessary that the algorithm would be related with the prime numbers in order to our  code would worked with nom prime numbers.

How to use Quickcheck

Quickcheck make a search about all possible amounts of each parameter, like this it establishes a different transversal test to each amount, it means that we choose a invariant code,  Quickcheck  analyses it and it detects the parameters . Thus, a function is obteined to work permanently.

suma x y = x + y

prop_suma_conmutativa :: Int ->Int -> Bool

prop_suma_conmutativa x y = suma x y == suma y x

That way QuickCheck transforms the function into a parameter pro_suma_conmutativa , in order to check it in some different aleatory cases and indicate  if the addition function fullfils this number property 

Why is the invariant choice so important?

As we have said before, QuickCheck , It produces so many arguments to our test as the amount of parameters that we choose, but it is important to know that they keep a exponential relation between them . Therefore, invariants and their choice is a fundamental matter. This means, we have to look invariants that connects relations between them and covers the Quickcheck  results.


Finally, we have explained how this tool is really useful to produce million of test and then, we are able to find the mistakes or code bugs. In conclusion, we believe  that the real problem is the invariant choice with which our code is more affected and what are our codes.From Mola Games we hope that it helps you. If you want to read more posts, you can visit our website.Click here!

A window bug



Mola Games

Leave a Reply

Your email address will not be published. Required fields are marked *