
I'd heard of quick check, but haven't got my head around it. This
seems like a good place to start.
I understand you have to build an invariant and then you can automate
against it, eg "reverse of reverse is your original string"
prop_RevRev xs = reverse (reverse xs) == xs
where types = xs::[Int]
(from http://www.kimbly.com/blog/000042.html)
but what would be your invariant with the drop function?
At first I thought
prop_HeadConsDropped xs = (head xs) : (drop 1 xs) == xs
where types = xs::[a]
But I think then you have the issue of head nil being an error.
So, is there a better strategy? Or is using quickcheck here overkill?
2007/2/26, Antonio Cangiano
On 2/26/07, Thomas Hartman
wrote: Here's my, probably very obvious, contribution.
What I'd like feedback on is
1) code seem ok? (hope so!)
Hi Thomas,
tail [] raises an error, therefore your code will fail when n > length xs ( e.g. mydrop 3 [1,2] will raise an exception, where [] is the expected result). Your function is also limited to list of Int only (mydrop :: Int -> [Int] -> [Int]).
2) What do you think of the tests I did to verify that this behaves the way I want? Is there a better / more idiomatic way to do this?
You may be interested in the following projects:
QuickCheck: http://www.cs.chalmers.se/~rjmh/QuickCheck/ HUnit: http://sourceforge.net/projects/hunit
Regards, Antonio -- http://antoniocangiano.com Zen and the Art of Ruby Programming