[Pkg-ganeti-devel] [ganeti] 49/165: Add a correctness test for diffClockTimes

Apollon Oikonomopoulos apoikos at moszumanska.debian.org
Tue Aug 11 13:53:12 UTC 2015


This is an automated email from the git hooks/post-receive script.

apoikos pushed a commit to branch master
in repository ganeti.

commit 9625da280b597e1114509022311815d9cdd6b839
Author: Klaus Aehlig <aehlig at google.com>
Date:   Thu Feb 19 14:30:16 2015 +0100

    Add a correctness test for diffClockTimes
    
    ...verifying that adding a time difference, followed
    by adding its inverse has no effect. In particular, we
    expect the addToClockTime not to throw an exception.
    
    Signed-off-by: Klaus Aehlig <aehlig at google.com>
    Reviewed-by: Helga Velroyen <helgav at google.com>
---
 test/hs/Test/Ganeti/Utils.hs | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/test/hs/Test/Ganeti/Utils.hs b/test/hs/Test/Ganeti/Utils.hs
index afcf4a9..af1c5b6 100644
--- a/test/hs/Test/Ganeti/Utils.hs
+++ b/test/hs/Test/Ganeti/Utils.hs
@@ -40,6 +40,7 @@ module Test.Ganeti.Utils (testUtils) where
 import Test.QuickCheck hiding (Result)
 import Test.HUnit
 
+import Control.Applicative ((<$>), (<*>))
 import Data.Char (isSpace)
 import qualified Data.Either as Either
 import Data.List
@@ -283,6 +284,17 @@ prop_clockTimeToString :: Integer -> Integer -> Property
 prop_clockTimeToString ts pico =
   clockTimeToString (TOD ts pico) ==? show ts
 
+instance Arbitrary ClockTime where
+  arbitrary = TOD <$> choose (946681200, 2082754800) <*> choose (0, 99999999999)
+
+-- | Verify our work-around for ghc bug #2519. Taking `diffClockTimes` form
+-- `System.Time`, this test fails with an exception.
+prop_timediffAdd :: ClockTime -> ClockTime -> ClockTime -> Property
+prop_timediffAdd a b c =
+  let fwd = Ganeti.Utils.diffClockTimes a b
+      back = Ganeti.Utils.diffClockTimes b a
+  in addToClockTime fwd (addToClockTime back c) ==? c
+
 -- | Test normal operation for 'chompPrefix'.
 --
 -- Any random prefix of a string must be stripped correctly, including the empty
@@ -394,6 +406,7 @@ testSuite "Utils"
             , 'case_new_uuid_regex
 #endif
             , 'prop_clockTimeToString
+            , 'prop_timediffAdd
             , 'prop_chompPrefix_normal
             , 'prop_chompPrefix_last
             , 'prop_chompPrefix_empty_string

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ganeti/ganeti.git



More information about the Pkg-ganeti-devel mailing list