Skip to content

Commit

Permalink
Use Integer in towards for halving during shrinking (#397)
Browse files Browse the repository at this point in the history
* Use Integer in towards for halving during shrinking

This fixes the odd situation in which 2 is not representable as a number. In
particular this occurs in the package 'clash-prelude', which defines types
such as `Unsigned 1` where only 0 and 1 can be represented.

* Special case 1-bit numbers

Co-authored-by: Jacob Stanley <jacob@stanley.io>
  • Loading branch information
jonfowler and jacobstanley committed Jan 25, 2021
1 parent 1a125be commit 4dd8ccd
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hedgehog/src/Hedgehog/Internal/Shrink.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ towards :: Integral a => a -> a -> [a]
towards destination x =
if destination == x then
[]
-- special case for 1-bit numbers
else if destination == 0 && x == 1 then
[0]
else
let
-- Halve the operands before subtracting them so they don't overflow.
Expand Down

0 comments on commit 4dd8ccd

Please sign in to comment.