I propose the interdiff: diff --git a/test/hs/Test/Ganeti/Objects.hs b/test/hs/Test/Ganeti/Objects.hs index f3c224f..9d3b633 100644 --- a/test/hs/Test/Ganeti/Objects.hs +++ b/test/hs/Test/Ganeti/Objects.hs @@ -50,6 +50,7 @@ import qualified Data.List as List import qualified Data.Map as Map import Data.Maybe (fromMaybe) import qualified Data.Set as Set +import Data.Word (Word32) import GHC.Exts (IsString(..)) import System.Time (ClockTime(..)) import qualified Text.JSON as J @@ -527,10 +528,15 @@ prop_ip4AddressAsNum :: Ip4Address -> Property prop_ip4AddressAsNum ip4 = ip4AddressFromNumber (ip4AddressToNumber ip4) ==? ip4
--- | Tests that any difference between IPv4 consecutive addresses is 1. -prop_ip4AddressFromNumber :: Property -prop_ip4AddressFromNumber = - ip4AddressToNumber <$> readIp4Address "1.2.3.4" ==? Just 0x01020304 +-- | Tests that the number produced by 'ip4AddressToNumber' has the correct +-- order of bytes. +prop_ip4AddressToNumber :: Word32 -> Property +prop_ip4AddressToNumber w = + let byte :: Int -> Word32 + byte i = (w `div` (256^i)) `mod` 256 + ipaddr = List.intercalate "." $ map (show . byte) [3,2..0] + in ip4AddressToNumber <$> readIp4Address ipaddr + ==? (return (toInteger w) :: Either String Integer) -- | IsString instance for 'Ip4Address', to help write the tests. instance IsString Ip4Address where On Fri, Jul 4, 2014 at 2:58 PM, Klaus Aehlig <[email protected]> wrote: > On Fri, Jul 04, 2014 at 02:44:23PM +0200, Petr Pudlák wrote: > > Ack. > > > > The point of the test is to test the correct order of the conversion > > (0x01020304 vs 0x04030201). > > Ah, I see. > > > I could make it more general by testnig on arbitrary Word32 numbers. > > Yes, I think that would make more sense. > > Thanks, > Klaus > > -- > Klaus Aehlig > Google Germany GmbH, Dienerstr. 12, 80331 Muenchen > Registergericht und -nummer: Hamburg, HRB 86891 > Sitz der Gesellschaft: Hamburg > Geschaeftsfuehrer: Graham Law, Christine Elizabeth Flores >
