quickcheck

Haskell QuickCheck2 using ByteString?

假装没事ソ 提交于 2019-11-30 23:40:24
问题 The RWH books says that to get ByteString support, I need to add: instance Arbitrary B.ByteString where arbitrary = fmap B.pack arbitrary coarbitrary = coarbitrary . B.unpack But my GHC 7.2 with QuickCheck 2.4.1.1 tells me: `coarbitrary' is not a (visible) method of class `Arbitrary' Any pointers? 回答1: coarbitrary has moved to it's own typeclass CoAbritary in QC 2.0, so simply just remove the equation for coarbitrary . Also see the latest documentation. 来源: https://stackoverflow.com/questions

Controlling how test data is generated in QuickCheck

南楼画角 提交于 2019-11-30 04:48:43
I wrote an algorithm to find a solution to the subset sum problem in Haskell. The signature is subsetSum :: (Ord a, Num a) => [a] -> a -> Maybe [a] QuickCheck seems to be a good fit to test that. For example I here is one of the properties that I could check: prop_sumEqualsS l s = case subsetSum l s of Just solution -> (sum solution) == s Nothing -> True The problem is that the algorithm is quite computationally intensive and running 100 tests with big input lists takes ages to run. I tried with QuickCheck 1 and it did run quickly, but the data sets used for testing were very small. After

Testing IO actions with Monadic QuickCheck

纵然是瞬间 提交于 2019-11-29 19:42:55
Can anyone give me a brief example of testing IO actions using Monadic QuickCheck? The Test.QuickCheck.Monadic module lets you test monadic code, even things that run in IO . A monadic property test is of type PropertyM m a , where m is the monad the test runs in and a is ultimately ignored. In the case of PropertyM IO a , you convert the monadic test to a Property by using monadicIO ; for all other monads, you use monadic instead (which takes a function to run the monad, something IO doesn't have). In a monadic test, the value return ed out of the monad is ignored. To check an expression, use

Testing QuickCheck properties against multiple types?

梦想与她 提交于 2019-11-29 06:12:05
I have a type class Atomic , which defines functions for converting certain types to/from a wrapper value ( Atom ). I'd like to define a QuickCheck property which states: "for all instances of Atomic , any value may be stored and retrieved safely". The property looks like this: class Atomic a where toAtom :: a -> Atom fromAtom :: Atom -> Maybe a prop_AtomIdentity x = fromAtom (toAtom x) == Just x However, if I just try to run that property through QuickCheck, it just picks one instance ( Bool ) and tests it. I'm currently working around that by defining type signatures for each supported

How can we apply a non-vararg function over a va_list?

柔情痞子 提交于 2019-11-29 04:54:05
Backstory I'm porting the QuickCheck unit test framework to C (see the working code at GitHub ). The syntax will be: for_all(property, gen1, gen2, gen3 ...); Where property is a function to test, for example bool is_odd(int) . gen1 , gen2 , etc. are functions that generate input values for property . Some generate integers, some generate chars, some generate strings, and so on. for_all will accept a function with arbitrary inputs (any number of arguments, any types of arguments). for_all will run the generators, creating test values to pass to the property function. For example, the property

How do you override Haskell type class instances provided by package code?

夙愿已清 提交于 2019-11-29 03:53:02
I have some old Haskell code that includes QuickCheck test cases. Newer versions of QuickCheck (I've just upgraded to 2.4.0.1) include type class instances for Arbitrary Word8 and others. These did not exist in older 2.0.x versions of Test.QuickCheck.Arbitrary. While useful in the general sense, the package-provided Arbitrary Word8 generator is not the one I want to use for my test suite: instance Arbitrary Word8 where arbitrary = frequency [(2, oneof [return ctrlFrameDelim, return ctrlEscape, return ctrlXon, return ctrlXoff]), (8, choose (0, 255))] The above code causes a duplicate instance

Controlling how test data is generated in QuickCheck

自闭症网瘾萝莉.ら 提交于 2019-11-29 02:17:46
问题 I wrote an algorithm to find a solution to the subset sum problem in Haskell. The signature is subsetSum :: (Ord a, Num a) => [a] -> a -> Maybe [a] QuickCheck seems to be a good fit to test that. For example I here is one of the properties that I could check: prop_sumEqualsS l s = case subsetSum l s of Just solution -> (sum solution) == s Nothing -> True The problem is that the algorithm is quite computationally intensive and running 100 tests with big input lists takes ages to run. I tried

QuickCheck: Arbitrary instances of nested data structures that generate balanced specimens

雨燕双飞 提交于 2019-11-28 07:21:17
tl;dr: how do you write instances of Arbitrary that don't explode if your data type allows for way too much nesting? And how would you guarantee these instances produce truly random specimens of your data structure? I want to generate random tree structures, then test certain properties of these structures after I've mangled them with my library code. (NB: I'm writing an implementation of a subtyping algorithm, i.e. given a hierarchy of types, is type A a subtype of type B. This can be made arbitrarily complex, by including multiple-inheritance and post-initialization updates to the hierarchy.

Testing QuickCheck properties against multiple types?

好久不见. 提交于 2019-11-27 23:43:03
问题 I have a type class Atomic , which defines functions for converting certain types to/from a wrapper value ( Atom ). I'd like to define a QuickCheck property which states: "for all instances of Atomic , any value may be stored and retrieved safely". The property looks like this: class Atomic a where toAtom :: a -> Atom fromAtom :: Atom -> Maybe a prop_AtomIdentity x = fromAtom (toAtom x) == Just x However, if I just try to run that property through QuickCheck, it just picks one instance ( Bool

How can we apply a non-vararg function over a va_list?

你说的曾经没有我的故事 提交于 2019-11-27 22:35:32
问题 Backstory I'm porting the QuickCheck unit test framework to C (see the working code at GitHub). The syntax will be: for_all(property, gen1, gen2, gen3 ...); Where property is a function to test, for example bool is_odd(int) . gen1 , gen2 , etc. are functions that generate input values for property . Some generate integers, some generate chars, some generate strings, and so on. for_all will accept a function with arbitrary inputs (any number of arguments, any types of arguments). for_all will