Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove backward pipe #276

Merged
merged 5 commits into from Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ One way to use Hedgehog to check the above property is to use the `property` com

```fs
property {
let! xs = Gen.list (Range.linear 0 100) <| Gen.int (Range.constant 0 1000)
let! xs = Range.constant 0 1000 |> Gen.int |> Gen.list (Range.linear 0 100)
return List.rev (List.rev xs) = xs
}
}
```

and to test the above property on 100 random lists of integers, pipe it into `Property.print`:

```fs
property {
let! xs = Gen.list (Range.linear 0 100) <| Gen.int (Range.constant 0 1000)
let! xs = Range.constant 0 1000 |> Gen.int |> Gen.list (Range.linear 0 100)
return List.rev (List.rev xs) = xs
}
}
|> Property.print

+++ OK, passed 100 tests.
Expand Down Expand Up @@ -251,10 +251,10 @@ let version =
|> Gen.tuple3
|> Gen.map (fun (ma, mi, bu) -> Version (ma, mi, bu))

Property.print <| property {
Property.print (property {
let! xs = Gen.list (Range.linear 0 100) version
return xs |> List.rev = xs
}
})
Comment on lines -254 to +257
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do either

property {
} |> Property.print

or

property {
}
|> Property.print

but this is fine too.

There are other cases like this. I won't comment on them until we decide what is preferred here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer

let name =
    property {
        // ..
    }
Property.print name

Often times F# code plays chicken with the off-side rule and I'd rather just be blunt and direct.

This is actually one situation where I think <| makes perfect sense to use. Passing a CE directly to a function as the last (or only) parameter, when no other piping is being used.

Property.print <| property {
    // ...
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with anything here


>
*** Failed! Falsifiable (after 3 tests and 6 shrinks):
Expand All @@ -277,7 +277,7 @@ let version =
|> Arb.fromGen

version
|> Prop.forAll <| fun xs -> xs |> List.rev = xs
|> Prop.forAll (fun xs -> xs |> List.rev = xs)
|> Check.Quick

>
Expand Down Expand Up @@ -351,11 +351,10 @@ Hedgehog supports a convenient syntax for working with generators through the `g
```fs
open System.Net

let ipAddressGen : Gen<IPAddress> =
gen {
let! addr = Gen.array (Range.constant 4 4) (Gen.byte <| Range.constantBounded())
return System.Net.IPAddress addr
}
let ipAddressGen : Gen<IPAddress> = gen {
let! addr = Range.constantBounded () |> Gen.byte |> Gen.array (Range.singleton 4)
return System.Net.IPAddress addr
}

ipAddressGen |> Gen.printSample;;

Expand Down Expand Up @@ -559,7 +558,7 @@ Hedgehog will then attempt to generate a test case that *falsifies* the assertio
Values for `xs` need to be generated by a generator, as shown in the *Generators* sections. The following one is for lists of type integer:

```fs
let g = Gen.list (Range.linear 0 20) (Gen.int <| Range.constant 0 100);;
let g = Range.constant 0 100 |> Gen.int |> Gen.list (Range.linear 0 20);;

val g : Gen<int list>
```
Expand Down Expand Up @@ -631,8 +630,8 @@ let tryAdd a b =
if a > 100 then None // Nasty bug.
else Some (a + b)

property { let! a = Gen.int <| Range.constantBounded ()
let! b = Gen.int <| Range.constantBounded ()
property { let! a = Gen.int (Range.constantBounded ())
let! b = Gen.int (Range.constantBounded ())
This conversation was marked as resolved.
Show resolved Hide resolved
return tryAdd a b = Some (a + b) }
|> Property.print;;

Expand All @@ -658,8 +657,8 @@ let tryAdd a b =
if a > 100 then None // Nasty bug.
else Some(a + b)

property { let! a = Gen.int <| Range.constantBounded ()
let! b = Gen.int <| Range.constantBounded ()
property { let! a = Gen.int (Range.constantBounded ())
let! b = Gen.int (Range.constantBounded ())
This conversation was marked as resolved.
Show resolved Hide resolved
counterexample (sprintf "The value of a was %d." a)
return tryAdd a b = Some(a + b) }
|> Property.print;;
Expand All @@ -681,8 +680,8 @@ let tryAdd a b =
if a > 100 then None // Nasty bug.
else Some(a + b)

property { let! a = Gen.int <| Range.constantBounded ()
let! b = Gen.int <| Range.constantBounded ()
property { let! a = Gen.int (Range.constantBounded ())
let! b = Gen.int (Range.constantBounded ())
This conversation was marked as resolved.
Show resolved Hide resolved
where (a < 100)
return tryAdd a b = Some(a + b) }
|> Property.print;;
Expand Down Expand Up @@ -754,8 +753,10 @@ Here's a way to use it:
```fs
let pattern = "^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$"

Property.print <| property { let! s = fromRegex pattern
return matches s pattern }
Property.print (property {
let! s = fromRegex pattern
return matches s pattern
})

+++ OK, passed 100 tests.

Expand Down
Loading