Created
October 17, 2017 17:52
-
-
Save sgoguen/566aed709a29c6d53e7856cddb8960d4 to your computer and use it in GitHub Desktop.
Using FsCheck to Enumerate Invalid Instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In this example, we're using FsCheck in an unorthodox way. | |
// Typically you tell FsCheck to look for something that violates | |
// your rule. Here, we're reappropriating FsCheck's fuzz testing | |
// capabilities to enumerate everything that has been deemed | |
// "valid" to see if it's actually valid to help us figure out the rules. | |
type Money = decimal | |
type CouponType = FreeMail | FreeSide | |
type PaymentOption = | |
| Cash of Amount:Money | |
| Coupon of CouponType | |
| Credit of Amount:Money * CardNumber:string * Expiration:string | |
| GiftCard of Amount:Money * Balance:Money * CardNumber:Guid | |
// We'll first assume everything is valid | |
let isValidPayment(paymentType:PaymentOption) = true | |
// We pass this function to tell FsCheck everything is valid | |
// so it keeps throwing data at us. We only print the ones that | |
// we've deemed valid. | |
let showValidPayment(paymentType) = | |
if isValidPayment(paymentType) then | |
printfn "%A" paymentType | |
true | |
FsCheck.Check.Quick(showValidPayment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment