Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add property test checking for 'parseNetworkParameters'
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,5 +138,6 @@ tests: | |
- relude | ||
- shelley-spec-ledger | ||
- shelley-spec-ledger-test | ||
- time | ||
build-tools: | ||
- hspec-discover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
-- file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
module Ogmios.App.OptionsSpec | ||
( spec | ||
) where | ||
|
||
import Ogmios.Prelude | ||
|
||
import Ogmios.App.Options | ||
( EpochSlots (..) | ||
, NetworkMagic (..) | ||
, NetworkParameters (..) | ||
, SystemStart (..) | ||
, parseNetworkParameters | ||
) | ||
|
||
import Data.Time.Clock.POSIX | ||
( posixSecondsToUTCTime ) | ||
import Test.Hspec | ||
( Spec, context, parallel ) | ||
import Test.Hspec.QuickCheck | ||
( prop ) | ||
import Test.QuickCheck | ||
( Arbitrary (..), Gen, Property, choose, conjoin, forAll, property, (===) ) | ||
|
||
spec :: Spec | ||
spec = parallel $ do | ||
context "parseNetworkParameters" $ do | ||
prop | ||
"Parse any combination of colon separated naturals" | ||
prop_anyParseNetworkParameters | ||
|
||
prop_anyParseNetworkParameters :: Property | ||
prop_anyParseNetworkParameters = | ||
forAll genRawParameters $ \(a,b,c) -> do | ||
case parseNetworkParameters (intercalate ":" [show a, show b, show c]) of | ||
Nothing -> | ||
property False | ||
Just params -> conjoin | ||
[ networkMagic params === NetworkMagic a | ||
, systemStart params === mkSystemStart b | ||
, slotsPerEpoch params === EpochSlots c | ||
] | ||
where | ||
mkSystemStart :: Int -> SystemStart | ||
mkSystemStart = | ||
SystemStart . posixSecondsToUTCTime . toPicoResolution . toEnum | ||
where | ||
toPicoResolution = (*1000000000000) | ||
|
||
genRawParameters :: Gen (Word32, Int, Word64) | ||
genRawParameters = (,,) | ||
<$> arbitrary | ||
<*> choose (0, fromIntegral (maxBound :: Word32)) | ||
<*> choose (0, 100000) |