From 468b828ebd40725ad5e656aac115dc5db3101a9e Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Mon, 16 Jan 2012 00:48:11 +0100 Subject: [PATCH] Another small optimisation in test data generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It seems that QuickCheck will happily generate huge data structures, if that's what one requests. For this test, where we ask for [[Char]], it could happen that we get a huge number of chars, so let's limit them to some (arbitrary, but low) limits. This doesn't "ruin" the test, since the implementation of sepSplit/commaJoin is not size-based. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: RenΓ© Nussbaumer <rn@google.com> --- htools/Ganeti/HTools/QC.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs index e2c005974..6ad6b881b 100644 --- a/htools/Ganeti/HTools/QC.hs +++ b/htools/Ganeti/HTools/QC.hs @@ -449,11 +449,16 @@ instance Arbitrary Types.IPolicy where -- ** Utils tests +-- | Helper to generate a small string that doesn't contain commas. +genNonCommaString = do + size <- choose (0, 20) -- arbitrary max size + vectorOf size (arbitrary `suchThat` ((/=) ',')) + -- | If the list is not just an empty element, and if the elements do -- not contain commas, then join+split should be idempotent. prop_Utils_commaJoinSplit = - forAll (arbitrary `suchThat` - (\l -> l /= [""] && all (notElem ',') l )) $ \lst -> + forAll (choose (0, 20)) $ \llen -> + forAll (vectorOf llen genNonCommaString `suchThat` ((/=) [""])) $ \lst -> Utils.sepSplit ',' (Utils.commaJoin lst) ==? lst -- | Split and join should always be idempotent. -- GitLab