Skip to content

Commit

Permalink
removed duplicates from frequency shrink tree #319
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonMN committed Feb 23, 2021
1 parent 4297e1e commit 2177401
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Hedgehog/Gen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,26 @@ module Gen =
else
pick (n - k) ys

let f n =
let smallWeights =
xs
|> List.map fst
|> List.scan (+) 0
|> List.pairwise
|> List.takeWhile (fun (a, _) -> a < n)
|> List.map snd
|> List.toArray
let length = smallWeights |> Array.length
Shrink.createTree 0 (length - 1)
|> Tree.map (fun i -> smallWeights.[i])

gen {
let! n = Range.constant 1 total |> integral
let! n =
Range.constant 1 total
|> integral
|> toRandom
|> Random.map (Tree.outcome >> f)
|> ofRandom
return! pick n xs
}

Expand Down

0 comments on commit 2177401

Please sign in to comment.