diff --git a/Ganeti/HTools/QC.hs b/Ganeti/HTools/QC.hs index 8944a74a9c2d3e3b82087558aefb04b9cb31604c..57f56c04dbea9db8bc7afe5e582b3c612900f31f 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 ad8f15bceb1e6c9acb632cb34344b1fb9c528658..0d585b693cc61348321d84eb63f3cfffae524075 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 8ae8fa59df7f137e9cf245e5dc3c00756f6d175c..12aa50da52995cbcee49d333a85717e45e74cdec 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)