I am using Haskell and QuickCheck to write a test for the following function:
{-| Given a list of points and a direction, find the point furthest
along in that direction. -}
fn :: (Eq a, Ord a, DotProd a) => [a] -> a -> a
fn pnts dir = pnts !! index
where index = fromJust $ elemIndex (maximum dotproducts) dotproducts
dotproducts = map (dot dir) pnts
I believe this implementation to be correct, since it's not too complex of a function. But, I want to use QuickCheck to test it for some edge cases.
However, I run into the problem that, when I define my QuickCheck tests, they are identical to the function I am testing.
How do I write a test in QuickCheck that tests the purpose of a function without repeating its implementation?
fn
. – ToddArbitrary
for a point? A direction? If so, what property of the randomly generated points is unsatisfactory? – RikerDotProd
and some its instances. It'd also help if you added the QuickCheck tests you tried. – ArolamaximumBy
function inData.List
. UsingfromJust
is unsafe since it can throw an exception. – Term