From b2186bdae2d4d3c95559099fef1a8320bb9ea4a8 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 f4302c6394a..ecfeaf486f0 100644 --- a/lib/core/test/unit/Cardano/Wallet/Primitive/Migration/PlanningSpec.hs +++ b/lib/core/test/unit/Cardano/Wallet/Primitive/Migration/PlanningSpec.hs @@ -71,10 +71,10 @@ import Test.QuickCheck , choose , counterexample , cover - , label , oneof , property , shrinkList + , tabulate , withMaxSuccess , (===) ) @@ -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" @@ -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) @@ -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) @@ -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 @@ -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