Skip to content

Instantly share code, notes, and snippets.

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

  • Save CoditCompany/71624ce0fb16ef36bb808409a6009dac to your computer and use it in GitHub Desktop.

Select an option

Save CoditCompany/71624ce0fb16ef36bb808409a6009dac to your computer and use it in GitHub Desktop.
let pitem = pipe5 pid_pipe pdes_pipe pquantity_pipe punitPrice_pipe pnotes itemOpt
let itemRE = "ITEM[0-9]{3}-[A-Z]{2}\|[A-Za-z]+\|[0-9]\|([0-9]+\.[0-9]+|[0-9])\|[A-Za-z ]+"
let genItemId = gen {
let! number = genString num 3
let! capitals = genString AZ 2
return sprintf "ITEM%s-%s" number capitals }
let genQuantity =
Arb.generate<byte>
|> Gen.map string
let genUnitPrice =
Arb.generate<NormalFloat>
|> Gen.map (fun (NormalFloat x) -> string x)
let genItem = gen {
let! itemId = genItemId
let! description = genString (AZ @ az) 10
let! quantity = genQuantity
let! price = genUnitPrice
let! notes = genString (AZ @ az @ [ ‘ ‘ ]) 10
return [ itemId; description; quantity; price; notes ]
|> List.reduce (sprintf "%s|%s") }
[<Property>]
let ``Item gets parsed when it gets a valid input`` () =
genItem
|> Gen.filter (matchRegex itemRE)
|> Arb.fromGen
|> Prop.forAll <| exercise pitem
[<Property>]
let ``Item don't gets parsed when it gets an invalid input`` () =
Arb.generate<NonNull<String>>
|> Gen.map (fun (NonNull x) -> x)
|> Gen.filter (not << matchRegex itemRE)
|> Arb.fromGen
|> Prop.forAll <| (not << exercise pitem)
[<Property>]
let ``Item gets parsed the same as the regex variant`` x =
let expected = exercise pitem
let actual = matchRegex itemRE
expected x = actual x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment