A Simple Example

A simple example of a property definition is

let prop_RevRev xs = List.rev(List.rev xs) = xs

This property asserts that the reverse of the reverse of a list is the list itself. To check the property, we load this definition in F# interactive and then invoke

> quickCheck prop_RevRev;;
Ok, passed 100 tests.
val it : unit = ()

When a property fails, FsCheck displays a counter-example. For example, if we define

let prop_RevId xs = List.rev xs = xs

then checking it results in

> quickCheck prop_RevId;;
Falsifiable, after 8 tests:
["[-2; -4; -1]"]
val it : unit = ()

Last edited Nov 30, 2008 at 3:21 PM by kurt2001, version 3


No comments yet.