quickcheck

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

旧街凉风 提交于 2019-12-12 10:18:40
问题 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

Quickcheck for runtime errors

╄→гoц情女王★ 提交于 2019-12-11 12:43:27
问题 I have interest in using the quick check library but it seems that it is designed to test properties. What I would like to do is generate random data for my defined data types and test functions I have written. I do not care about what the result is, just if the function produces a runtime error when fed random data. All of the quick check examples I have seen are for testing properties of functions like is the result greater than 5 when fed random data. Is there a way to use quick check in

Example that shows the limitations of integrated shrinking

廉价感情. 提交于 2019-12-11 05:13:57
问题 I just watched a video that presents the notion of integrated shrinking for property based tests. The approach seems to have some advantages over type directed shrinking , however it was pointed out in this reddit thread that the integrated shrinking approach does not fit well in the case of monadic generators: Doing shrinking in your way does not fit well with a monadic style for generators. Here is an example, consider generating an arbitrary list (ignore termination for now): do x <-

Haskell: Property Based Testing for Higher Order Function

痴心易碎 提交于 2019-12-11 05:13:38
问题 I have two properties that a function foo must satisfy: prop_1 :: [Int] -> Bool prop_1 xs = foo xs id == xs prop_2 :: [Int] -> (Int -> Int) -> (Int -> Int) -> Bool prop_2 xs f g = foo (foo xs f) g == foo xs (g . f) I am trying to check whether the above properties satisfy the following function using quickCheck: foo :: [a] -> (a -> b) -> [b] foo xs f = [] When I tried running quickCheck with prop_2 I get the following error: quickCheck(prop_2) <interactive>:18:1: error: No instance for (Show

How to write a test for StateT using QuickCheck

旧街凉风 提交于 2019-12-10 23:33:41
问题 The StateT is in Control.Monad.Trans.State.Lazy The function inside and m being higher kinded makes it hard {-# LANGUAGE FlexibleContexts #-} import Test.QuickCheck newtype StateT s m a = StateT { runStateT :: s -> m (a,s) } instance (CoArbitrary s, Arbitrary s, Arbitrary a) => Arbitrary (StateT s (Maybe) a) where -- doesn't quite work arbitrary = undefined The reason I want to do this is because I want to check using QuickCheck if the applicative instance for StateT that I write (for

Testing monadic laws using QuickCheck

醉酒当歌 提交于 2019-12-10 21:56:25
问题 Is there a library or tools for testing the laws of a custom monad? My current hacked attempt goes something like this: Define Arbitrary1 , similar to Eq1 , Show1 etc. Define a helper type that wraps Arbitrary1 as Arbitrary . Define a test (for example) for monadic laws. Is any of this already implemented somewhere? {-# LANGUAGE RankNTypes, ScopedTypeVariables #-} import Data.Functor.Classes import Data.Proxy import Test.QuickCheck import Test.QuickCheck.Function import Test.QuickCheck.Poly

test isolation between pytest-hypothesis runs

瘦欲@ 提交于 2019-12-10 20:29:22
问题 I just migrated a pytest test suite from quickcheck to hypothesis . This worked quite well (and immediately uncovered some hidden edge case bugs), but one major difference I see is related to test isolation between the two property managers. quickcheck seems to simply run the test function multiple times with different parameter values, each time running my function-scoped fixtures. This also results in many more dots in pytest's output. hypothesis however seems to run only the body of the

Arbitrary instance for TimeOfDay

那年仲夏 提交于 2019-12-10 14:39:18
问题 Using QuickCheck, I'd like to create a series of pseudorandom TimeOfDay values. It's easy to create a specific TimeOfDay : now = TimeOfDay 17 35 22 Printing this with GHCi 8.6.5 yields: 17:35:22 I thought that the Arbitrary instance necessary for creating TimeOfDay values with QuickCheck would thus be: instance Arbitrary TimeOfDay where arbitrary = do hour <- elements [0 .. 23] min <- elements [0 .. 59] -- Going till 60 accounts for leap seconds sec <- elements [0 .. 60] return $ TimeOfDay

Is there a good way to QuickCheck Happstack.State methods?

你说的曾经没有我的故事 提交于 2019-12-10 11:25:23
问题 I have a set of Happstack.State MACID methods that I want to test using QuickCheck, but I'm having trouble figuring out the most elegant way to accomplish that. The problems I'm running into are: The only way to evaluate an Ev monad computation is in the IO monad via query or update . There's no way to create a purely in-memory MACID store; this is by design. Therefore, running things in the IO monad means there are temporary files to clean up after each test. There's no way to initialize a

How to use modifiers with Quickcheck (Positive in my case)

核能气质少年 提交于 2019-12-10 02:56:24
问题 I've a function, rev , that returns some value for a type that is in three typeclasses: rev :: (Integral a, Show a, Read a) => a -> a rev = read . reverse . show I'd like to test some property about it with quickcheck. Though, I'm not interested in testing negative values of Integral types because I'm using Integer by lack of a Natural type in the base library. So I thought, let's take the opposite of the value generated when the value generated is negative and I'll be fine: prop_id ::