Skip to content
Permalink
Browse files

test-consensus: replace suchThat with a binary search

  • Loading branch information
nfrisby committed Dec 3, 2019
1 parent 1191866 commit b6a47f61a3402c096472a80c2dc164f522418cf3

Some generated files are not rendered by default. Learn more.

@@ -308,6 +308,7 @@ test-suite test-consensus
io-sim-classes,
io-sim,

binary-search,
cborg,
containers,
contra-tracer,
@@ -15,6 +15,7 @@ import qualified Data.Map.Strict as Map
import Data.Maybe (fromJust)
import Data.Time (Day (..), UTCTime (..))

import Numeric.Search.Range (searchFromTo)
import Test.QuickCheck
import Test.Tasty
import Test.Tasty.QuickCheck
@@ -257,8 +258,17 @@ genRealPBFTNodeJoinPlan params numSlots@(NumSlots t)
Ref.viable params lastSlot
(NodeJoinPlan (Map.insert nid s' m))
st
s' <- genSlot (Ref.nextSlot st) lastSlot
`suchThat` check
lo = Ref.nextSlot st

-- @check@ is downward-closed, but 'searchFromTo' requires
-- upward-closed, so we search in dualized range
inn = (maxBound -) . unSlotNo
out = SlotNo . (maxBound -)
s' <- case out <$> searchFromTo (check . out) (inn lastSlot) (inn lo) of
Just hi -> genSlot lo hi
Nothing -> error $
"Cannot find viable RealPBFT NodeJoinPlan: " ++
show (nodeJoinPlan, st)

let m' = Map.insert nid s' m

@@ -83,8 +83,10 @@ data State = State
, outs :: !(Seq Outcome)
-- ^ the outcome of each the last @2k@ slots
}
deriving (Eq, Show)

newtype NumNominals = NumNominals Int
deriving (Eq, Ord, Show)

emptyState :: State
emptyState = State Seq.empty (NumNominals 0) 0 Seq.empty

0 comments on commit b6a47f6

Please sign in to comment.
You can’t perform that action at this time.