Questions tagged [property-based-testing]
111 questions
2
votes
1 answer
Combining two generators to a single arbitrary in FsCheck
I have a property I want to test on a collection of Stuff, where one of the Stuff satisfies a certain property. I have a way to generate a Stuff satisfying the property, and a way to generate a Stuff that doesn't.
Today, I'm doing something like…
![](../../users/profiles/38055.webp)
Tomas Aschan
- 53,075
- 51
- 214
- 362
2
votes
1 answer
What is a proper use for Prop.delay in ScalaCheck
Delayed generators could make sense for recursive data structures. I'm wondering in which situation this Prop.delay could be helpful. Could you please demonstrate a real life example.
![](../../users/profiles/1655785.webp)
ppopoff
- 609
- 7
- 17
2
votes
1 answer
How can I establish conditions on test inputs when performing Property-based testing?
How can I establish conditions on test inputs when performing Property-based testing?
For example, the following code generates bools when I need ints:
Gen.map (fun v -> v > 0)
Here's the function:
[]
let ``number…
![](../../users/profiles/492701.webp)
Scott Nimrod
- 10,451
- 8
- 46
- 94
2
votes
1 answer
Negative Property-Based Tests
Property-based testing is good when you can express simple and well-defined properties.
I've also had luck with "negative properties" in the case of testing parsers, e.g. by generating invalid identifiers or mismatching indentation for…
![](../../users/profiles/235908.webp)
Simon Shine
- 14,573
- 1
- 40
- 60
1
vote
1 answer
Arbitrary created with flatMap does not consider the filter
I am trying jqwik (version 1.5.1) and I read from the documentation that I can create an Arbitrary whose generated value depends on the one supplied by another Arbitrary, specifically using the flatMap function.
My actual goal is different, but…
![](../../users/profiles/5587393.webp)
Marco Luzzara
- 3,078
- 3
- 9
- 28
1
vote
0 answers
Run a property-test's iterations in parallel?
I have a property-based test (in Hedgehog), that does the following:
Push an item to a remote service that queues it
Poll the remote service to figure out when the item was processed
Assert some properties on the item's processing results
The test…
![](../../users/profiles/534481.webp)
Saurabh Nanda
- 5,737
- 5
- 30
- 52
1
vote
1 answer
Generating recursive structures in scalacheck
I'm trying to make a generator for a recursive datatype called Row. A row is a list of named Vals, where a Val is either an atomic Bin or else a nested Row.
This is my code:
package com.dtci.data.anonymize.parquet
import…
![](../../users/profiles/255999.webp)
mac01021
- 601
- 4
- 12
1
vote
1 answer
How do I register my own FsCheck Generator on Expecto
I've built my generator type that generates multiples of three. I want to use it in a test with Expecto. How can register this generator and tell my test to use it?
let multipleOfThree n = n * 3
type ThreeGenerator =
static member…
![](../../users/profiles/6879050.webp)
ntonjeta
- 23
- 4
1
vote
1 answer
Property based testing for a custom ordered list in Java
Given the following ordering requirement:
All strings starting with "foo" should be first.
All string starting with "bar" should be last.
Strings that do not start with "foo" or "bar" can also be present in the list.
How can one use Property-Based…
![](../../users/profiles/5698534.webp)
Erez Ben Harush
- 711
- 7
- 20
1
vote
1 answer
jqwik pairs of sorted array with some element of it
Following code aims to generate random sorted array, and key as one element of that array. But I do not know the issue, the keys are not in the array?
@Provide
Arbitrary
![](../../users/profiles/12826135.webp)
rima.j
- 21
- 1
1
vote
1 answer
How to generate a sorted array of numbers with jqwik
I am using java jqwik for property based testing, I want to generate sorted array, my code so far:
@Provide
Integer[] arrProvider() {
Arbitrary integerArbitrary = Arbitraries.integers().between(0, 100);
Arbitrary…
![](../../users/profiles/12826135.webp)
rima.j
- 21
- 1
1
vote
1 answer
@composite vs flatmap in complex strategies
hypothesis allows two different ways to define derived strategies, @composite and flatmap. As far as I can tell the former can do anything the latter can do. However, the implementation of the numpy arrays strategy, speaks of some hidden costs
#…
![](../../users/profiles/778278.webp)
Marten
- 1,241
- 9
- 15
1
vote
1 answer
KotlinTest property based testing and generators
I have the following definition of a directed graph in Kotlin. (I'm still learning Kotlin so please forgive any shortcomings. Improvements and suggestions are always welcome.) My goal is to have a method, reverse, which maintains the vertices and…
![](../../users/profiles/3180151.webp)
Sebastian
- 557
- 4
- 11
1
vote
1 answer
How do you generate data from a file in scalacheck?
I want to run scalacheck on a sample dataset that I have in a file. How do I create a generator that reads data from this file and allows me to check a property on it?
![](../../users/profiles/3751515.webp)
indraneel
- 395
- 3
- 10
1
vote
1 answer
Declare relationship between two arguments generated by hypothesis
I am using hypothesis for testing, and I wanted to establish a relationship between two arguments of a test. I am aware of assume, but that seems quite wasteful when I know the constraints beforehand.
Here's a minimal example:
from datetime import…
![](../../users/profiles/289784.webp)
suvayu
- 2,811
- 22
- 30