Skip to content

Commit

Permalink
Use tabulate instead of label in prop_createPlan.
Browse files Browse the repository at this point in the history
This produces a clearer statistical summary.

In addition, this commit replaces "percentage not selected" with
"percentage selected", which is arguably easier to interpret.

In response to review feedback:

#2618 (comment)
  • Loading branch information
jonathanknowles committed Apr 20, 2021
1 parent c3651da commit b2186bd
Showing 1 changed file with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ import Test.QuickCheck
, choose
, counterexample
, cover
, label
, oneof
, property
, shrinkList
, tabulate
, withMaxSuccess
, (===)
)
Expand Down Expand Up @@ -180,13 +180,18 @@ genArgsForCreatePlan (inputCountMin, inputCountMax) genInput = do

prop_createPlan :: ArgsForCreatePlan -> Property
prop_createPlan mockArgs =
label labelTransactionCount $
label labelMeanTransactionInputCount $
label labelMeanTransactionOutputCount $
label (labelNotSelectedPercentage "freeriders" freeriders) $
label (labelNotSelectedPercentage "supporters" supporters) $
label (labelNotSelectedPercentage "ignorables" ignorables) $

tabulate "Number of transactions required"
[transactionCount] $
tabulate "Mean number of inputs per transaction"
[meanTransactionInputCount] $
tabulate "Mean number of outputs per transaction"
[meanTransactionOutputCount] $
tabulate "Percentage of supporters selected"
[percentageSelected supporters] $
tabulate "Percentage of freeriders selected"
[percentageSelected freeriders] $
tabulate "Percentage of ignorables selected"
[percentageSelected ignorables] $
counterexample counterexampleText $
conjoinMap
[ ( "inputs are not preserved"
Expand All @@ -201,8 +206,8 @@ prop_createPlan mockArgs =
, null (supporters (unselected result)) )
]
where
labelTransactionCount = pretty $ mconcat
[ "number of transactions required: ["
transactionCount = pretty $ mconcat
[ "["
, padLeftF 3 '0' (10 * selectionCountDiv10)
, ""
, padLeftF 3 '0' (10 * (selectionCountDiv10 + 1) - 1)
Expand All @@ -211,8 +216,8 @@ prop_createPlan mockArgs =
where
selectionCountDiv10 = selectionCount `div` 10

labelMeanTransactionInputCount = pretty $ mconcat
[ "mean number of inputs per transaction: ["
meanTransactionInputCount = pretty $ mconcat
[ "["
, padLeftF 3 '0' (10 * meanTxInputCountDiv10)
, ""
, padLeftF 3 '0' (10 * (meanTxInputCountDiv10 + 1) - 1)
Expand All @@ -230,10 +235,8 @@ prop_createPlan mockArgs =
totalSelectedInputCount =
L.sum $ L.length . view #inputIds <$> selections result

labelMeanTransactionOutputCount = pretty $ mconcat
[ "mean number of outputs per transaction: "
, padLeftF 3 '0' meanTxOutputCount
]
meanTransactionOutputCount = pretty $
padLeftF 3 ' ' meanTxOutputCount
where
meanTxOutputCount :: Int
meanTxOutputCount
Expand All @@ -245,20 +248,15 @@ prop_createPlan mockArgs =
totalSelectedOutputCount =
L.sum $ L.length . view #outputs <$> selections result

labelNotSelectedPercentage categoryName category = pretty $ mconcat
[ categoryName
, " not selected: "
, maybe
("no entries available")
(\p -> padLeftF 3 '0' p <> "%")
(percentage)
]
percentageSelected category = pretty $
padLeftF 3 ' ' percentage <> "%"
where
percentage :: Int
percentage
| entriesAvailable == 0 =
Nothing
100
| otherwise =
Just $ (entriesNotSelected * 100) `div` entriesAvailable
100 - ((entriesNotSelected * 100) `div` entriesAvailable)

entriesAvailable :: Int
entriesAvailable = length $ category categorizedUTxO
Expand Down

0 comments on commit b2186bd

Please sign in to comment.