Guest User

Untitled

a guest
Oct 18th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. // In this example, we're using FsCheck in an unorthodox way.
  2. // Typically you tell FsCheck to look for something that violates
  3. // your rule. Here, we're reappropriating FsCheck's fuzz testing
  4. // capabilities to enumerate everything that has been deemed
  5. // "valid" to see if it's actually valid to help us figure out the rules.
  6.  
  7. type Money = decimal
  8. type CouponType = FreeMail | FreeSide
  9.  
  10. type PaymentOption =
  11. | Cash of Amount:Money
  12. | Coupon of CouponType
  13. | Credit of Amount:Money * CardNumber:string * Expiration:string
  14. | GiftCard of Amount:Money * Balance:Money * CardNumber:Guid
  15.  
  16. // We'll first assume everything is valid
  17. let isValidPayment(paymentType:PaymentOption) = true
  18.  
  19. // We pass this function to tell FsCheck everything is valid
  20. // so it keeps throwing data at us. We only print the ones that
  21. // we've deemed valid.
  22. let showValidPayment(paymentType) =
  23. if isValidPayment(paymentType) then
  24. printfn "%A" paymentType
  25. true
  26.  
  27. FsCheck.Check.Quick(showValidPayment)
Add Comment
Please, Sign In to add comment