Questions tagged [property-based-testing]

111 questions
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,566
  • 2
  • 27
  • 46
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:…
ElBaulP
  • 5,097
  • 5
  • 31
  • 66
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
  • 183
  • 2
  • 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
  • 15,633
  • 2
  • 24
  • 56
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,109
  • 15
  • 25
1
vote
1 answer

How to use Property-based testing using FsCheck.NUnit or XUnit?

I new to property-based and unit testing, and in my project I want to to use this technique, but unfortunately it is easy to say... I watched a talk about FsCheck.XUnit library, but the guy was testing numeric function (modulus)... And I want to…
alex_z
  • 329
  • 4
  • 12
1
vote
1 answer

Force specific input with JSVerify

I'm starting to use JSVerify for property based testing. Given a function (just an example) that accepts a string as parameter, I use JSVerify to pass in a large number of arbitrary strings and see if the function behaves as intended for all of…
abl
  • 5,554
  • 2
  • 21
  • 41
1
vote
1 answer

How to accumulate a list of FsCheck generators into a single value?

I wrote an FsCheck generator that yields random glob syntax patterns (e.g. a*c?) along with a random string that matches the pattern (e.g. abcd). However my solution uses a mutable variable and I'm rather ashamed of that. Have a look: open…
Good Night Nerd Pride
  • 6,287
  • 3
  • 38
  • 54
1
vote
1 answer

ScalaCheck not failing?

I'm trying to use ScalaTest with ScalaCheck to do property based testing. I've got the tests outlined below: import org.scalatest.prop.PropertyChecks import org.scalatest.{FlatSpec, Matchers} object Calc { def add(a:Int, b:Int) = a+b def…
ashic
  • 5,932
  • 3
  • 28
  • 47
1
vote
0 answers

How can I Property-based Test a Function that takes a list of functions?

How can I Property-based Test a Function that takes a list of functions? Take the following function: let handleAll handlers item = handlers |> List.collect(fun handler -> handler item) Additional context is as follows: let handleAll handlers…
Scott Nimrod
  • 10,451
  • 8
  • 46
  • 94
1
vote
1 answer

How can I interpret property based test code?

How can I interpret property based test code? I'm struggling to translate the instructions on the following snippet: let myProperty = Prop.forAll fiveAndThrees <| fun number -> let actual = transform number let expected =…
Scott Nimrod
  • 10,451
  • 8
  • 46
  • 94
1
vote
1 answer

In Erlang's PropEr, how to get a sample of a generator?

I'm using PropEr to write my property based test. How can I see what kind of data my generator produces? Let's say I have the following generator: -module(my). -include_lib("proper/include/proper.hrl"). -export([valid_type_gen/0]). valid_type_gen()…
aronisstav
  • 7,148
  • 4
  • 21
  • 45