431
questions
0
votes
1
answer
60
views
Adding the QuickCheck library to a stack project
I'm trying to add the QuickCheck library to my stack project, I've already added it to build depends on the .cabal file and when I run the stack build command I can see that the library was compiled, ...
3
votes
0
answers
44
views
Never-ending QuickCheck test leaves running process even after interrupting "cabal test"
Take this silly test, which is meant to never terminate:
module Main where
import Control.Monad (unless)
import System.Exit (exitFailure)
import Test.QuickCheck
main :: IO ()
main = do
result <-...
2
votes
1
answer
41
views
How to approach testing for polymorphic functions taking newtype smart wrappers around simple types?
I have written a program in whcih I've defined several functions for which I've defined a concrete signature, say
work :: Foo -> [(Foo, Bar)] -> [(Foo, Bar)]
When approaching QuickCheck-based ...
0
votes
1
answer
58
views
cabal test is inconsistent with its QuickCheck log [duplicate]
The following example fails (like it should) after 5 attempts:
prop_varName :: VarName -> Bool
prop_varName v = let s = content (getVarNameToken v) in
length s <= 2 || isPrefixOf "a&...
1
vote
1
answer
67
views
Printing an expression using Dump library fails
I would like to print the property being tested alongside the argument that caused failure. So, I am trying to solve the second part of the problem by using Debug.Dump from the dump package. This is a ...
1
vote
0
answers
122
views
How can I pinpoint the specific location where property tests fail when using QuickCheck more efficiently?
Current solution:
I am currently using counterexample function from Test.Quickcheck:
counterexample :: Testable prop => String -> prop -> Property
to add informative messages in order to ...
1
vote
2
answers
83
views
Haskell: Using quickCheckAll with a size constraint (e.g. quickCheckWith (stdArgs {maxSize = n}))
I want to be able to use quickCheckAll to run a number of tests together. At the same time, I need to specify size constraints on my tests.
In the following program, there are two tests that are ...
0
votes
1
answer
42
views
Haskell - QuickCheck: Checking Equality in TestTree
I am trying to write a TestTree in which I check the following axiom for my data type
type Deque a = [a]
My approach is the following
prop1 :: TestTree
prop1 = QC.testProperty "read_empty" $...
1
vote
0
answers
58
views
Model based property failed after few tests
I am developing a property based test generator in Erlang. I have developed all the properties successfully, but only model based properties are failed after few tests.
Here is my code:
...
1
vote
1
answer
64
views
How is arbitrary distributed for Int? Why is it limited by so small values?
I am trying to compare the QuickCheck library to the SmallCheck one. In SmallCheck I can reach particular value manipulating depth parameter. In QuickCheck:
>a<-generate (replicateM 10000 ...
0
votes
1
answer
94
views
How to write a Quickcheck property for ANSI escaped coded string parser?
Please consider the following piece of code:
-- Represents a parsing result of an ANSI coded string.
data Slice = Slice
{ text :: String,
color :: Color
}
newtype Color = Color
{ string :: ...
2
votes
1
answer
161
views
Using mocks in unit testing in Haskell?
Consider the following piece of code:
data Slice = Slice
{ text :: String,
color :: Color
}
newtype Color = Color
{ string :: String
}
mainList :: [FilePath] -> [FilePath] -> [...
0
votes
0
answers
132
views
Issues with installing QuickCheck
I am having issues with installing QuickCheck for Haskell using GHC 9.4.4 and GHC 8.8.4, and I get the same output. Any assistance would be greatly appreciated!
Resolving dependencies...
cabal: Could ...
0
votes
1
answer
91
views
How to constraint quickcheck test argument to be non-empty in Rust
I am trying to write a test which depends on non-empty vector of tuples as an argument but unsure of how to add such a constraint using quickcheck.
#[quickcheck]
fn graph_contains_vertex(vs: Vec<(...
1
vote
0
answers
29
views
Is there an easy way to integrate QuickCheck (Quiviq) with Erlang Eunit and if so how?
Whenever I have tried to use Quiviq I am not able to run it within the eunit:test/2. Is there a way to do so, such that you can get the Eunit report, but also showing in detail if the Quiviq fails and ...
3
votes
2
answers
98
views
How to test Monad instance for custom StateT?
I'm learning Monad Transformers, and one of the exercises asks to implement the Monad instance for StateT.
I want to test that my implementation admits to the Monad laws using the validity package, ...
1
vote
1
answer
96
views
QuickCheck returns "0 tests" when checking Applicative homomorphism property (Binary Tree)
I would like to check that homomorphism Applicative law holds for datatype BinTree:
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE TypeApplications #-}
{-# ...
0
votes
1
answer
85
views
Quickcheck Applicative homomorphism law for Binary Tree
I am aware that the following question exists:
haskell - How to quickcheck applicative homomorphism property? - Stack Overflow
However, the introduction of the following PRAGMA
{-# LANGUAGE ...
0
votes
1
answer
46
views
Using QuickCheck properties with coverage inside a monadic context
I'm trying to write a QuickCheck property that uses cover to make sure that the test data covers certain cases in combination with the fact that the test involves an IO action.
The problem essentially ...
0
votes
1
answer
89
views
How do you run a single test with QuickCheck when using monadicIO in Haskell?
I am using QuickCheck as a test suite in Haskell. I want to run a single test that is always the same in the IO Monad.
The problem is that QuickCheck generates 100 tests automatically even though the ...
3
votes
1
answer
143
views
Generate stateful function pointer for FFI testing
I want to generate stateful functions (C signature T f()) with QuickCheck as arguments for foreign functions. Preferably I also want to make them (or their inner s->(T,s)) showable.
I know that for ...
2
votes
1
answer
189
views
How to organize definition with QuickCheck Arbitrary class in Haskell
I am learning to use QuickCheck and find it is a very powerful library. I wrote some toy program with stack, involving a few customized data type and defined all Arbitrary instances in one file in my ...
1
vote
1
answer
223
views
Symbolic calls with Quickcheck in erlang
Hi I am trying to learn quickcheck (quviq) in erlang and I have come across an exercise where I have to test a simulated cache with symbolic calls. However I encounter problems because
I get an
31> ...
1
vote
1
answer
155
views
Are there Rust QuickCheck ports which support running with a seed
I'd like to do quickcheck/property-based testing and have it run in CI, but I don't want to add a randomized test to CI (since it could potentially fail when someone else is attempting to merge an ...
0
votes
1
answer
158
views
QuickCheck Stack Overflow
I have the following struct:
pub struct Restriction {
pub min: Option<u64>,
pub max: Option<u64>,
}
for which I have defined Arbitrary as follows:
impl Arbitrary for Restriction {
...
2
votes
1
answer
276
views
How to explicitly import 'Fn' pattern from Test.QuickCheck?
Haskell's Test.QuickCheck module exports pattern Fn, which I have been using.
When I import it with:
import Test.QuickCheck
it works fine. However, when I import it with:
import Test.QuickCheck (Fn)
...
0
votes
1
answer
557
views
How to configure QuickCheck with cabal?
I'm learning to build a Haskell package. One thing I'm stuck with is running tests with QuickCheck.
Specifically, how can I configure the number of trials to run?
Here is my test file (Test.hs) with a ...
4
votes
2
answers
300
views
Using choose in frequency Haskell QuickCheck
So I have the code below and I am trying to make it an instance of Arbitrary:
data MyData = I Int | B Bool
instance Arbitrary MyData where
arbitrary = do {
frequency [(1, return (I 1)),
...
1
vote
1
answer
215
views
Generating random binary search trees with the Arbitrary typeclass
I am working on a problem set where I must write an arbitrary instance for binary search trees. Here is the code I've written so far:
data Tree e = E | N (Tree e) e (Tree e)
insert :: (Ord e) => e ...
2
votes
1
answer
539
views
Build variable length arguments array for @call
I've recently started learning Zig.
As a little project I wanted to implement a small QuickCheck [1] style helper library for writing randomized tests.
However, I can't figure out how to write a ...
3
votes
1
answer
394
views
Using IO within a QuickCheck property test?
I'm currently writing a Haskell library to replace a closed-source 3rd party command line application. This 3rd party CLI has a spec that I've replicated, but the actually binary allows much more ...
2
votes
3
answers
231
views
What does the maxSize field describe in Args from Test.QuickCheck?
I'm looking at maxSize in Args.
its description says: "Size to use for the biggest test cases". But how is the size of test cases determined? I'd rather to ask than to go through the source ...
3
votes
2
answers
207
views
Why cannot I get `where` to work in Hspec
I'm struggling with the semantics of where within do blocks, specifically with Test.Hspec. The following works:
module ExampleSpec where
import Test.Hspec
import Test.QuickCheck
spec :: Spec
spec = ...
1
vote
0
answers
233
views
Unable to run QuickCheck for Haskell after updating macOS to Monterey
After updating the OS, I have updated the command line tools as well and have tried reinstalling QuickCheck using cabal which shows something like "resolving dependencies". Now every time I ...
2
votes
1
answer
202
views
No instance for (Arbitrary Natural) arising from a use of ‘prop’
I'm trying to write the following test for an implementation of the dyadic rational numbers.
import Numeric.Natural
import Test.Hspec
import Test.Hspec.QuickCheck
import Dyadics
dyadic_add :: ...
2
votes
1
answer
189
views
How to come up with properties in propety based testing
This question applies to any particular programming language.
Let us imagine I have a function that converts a data structure to a string of hex.
func toHex(input: data) => string
Let's say I now ...
1
vote
2
answers
135
views
Issues with QuickCheck involving a data type with a function as a constructor
wrote the code below and am getting some issues with it :
The error I am getting is : Data constructor not in scope: Int :: Int
If I eradicate the Numeric Int element from my array the code works ...
1
vote
1
answer
71
views
How to fix a matching error on a quickCheck done on a valid property of a function?
I want to write a function search :: String -> Char -> [Int] that returns the positions of all occurrences of the second argument in the first. For example:
search "Bookshop" 'o' == [1,...
0
votes
1
answer
169
views
How to make the property test get a collection of entities an entity-generator can return?
I have recently started exploring property based testing using junit-quickcheck. I came across an usecase where a property has to take a list of entities(I have a generator for a standalone entity). I ...
2
votes
0
answers
104
views
Why is 'shrink' not called in a custom Arbitrary instance Haskell's QuickCheck?
I'm trying to understand how shrink works in Haskell's QuickCheck, so I've come up with a minimal example shown below, but when I run it, the falsified examples are not shrunk.
The result object shows ...
1
vote
1
answer
146
views
Is it possible to pass and retrieve a state in a quickcheck generator
I would like to create a quickcheck generator to generate a data structure like a tree. Due to the specifics caracteristics of this structure I would like the value to be generated according to its ...
0
votes
1
answer
233
views
Haskell QuickCheck runs slowly
I am learning Haskell and recently worked on a small project to mimic arithmetics in the way how human does it, ultimately I can keep as many decimal places as I want and computation results are not ...
0
votes
1
answer
230
views
Functor laws checking with QuickCheck-classes library
I want to check functor laws for instance:
instance Functor Stream where
fmap f (x :> xs) = (f x) :> fmap f xs
where Stream is
data Stream a = a :> Stream a
I use QuickCheck.Classes (...
7
votes
2
answers
315
views
Why does quickcheck pass for these two different functions Haskell?
I have two functions. They are:
f1 [] = []
f1 (x:xs) = if contains x xs then f1 xs else x:f1 xs
and
f6 xs = f1 (rev xs)
It would not make sense that these two functions return the same list for ...
3
votes
1
answer
109
views
What's wrong with my quickCheck type declaration?
I roll my own elem function called elem'
elem' :: (Eq a) => a -> [a] -> Bool
elem' n ys = foldl (\acc p -> if (p == n) then True else False) False ys
Seems to work but I want to ...
3
votes
0
answers
126
views
How do I write a Hedgehog generator for a wrapped function?
I'm currently working through the book Thinking with Types. In the third chapter Variance, the author provides an exercise in which the reader should implement the functor instance for T1.
newtype T1 ...
0
votes
2
answers
510
views
Is there any ways to traverse a random json string created by a generator in java?
I have a generator which is generating a completely json scripts with random keys and values(quickcheck.generator). I want to read this string and get the values of the keys. The problem is that each ...
1
vote
2
answers
164
views
QuickCheck Generator not terminating
This QuickCheck generator
notEqual :: Gen (Int, Int)
notEqual = do
(a, b) <- arbitrary
if a /= b
then return (a, b)
else notEqual
Doesn't seem to terminate when passed to forAll. I'm ...
0
votes
1
answer
78
views
quickCheck returns error when comparing zipWith functions
I created my own myzipWith function and want to compare it with the original zipWith with the use of quickCheck.
myzipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
myzipWith a y [] = []
...
0
votes
1
answer
141
views
Is there any way to generate values for testing this way in Haskell QuickCheck?
I have 2 data types that I use for the representation of natural numbers in the unary system
data Valoare_Unar = Unu deriving(Show);
data Numar_Unar = Invalid | Unar [Valoare_Unar] deriving(Show);
I ...