[Haskell-beginners] Spec with QuickCheck generationg list of list of the same length

Ondrej Nekola ondra at nekola.cz
Sun Feb 15 10:52:12 UTC 2015


I am playing with Test.Hspec and Test.QuickCheck and I am traying to 
implement KMeans algorithm as a training. I use very simple 
representation of vectors: type LVector=[Double]

I have no problems to write testcases with some concreate examples of 
input and expected output:

it  "sum of vectors is computed field by field" $ do
        (*sumVect* [[1.0, 2.0], [3.0, 4.0], [4, 5]]) `shouldBe` [8.0, 11.0]

or simple properties based tests:

it "zeroVector contains just zeroes" $
        property (\(Positive d) ->  [] == filter (/= 0.0) (*zeroVector*d) )

but I get sticked, when I try to create QuickCheck test, for example for 
the first case (*sumVect*). How can I generate list of lists, where all 
the included lists are of the same length?

Link for some tutorial *) can be, I believe, enough but I would be glad 
for any help.

Thanks
    Ondra @satai Nekola
    ondra at nekola.cz

*) Maybe I have not trained my google good enough yet, but lack of 
tutorials describing more than the most basic usecase is probably the 
most problematic point in re-learning Haskell so far.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150215/d7eccaaa/attachment.html>


More information about the Beginners mailing list