Quicksort implementation and testing FsCheck vs ScalaCheck
In this functional exercise, I’m going to implement simple Quicksort algorithm and examine it by using property-based testing approach.
For those who are not familiar with property-based testing, it is a great talk of Scott Wlaschin - An introduction to property based testing.
Libs
- FsCheck is a library for testing .NET programs on F#, C#, and VB.
- ScalaCheck is a library used for automated property-based testing of Scala or Java programs.
Both libraries are ports of Haskell’s QuickCheck, but ScalaCheck has influenced FsCheck as well.
F#
output:
> Check.One (config, list is sorted
badSort)
;;
Falsifiable, after 508 tests (3 shrinks) (StdGen (93102065,296205589)):
Label of failing property: neighbour pairs from a list should be ordered
Original:
[2; -1]
Shrunk:
[1; 0]
Ok, passed 100000 tests.
Scala
Sort function looks quite similar to F# version.
output:
> + list is sorted.sorted list should have same length as original: OK, passe
d 100000 tests.
! list is sorted.neighbour pairs from a list should be ordered: Falsified a
fter 1506 passed tests.
> ARG_0: List(“0”, “-1”)
> ARG_0_ORIGINAL: List(“2147483647”, “-1208819329”)
+ list is sorted.sorted list should have same length as original: OK, passe
d 100000 tests.
+ list is sorted.neighbour pairs from a list should be ordered: OK, passed
100000 tests.
res0: Unit = ()
blog comments powered by Disqus