Skip to content

Instantly share code, notes, and snippets.

@CoditCompany
Created October 3, 2017 05:04
Show Gist options
  • Select an option

  • Save CoditCompany/9c4e88c17bf06784946a233b8dbef283 to your computer and use it in GitHub Desktop.

Select an option

Save CoditCompany/9c4e88c17bf06784946a233b8dbef283 to your computer and use it in GitHub Desktop.
let pcustomer = pipe6 country fullname street city state postal optCustomer
let customerRE = "[A-Z]{2}\s+[A-Za-z ]+[0-9A-Za-z ]+[A-Za-z ]+[A-Z]{2}\s[0-9 ]{5}"
let genString xs l =
Gen.elements xs
|> Gen.map string
|> Gen.listOfLength l
|> Gen.map (List.reduce (+))
|> Gen.filter (String.length >> (>=) l)
let AZ = ['A'..'Z']
let az = ['a'..'z']
let numbers = [for i in 0..9 -> i |> string |> char]
let genNum l = genString numbers 5
let genWord l =
AZ @ az @ [' ']
|> genString <| l
let genAWordNum l =
AZ @ az @ numbers @ [' ']
|> genString <| l
let paddingR i s = String.Format (sprintf "{0,-%i}" i, [|box s|])
let genCustString = gen {
let! country = genString AZ 2
let! name = genWord 20
let! street = genWordNum 20
let! city = genWord 15
let! state = genString AZ 2
let! code = genNum 5
return [ (10, country); (20, name); (20, street); (15, city); (3, state); (5, code) ]
|> List.map (fun (x, y) -> paddingR x y)
|> List.reduce (+) }
[<Property>]
let ``Customer gets parsed with a valid input`` () =
let expected = matchRegex customerRE
let actual = exercise pcustomer
genCustString
|> Arb.fromGen
|> Prop.forAll <| fun x ->
expected x = actual x
[<Property>]
let ``Customer doesn't gets parsed with invalid input`` () =
let expected = matchRegex customerRE
let actual = exercise pcustomer
Arb.generate<NonNull<string>>
|> Gen.map (fun (NonNull x) -> x)
|> Gen.filter (not << expected)
|> Arb.fromGen
|> Prop.forAll <| (not << actual)
[<Property>]
let ``Customer gets parsed as the regular expression`` (NonNull x) =
let expected = matchRegex customerRE
let actual = exercise pcustomers
expected x = actual x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment