Skip to content

Commit

Permalink
Merge pull request #173 from jwChung/address-out-of-range-value
Browse files Browse the repository at this point in the history
fix for generating out-of-range values,
  • Loading branch information
moodmosaic committed Jul 27, 2018
2 parents 5f14a9c + 9a95b50 commit 252e23a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Hedgehog/Numeric.fs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ type FromBigInt =
fun (x : bigint) -> uint16 (int x)

static member FromBigInt (_ : uint32, _ : FromBigInt) =
fun (x : bigint) -> uint32 (int x)
fun (x : bigint) -> uint32 x

static member FromBigInt (_ : uint64, _ : FromBigInt) =
fun (x : bigint) -> uint64 (int64 x)
fun (x : bigint) -> uint64 x

static member FromBigInt (_ : float32, _ : FromBigInt) =
fun (x : bigint) -> float32 (int x)
Expand Down Expand Up @@ -246,10 +246,10 @@ type ToBigInt =
x

static member ToBigInt (x : uint32) =
bigint (int x)
bigint x

static member ToBigInt (x : uint64) =
bigint (int64 x)
bigint x

static member ToBigInt (x : double) =
bigint x
Expand Down
15 changes: 14 additions & 1 deletion tests/Hedgehog.Tests/GenTests.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Hedgehog.Tests.GenTests

open System
open Hedgehog
open Swensen.Unquote
open Xunit
Expand Down Expand Up @@ -62,4 +63,16 @@ let ``dateTime shrinks to correct mid-value`` () =
|> (fun x -> x.Split System.Environment.NewLine)
|> Array.item 1
|> System.DateTime.Parse
System.DateTime (2000, 1, 1) =! result
System.DateTime (2000, 1, 1) =! result

[<Fact>]
let ``uint64 doesn't return any out-of-range value`` () =
let gen = Gen.uint64 <| Range.constant 1UL UInt64.MaxValue
let actual = Gen.sample 0 100 gen
test <@ actual |> List.contains 0UL |> not @>

[<Fact>]
let ``uint32 doesn't return any out-of-range value`` () =
let gen = Gen.uint32 <| Range.constant 1ul UInt32.MaxValue
let actual = Gen.sample 0 100 gen
test <@ actual |> List.contains 0ul |> not @>

0 comments on commit 252e23a

Please sign in to comment.