Permalink
Browse files

Switch from FsCheck to Hedgehog.

Since all NuGet Packages are checked in, I didn't want to run paket install, as this would produce a large diff. It should be done fairly easily though with something like:

  # Assuming that `git clean -xdf` has run first.
  $ .paket/paket.bootstrapper.exe
  $ .paket/paket.exe install
  $ ./build.sh
  • Loading branch information...
moodmosaic committed Aug 9, 2017
1 parent b79d67e commit 6f1d2bf0812609da38e0ac1520195ab3fdfea945
Showing with 47 additions and 38 deletions.
  1. +43 −36 FSharp/BookingApi/MaîtreDTests.fs
  2. +2 −1 FSharp/BookingApi/paket.references
  3. +2 −1 FSharp/paket.dependencies
@@ -1,45 +1,52 @@
module Ploeh.Samples.MaîtreDTests
open Ploeh.Samples.MaîtreD
open FsCheck
open FsCheck.Xunit
open Hedgehog
open Xunit
open System
open Swensen.Unquote
module Tuple2 =
let curry f x y = f (x, y)
module Gen =
let reservation = gen {
let! PositiveInt quantity = Arb.generate
let! reservation = Arb.generate
return { reservation with Quantity = quantity } }
[<Property(QuietOnSuccess = true)>]
let ``tryAccept behaves correctly when it can accept``
(NonNegativeInt excessCapacity) =
Tuple2.curry id
<!> Gen.reservation
<*> Gen.listOf Gen.reservation
|> Arb.fromGen |> Prop.forAll <| fun (reservation, reservations) ->
let capacity =
excessCapacity
+ (reservations |> List.sumBy (fun x -> x.Quantity))
+ reservation.Quantity
let actual = tryAccept capacity reservations reservation
Some { reservation with IsAccepted = true } =! actual
[<Property(QuietOnSuccess = true)>]
let ``tryAccept behaves correctly when it can't accept``
(PositiveInt lackingCapacity) =
Tuple2.curry id
<!> Gen.reservation
<*> Gen.listOf Gen.reservation
|> Arb.fromGen |> Prop.forAll <| fun (reservation, reservations) ->
let capacity =
(reservations |> List.sumBy (fun x -> x.Quantity)) - lackingCapacity
let actual = tryAccept capacity reservations reservation
None =! actual
let reservation =
gen {
let! bookingDate = Gen.dateTime |> Gen.map DateTimeOffset
let! positiveQty = Gen.int (Range.linear 1 100)
let! trueOrFalse = Gen.bool
return { Date = bookingDate
Quantity = positiveQty
IsAccepted = trueOrFalse }
}
[<Fact>]
let ``tryAccept behaves correctly when it can accept`` () =
property {
let! reservation = Gen.reservation
let! reservations = Gen.list (Range.linear 0 100) Gen.reservation
let! excessCapacity = Gen.int (Range.linear 0 100)
let capacity = excessCapacity
+ (reservations |> List.sumBy (fun x -> x.Quantity))
+ reservation.Quantity
let actual = tryAccept capacity reservations reservation
return Some { reservation with IsAccepted = true } = actual
}
[<Fact>]
let ``tryAccept behaves correctly when it can't accept`` () =
property {
let! reservation = Gen.reservation
let! reservations = Gen.list (Range.linear 0 100) Gen.reservation
let! lackingCapacity = Gen.int (Range.linear 1 100)
let capacity = (reservations |> List.sumBy (fun x -> x.Quantity))
- lackingCapacity
let actual = tryAccept capacity reservations reservation
return None = actual
}
@@ -1,3 +1,4 @@
xunit.runner.console
FsCheck.Xunit
xunit.core
Hedgehog
Unquote
@@ -2,6 +2,7 @@ redirects: on
source https://nuget.org/api/v2
nuget FAKE
nuget FsCheck.Xunit
nuget Hedgehog
nuget Unquote
nuget xunit.core
nuget xunit.runner.console

0 comments on commit 6f1d2bf

Please sign in to comment.