Skip to content

Commit 9d79eaf

Browse files
fucking bullshit
1 parent 8788d28 commit 9d79eaf

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/Constrained/NumOrd.hs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,13 +730,38 @@ instance {-# OVERLAPPABLE #-} (HasSpec a, Integral a, TypeSpec a ~ NumSpec a) =>
730730
doDivide = div
731731

732732
divideSpec 0 _ = TrueSpec
733-
divideSpec a (NumSpecInterval ml mu) = typeSpec $ NumSpecInterval (((`div`a) . (+1)) <$> ml) ((`div`a) <$> mu)
733+
-- TODO This is all wrong and hence the tests are all wrong
734+
divideSpec a (NumSpecInterval ml mu) = typeSpec ts
735+
where
736+
ts | a > 0 = NumSpecInterval ml' mu'
737+
| otherwise = NumSpecInterval mu' ml'
738+
ml' = adjustLowerBound <$> ml
739+
mu' = adjustUpperBound <$> mu
740+
adjustLowerBound l =
741+
let r = l `div` a in
742+
if r * a < l
743+
then r + 1
744+
else r
745+
746+
adjustUpperBound u =
747+
let r = u `div` a in
748+
if r * a > u
749+
then r - 1
750+
else r
734751

735752
instance HasDivision Float where
736753
doDivide = (/)
737754

738755
divideSpec 0 _ = TrueSpec
739-
divideSpec a (NumSpecInterval ml mu) = typeSpec $ NumSpecInterval ((/a) <$> ml) ((/a) <$> mu)
756+
divideSpec a (NumSpecInterval ml mu) = typeSpec ts
757+
where
758+
ts | a > 0 = NumSpecInterval ml' mu'
759+
| otherwise = NumSpecInterval mu' ml'
760+
ml' = adjustLowerBound <$> ml
761+
mu' = adjustUpperBound <$> mu
762+
adjustLowerBound l = l / a
763+
764+
adjustUpperBound u = u / a
740765

741766
instance HasDivision Double where
742767
doDivide = (/)

src/Constrained/Test.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ instance (HasSpec a, Arbitrary (TypeSpec a)) => Arbitrary (Specification a) wher
326326
, (10, pure baseSpec)
327327
]
328328

329+
shrink (TypeSpec ts cant) = flip TypeSpec cant <$> shrink ts
330+
shrink (ExplainSpec _ s) = [s]
331+
shrink _ = []
332+
329333
instance
330334
( Arbitrary a
331335
, Arbitrary (FoldSpec a)

0 commit comments

Comments
 (0)