Questions tagged [property-based-testing]

144 questions
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…
Erez Ben Harush
  • 833
  • 9
  • 26
1
vote
2 answers

How to execute Python functions using Hypothesis' composite strategy?

I am trying to execute a function decorated with Hypothesis' @strategy.composite decorator. I know I can test functions using the @given decorator, such as - from hypothesis import given from hypothesis import strategies as…
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> llstPairs() { // sortedArrayGenerator is…
rima.j
  • 31
  • 2
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 #…
Marten
  • 1,336
  • 10
  • 16
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…
Sebastian
  • 715
  • 6
  • 13
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?
indraneel
  • 405
  • 4
  • 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…
1
vote
2 answers

Haskell: Property Based Testing for Higher Order Function

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…
1
vote
2 answers

Example that shows the limitations of integrated shrinking

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…
1
vote
0 answers

How can I test that integer subtract is not commutative?

I want to write a property-based unit test that proves that the integer subtraction is not commutative. I have this with mocha and fast-check: const fc = require('fast-check') describe('The subtraction', () => { it('is not commutative', () =>…
1
vote
1 answer

Prohibit parameter combinations

I'm trying to use FsCheck to write a basic property based test for a class that generates random DateTimeOffset values in a given interval. [Property] public void ValueBetweenMinAndMax(DateTimeOffset min, DateTimeOffset max) { var sut = new…
Sebastian Weber
  • 6,766
  • 2
  • 30
  • 49
1
vote
1 answer

Difference between instantiating something from the class and from the companion object

I am reading and working on the exercises on the book Funcional Programming in Scala. In the chapter about property testing, one exercise ask to implement def listOf[A](g: Gen[A]): SGen[List[A]], here is the relevant code: case class Gen[+A](sample:…
Alejandro Alcalde
  • 5,990
  • 6
  • 39
  • 79
1
vote
1 answer

FsCheck: Generate Arbitrary of a ArrayList with its elements as Arbitraries in C#

I am using FsCheck in C#, I want to generate Arbitrary of an ArrayList to do PropertyBasedTesting by having 100's of ArrayList. I have this ArrayList with defined Arbitraries (they cannot be changed) for each element in it - E.g.…
grindlewald
  • 323
  • 3
  • 10
1
vote
1 answer

Test use scalatest fail to compile

I have sample test that use PropertyChecks trait: import org.scalatest.prop.PropertyChecks import org.scalatest.{Matchers, PropSpec} class AppTest extends PropSpec with PropertyChecks with Matchers { val invalidCombos = Table( ("str",…
talex
  • 17,973
  • 3
  • 29
  • 66
1
vote
2 answers

generating conditional data with Hypothesis Python

I want to generate a list of lists of integers of size 2 with the following conditions. the first element should be smaller than the second and all the data should be unique. I could generate each tuple with a custom function but don't know how…
Kevad
  • 2,781
  • 2
  • 18
  • 28