From 47377b082a9ca3cfc6bba50f44e04bd3f899dd4d Mon Sep 17 00:00:00 2001 From: Jonathan Knowles Date: Tue, 20 Apr 2021 06:08:07 +0000 Subject: [PATCH] Use `tabulate` instead of `label` in `prop_createPlan`. 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: https://github.com/input-output-hk/cardano-wallet/pull/2618#issuecomment-822413404 --- .../Primitive/Migration/PlanningSpec.hs | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/lib/core/test/unit/Cardano/Wallet/Primitive/Migration/PlanningSpec.hs b/lib/core/test/unit/Cardano/Wallet/Primitive/Migration/PlanningSpec.hs index b8cb53db0dd..9ee0d1142d2 100644 --- a/lib/core/test/unit/Cardano/Wallet/Primitive/Migration/PlanningSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/Primitive/Migration/PlanningSpec.hs @@ -70,10 +70,10 @@ import Test.QuickCheck , choose , counterexample , cover - , label , oneof , property , shrinkList + , tabulate , withMaxSuccess , (===) ) @@ -179,13 +179,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" @@ -200,8 +205,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) @@ -210,8 +215,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) @@ -229,10 +234,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 @@ -244,20 +247,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