From 691dcd2a5db503a89abb50a38f29c3cfef890a2b Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 21 Jul 2010 23:03:28 -0400 Subject: [PATCH] Remove an obsolete function and add Utils tests --- Ganeti/HTools/QC.hs | 18 +++++++++++++++++- Ganeti/HTools/Utils.hs | 5 ----- test.hs | 3 ++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Ganeti/HTools/QC.hs b/Ganeti/HTools/QC.hs index 8944a74a9..57f56c04d 100644 --- a/Ganeti/HTools/QC.hs +++ b/Ganeti/HTools/QC.hs @@ -24,7 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -} module Ganeti.HTools.QC - ( testPeerMap + ( testUtils + , testPeerMap , testContainer , testInstance , testNode @@ -192,6 +193,21 @@ instance Arbitrary Jobs.JobStatus where -- * Actual tests +-- | Test utils separator/joiner functions + +-- If the list is not just an empty element, and if the elements do +-- not contain commas, then join+split should be idepotent +prop_Utils_commaJoinSplit lst = lst /= [""] && + all (not . elem ',') lst ==> + Utils.sepSplit ',' (Utils.commaJoin lst) == lst +-- Split and join should always be idempotent +prop_Utils_commaSplitJoin s = Utils.commaJoin (Utils.sepSplit ',' s) == s + +testUtils = + [ run prop_Utils_commaJoinSplit + , run prop_Utils_commaSplitJoin + ] + -- | Make sure add is idempotent prop_PeerMap_addIdempotent pmap key em = fn puniq == fn (fn puniq) diff --git a/Ganeti/HTools/Utils.hs b/Ganeti/HTools/Utils.hs index ad8f15bce..0d585b693 100644 --- a/Ganeti/HTools/Utils.hs +++ b/Ganeti/HTools/Utils.hs @@ -25,7 +25,6 @@ module Ganeti.HTools.Utils ( debug , sepSplit - , fst3 , varianceCoeff , commaJoin , readEitherString @@ -73,10 +72,6 @@ sepSplit sep s where (x, xs) = break (== sep) s ys = drop 1 xs --- | Simple version of 'fst' for a triple -fst3 :: (a, b, c) -> a -fst3 (a, _, _) = a - -- * Mathematical functions -- Simple and slow statistical functions, please replace with better diff --git a/test.hs b/test.hs index 8ae8fa59d..12aa50da5 100644 --- a/test.hs +++ b/test.hs @@ -64,7 +64,8 @@ wrapTest ir t to = do allTests :: [(String, TestOptions, [TestOptions -> IO TestResult])] allTests = - [ ("PeerMap", fast, testPeerMap) + [ ("Utils", fast, testUtils) + , ("PeerMap", fast, testPeerMap) , ("Container", fast, testContainer) , ("Instance", fast, testInstance) , ("Node", fast, testNode) -- GitLab