haskell - QuickCheck: Testing every element in a finite set -


i'm looking way test function on deterministic set of values always (rather randomly selected value list). example, i'd way check

f :: (num a) => -> bool f x = (x - 2) == (x-3+1) 

holds ints 1, 3, , 5, without explicitly writing out

testgroup "f tests" $ map (testproperty . property) [f (1::int), f (3::int), f (5::int)] 

instead, want have wrapper type around int when call f on type, tests f values 1,3, , 5 every time.

the motivation this answer testing polymorphic functions.

i came solution using own instance arbitrary [some c]:

data c   :: (show a, arbitrary a, c a) => -> c  instance arbitrary [dict c] => arbitrary [some c]   arbitrary =     dicts  :: [dict c] <- arbitrary     sequence $ map (\(dict (proxy::proxy a)) -> liftm (arbitrary :: gen a)) dicts   data dict c   dict :: (show a, arbitrary a, c a)         => proxy -> dict c  class classtotest   -- ...      instance arbitrary [dict classtotest]   arbitrary = return $ [dict (proxy::proxy type1),                         dict (proxy::proxy type2)]  testall :: forall . (arbitrary [a]) => (a -> bool) -> gen bool testall f =   xs' <- arbitrary :: gen [a]   return $ , $ map f xs' 

then write function

mytest :: (classtotest a) => -> bool mytest x = error ""  thetest :: test thetest = testproperty "mytest" $ testall mytest 

which generate random value of type1 , run mytest, generate random value type2 , run mytest again. idea list of type* large, i'd rather not rely on random selection ensure in list being tested. problem approach of course quickcheck has generic instance (arbitrary a) => arbitrary [a], code requires -xoverlappinginstances. there nicer way?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -