Skip to content

Commit

Permalink
Use fewer type conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Aug 10, 2020
1 parent 65c48bc commit e03d29f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Expand Up @@ -255,9 +255,8 @@ propDeterministic
-> Property
propDeterministic (CoinSelProp utxo wdrl txOuts) = do
let opts = CoinSelectionOptions (const 100) noValidation
let wdrl' = Quantity wdrl
let resultOne = runIdentity $ runExceptT $ largestFirst opts txOuts wdrl' utxo
let resultTwo = runIdentity $ runExceptT $ largestFirst opts txOuts wdrl' utxo
let resultOne = runIdentity $ runExceptT $ largestFirst opts txOuts wdrl utxo
let resultTwo = runIdentity $ runExceptT $ largestFirst opts txOuts wdrl utxo
resultOne === resultTwo

propAtLeast
Expand All @@ -270,7 +269,7 @@ propAtLeast (CoinSelProp utxo wdrl txOuts) =
L.length (inputs cs) `shouldSatisfy` (>= NE.length txOuts)
selection = runIdentity $ runExceptT $ do
let opts = CoinSelectionOptions (const 100) noValidation
largestFirst opts txOuts (Quantity wdrl) utxo
largestFirst opts txOuts wdrl utxo

propInputDecreasingOrder
:: CoinSelProp
Expand All @@ -289,4 +288,4 @@ propInputDecreasingOrder (CoinSelProp utxo wdrl txOuts) =
getExtremumValue f = f . map (getCoin . coin . snd)
selection = runIdentity $ runExceptT $ do
let opts = CoinSelectionOptions (const 100) noValidation
largestFirst opts txOuts (Quantity wdrl) utxo
largestFirst opts txOuts wdrl utxo
Expand Up @@ -357,7 +357,7 @@ propFragmentation drg (CoinSelProp utxo wdrl txOuts) = do
(selection1,_) = withDRG drg
(runExceptT $ random opt txOuts (Quantity 0) utxo)
selection2 = runIdentity $ runExceptT $
largestFirst opt txOuts (Quantity wdrl) utxo
largestFirst opt txOuts wdrl utxo
opt = CoinSelectionOptions (const 100) noValidation

propErrors
Expand All @@ -372,7 +372,7 @@ propErrors drg (CoinSelProp utxo wdrl txOuts) = do
prop (err1, err2) =
err1 === err2
(selection1,_) = withDRG drg
(runExceptT $ random opt txOuts (Quantity wdrl) utxo)
(runExceptT $ random opt txOuts wdrl utxo)
selection2 = runIdentity $ runExceptT $
largestFirst opt txOuts (Quantity wdrl) utxo
largestFirst opt txOuts wdrl utxo
opt = (CoinSelectionOptions (const 1) noValidation)
Expand Up @@ -230,7 +230,7 @@ data CoinSelectionsSetup = CoinSelectionsSetup
data CoinSelProp = CoinSelProp
{ csUtxO :: UTxO
-- ^ Available UTxO for the selection
, csWithdrawal :: Word64
, csWithdrawal :: Quantity "lovelace" Word64
-- ^ Availible Withdrawal
, csOuts :: NonEmpty TxOut
-- ^ Requested outputs for the payment
Expand Down Expand Up @@ -347,11 +347,13 @@ instance Arbitrary a => Arbitrary (NonEmpty a) where
instance Arbitrary CoinSelProp where
shrink (CoinSelProp utxo wdrl outs) =
[ CoinSelProp utxo' wdrl outs | utxo' <- shrink utxo ]
++ [ CoinSelProp utxo wdrl' outs | wdrl' <- shrink wdrl ]
++ [ CoinSelProp utxo wdrl' outs | wdrl' <- shrinkWdrl wdrl ]
++ [ CoinSelProp utxo wdrl outs' | outs' <- shrink outs ]
where
shrinkWdrl = map Quantity . shrink . getQuantity
arbitrary = do
utxo <- arbitrary
wdrl <- frequency [(65, return 0), (35, arbitrary)]
wdrl <- Quantity <$> frequency [(65, return 0), (35, arbitrary)]
outs <- arbitrary
return $ CoinSelProp utxo wdrl outs

Expand Down

0 comments on commit e03d29f

Please sign in to comment.