Skip to content

Commit e28b443

Browse files
deal with wrapping around
1 parent f418639 commit e28b443

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Constrained/NumOrd.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,12 @@ class HasDivision a where
726726
Specification a
727727
divideSpec a ts = fromSimpleRepSpec $ divideSpec (toSimpleRep a) ts
728728

729-
instance {-# OVERLAPPABLE #-} (HasSpec a, Integral a, TypeSpec a ~ NumSpec a) => HasDivision a where
729+
instance {-# OVERLAPPABLE #-} (HasSpec a, MaybeBounded a, Integral a, TypeSpec a ~ NumSpec a) => HasDivision a where
730730
doDivide = div
731731

732732
divideSpec 0 _ = TrueSpec
733733
-- TODO This is all wrong and hence the tests are all wrong
734-
divideSpec a (NumSpecInterval ml mu) = typeSpec ts
734+
divideSpec a (NumSpecInterval (unionWithMaybe max lowerBound -> ml) (unionWithMaybe min upperBound -> mu)) = typeSpec ts
735735
where
736736
ts | a > 0 = NumSpecInterval ml' mu'
737737
| otherwise = NumSpecInterval mu' ml'
@@ -740,13 +740,13 @@ instance {-# OVERLAPPABLE #-} (HasSpec a, Integral a, TypeSpec a ~ NumSpec a) =>
740740
adjustLowerBound l =
741741
let r = l `div` a in
742742
if r * a < l
743-
then r + 1
743+
then r + signum a
744744
else r
745745

746746
adjustUpperBound u =
747747
let r = u `div` a in
748748
if r * a > u
749-
then r - 1
749+
then r - signum a
750750
else r
751751

752752
instance HasDivision Float where

src/Constrained/Test.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import Prettyprinter
4949
import Test.QuickCheck hiding (Fun)
5050
import qualified Test.QuickCheck as QC
5151
import Data.Word
52+
import Data.Int
5253

5354
-- | Check that a generator from a given `Specification` is sound, it never
5455
-- generates a bad value that doesn't satisfy the constraint
@@ -396,8 +397,12 @@ instance QC.Arbitrary TestableFn where
396397
TestableFn $ AddW @Int
397398
, TestableFn $ NegateW @Int
398399
, TestableFn $ MultW @Int
399-
, TestableFn $ MultW @Float
400+
, TestableFn $ MultW @Integer
401+
-- These are representative of the bounded types
400402
, TestableFn $ MultW @Word8
403+
, TestableFn $ MultW @Int8
404+
, TestableFn $ MultW @Float
405+
, TestableFn $ MultW @Double
401406
, TestableFn $ SizeOfW @(Map Int Int)
402407
, -- data BaseW
403408
TestableFn $ EqualW @Int

0 commit comments

Comments
 (0)