lundi 20 février 2017

Writing test cases in Haskell for differing types

I've made a library that creates "list like" sequences, and of which many Prelude style functions are implemented. I want to write some test cases for this, to ensure my library is producing correct output, and I thought the easiest way to do this is write some functions, convert the results to lists and compare them to the Prelude results. Lets say we've got this:

import qualified MyLibrary as ML
import qualified Prelude as P

For example I may want the following testcase:

P.take 5 (P.enumFrom 1) == toList (ML.take 5 (ML.enumFrom 1))

Note that ML.enumFrom does not output a list, it outputs it's own datatype.

The above works fine, but notice how I'm "repeating myself" (TM). I have to ensure the left and right side are the same otherwise my test case is erroneous.

Is there a nice way to write test cases like this so I don't have to repeat myself?

Aucun commentaire:

Enregistrer un commentaire