@@ -188,6 +188,30 @@ prop_containsEnforcesPositivity v
188188 (BuiltinFailure {}, BuiltinFailure {}) -> property True
189189 _ -> property False
190190
191+ scaleCorrectlyBound :: Integer -> Value -> Bool
192+ scaleCorrectlyBound factor val =
193+ any
194+ (\ (_, _, V. unQuantity -> q) -> isNothing $ V. quantity $ q * factor)
195+ $ V. toFlatList val
196+
197+ prop_scaleBookKeeping :: Integer -> Value -> Property
198+ prop_scaleBookKeeping factor v =
199+ case V. scaleValue factor v of
200+ BuiltinSuccess r -> checkBookkeeping r
201+ _ -> property $ scaleCorrectlyBound factor v
202+
203+ prop_scaleByOneIsId :: Value -> Property
204+ prop_scaleByOneIsId v =
205+ property $ case V. scaleValue 1 v of
206+ BuiltinSuccess r -> r == v
207+ _ -> scaleCorrectlyBound 1 v
208+
209+ prop_negateInvolutive :: Value -> Property
210+ prop_negateInvolutive v =
211+ property $ case V. scaleValue (- 1 ) v >>= V. scaleValue (- 1 ) of
212+ BuiltinSuccess r -> r == v
213+ _ -> scaleCorrectlyBound (- 1 ) v
214+
191215prop_negateIsInverse :: Value -> Property
192216prop_negateIsInverse v =
193217 let
@@ -196,22 +220,18 @@ prop_negateIsInverse v =
196220 V. unionValue v vInv
197221 in property $ case inverseUnion of
198222 BuiltinSuccess r -> r == V. empty
199- _ -> False
223+ _ -> scaleCorrectlyBound ( - 1 ) v
200224
201225prop_oppositeScaleIsInverse :: Integer -> Value -> Property
202226prop_oppositeScaleIsInverse c v =
203227 let
204- inverseUnion = do
228+ scaledValue = do
205229 vInv <- V. scaleValue (negate c) v
206230 v' <- V. scaleValue c v
207231 V. unionValue v' vInv
208- correctlyBound =
209- any
210- (\ (_, _, V. unQuantity -> q) -> isNothing $ V. quantity $ q * c)
211- $ V. toFlatList v
212- in property $ case inverseUnion of
232+ in property $ case scaledValue of
213233 BuiltinSuccess r -> r == V. empty
214- _ -> correctlyBound
234+ _ -> scaleCorrectlyBound c v
215235
216236prop_flatRoundtrip :: Value -> Property
217237prop_flatRoundtrip v = Flat. unflat (Flat. flat v) === Right v
@@ -447,6 +467,18 @@ tests =
447467 , testProperty
448468 " unionValueDetectsOverflow"
449469 prop_unionValueDetectsOverflow
470+ , testProperty
471+ " scaleBookKeeping"
472+ prop_scaleBookKeeping
473+ , testProperty
474+ " scaleByOneIsId"
475+ prop_scaleByOneIsId
476+ , testProperty
477+ " scaleByOneIsId"
478+ prop_scaleByOneIsId
479+ , testProperty
480+ " negateInvolutive"
481+ prop_negateInvolutive
450482 , testProperty
451483 " negateIsInverse"
452484 prop_negateIsInverse
0 commit comments