quickcheck

How to use 'oneof' in quickCheck (Haskell)

我怕爱的太早我们不能终老 提交于 2019-12-06 03:29:42
问题 I am trying to write a prop that changes a Sudoku and then checks if it's still valid. However, I am not sure how to use the "oneof"-function properly. Can you give me some hints, please? prop_candidates :: Sudoku -> Bool prop_candidates su = isSudoku newSu && isOkay newSu where newSu = update su aBlank aCandidate aCandidate = oneof [return x | x <- candidates su aBlank] aBlank = oneof [return x | x <- (blanks su)] Here are some more info... type Pos = (Int, Int) update :: Sudoku -> Pos ->

Use HSpec and QuickCheck to verify Data.Monoid properties

余生颓废 提交于 2019-12-06 02:37:01
问题 I'm trying to use HSpec and QuickCheck to verify properties of Monoids (associativity and identity element). I am going to verify particular instances, but would like to keep most of the code polymorphic. This is what I came up with after several hours: module Test where import Test.Hspec import Test.QuickCheck import Data.Monoid instance (Arbitrary a) => Arbitrary (Sum a) where arbitrary = fmap Sum arbitrary instance (Arbitrary a) => Arbitrary (Product a) where arbitrary = fmap Product

Haskell: QuickCheck property fails tests using implications

允我心安 提交于 2019-12-05 07:23:56
I've got the following property I want to test using quickcheck: prop_zip xs ys = length xs == length ys ==> unzip (zip xs ys) == (xs,ys) Eventhough it seems to be logically right according to the definition of zip and unzip, that this property should be correct fo lists of the same length, the quickcheck ends with: *** Gave up! Passed only 49 tests. Thanks in advance for any hint or advice! Preconditions that are difficult to meet by generating random test cases are often a bad idea in QuickCheck. Instead, you should use generators carefully to construct test cases that meet the precondition

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

泪湿孤枕 提交于 2019-12-05 04:02:11
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 :: (Integral a, Show a, Read a) => Positive a -> Bool prop_id n | n >= 0 = (rev.rev) n == n | otherwise = let n'

Find the value that failed for quickcheck

天涯浪子 提交于 2019-12-04 23:34:22
When a value fails a QuickCheck'd test, I'd like to use it for debugging. Is there any way I can do something like: let failValue = quickCheck' myTest in someStuff failValue If my data was read able then I could probably hack some way to get it in from IO, but it's not. I couldn't find anything in the QuickCheck API to do this in a nice way, but here's something I hacked together using the monadic QuickCheck API. It intercepts and logs the inputs to your property in an IORef , and assumes that if it failed, the last one was the culprit and returns it in a Just . If the test passed, the result

Where do QuickCheck instances belong in a cabal package?

旧巷老猫 提交于 2019-12-04 15:57:40
问题 I have a cabal package that exports a type NBT which might be useful for other developers. I've gone through the trouble of defining an Arbitrary instance for my type, and it would be a shame to not offer it to other developers for testing their code that integrates my work. However, I want to avoid situations where my instance might get in the way. Perhaps the other developer has a different idea for what the Arbitrary instance should be. Perhaps my package's dependency on a particular

Arbitrary instance for generating unbiased graphs for quickcheck

匆匆过客 提交于 2019-12-04 15:07:53
module Main where import Test.QuickCheck import Data.Set as Set data Edge v = Edge {source :: v, target :: v} deriving (Show,Eq,Ord) data Graph v = Graph {nodes :: Set v, edges :: Set (Edge v)} deriving Show instance Arbitrary v => Int-> Arbitrary (Edge v) where arbitrary = sized aux where aux n = do s <- arbitrary t <- arbitrary `suchThat` (/= s) return $ Edge {source = s, target = t} instance (Ord v, Arbitrary v) => Arbitrary (Graph v) where arbitrary = aux `suchThat` isValid where aux = do ns <- arbitrary es <- arbitrary return $ Graph {nodes = fromList ns, edges = fromList es} This current

How do I test this applicative instance with checkers? (No instance for CoArbitrary (Validation e0 [Char]))

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 09:23:56
Checkers is a library for reusable QuickCheck properties, particularly for standard type classes How do I write a checkers instance to test whether my applicative instance of Validation is valid? import Test.QuickCheck import Test.QuickCheck.Checkers import Test.QuickCheck.Classes import Control.Applicative import Data.Monoid data Validation e a = Error e | Scss a deriving (Eq, Show) instance Functor (Validation e) where fmap _ (Error e) = Error e fmap f (Scss a) = Scss $ f a instance Monoid e => Applicative (Validation e) where pure = Scss (<*>) (Scss f) (Scss a) = Scss $ f a (<*>) (Error g)

Use HSpec and QuickCheck to verify Data.Monoid properties

非 Y 不嫁゛ 提交于 2019-12-04 09:21:55
I'm trying to use HSpec and QuickCheck to verify properties of Monoids (associativity and identity element). I am going to verify particular instances, but would like to keep most of the code polymorphic. This is what I came up with after several hours: module Test where import Test.Hspec import Test.QuickCheck import Data.Monoid instance (Arbitrary a) => Arbitrary (Sum a) where arbitrary = fmap Sum arbitrary instance (Arbitrary a) => Arbitrary (Product a) where arbitrary = fmap Product arbitrary prop_Monoid_mappend_mempty_x x = mappend mempty x === x sumMonoidSpec = it "mappend mempty x = x"

How to use 'oneof' in quickCheck (Haskell)

。_饼干妹妹 提交于 2019-12-04 08:40:42
I am trying to write a prop that changes a Sudoku and then checks if it's still valid. However, I am not sure how to use the "oneof"-function properly. Can you give me some hints, please? prop_candidates :: Sudoku -> Bool prop_candidates su = isSudoku newSu && isOkay newSu where newSu = update su aBlank aCandidate aCandidate = oneof [return x | x <- candidates su aBlank] aBlank = oneof [return x | x <- (blanks su)] Here are some more info... type Pos = (Int, Int) update :: Sudoku -> Pos -> Maybe Int -> Sudoku blanks :: Sudoku -> [Pos] candidates :: Sudoku -> Pos -> [Int] [return x | x <-