Skip to content
Permalink
Browse files

test-consensus: replace suchThat with a binary search

  • Loading branch information
nfrisby committed Dec 3, 2019
1 parent f0bcbf7 commit ccf0ef081e0a5db036af5d1d969bedf9f4a54bf1

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

@@ -306,6 +306,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
@@ -255,10 +256,20 @@ genRealPBFTNodeJoinPlan params numSlots@(NumSlots t)
-- *always* suffice?)
let check s' =
Ref.viable params lastSlot
(NodeJoinPlan (Map.insert nid s' m))
(NodeJoinPlan (Map.insert nid (SlotNo 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 instead search to find the first slot
-- that is /not/ /viable/ and then decrement it to find the
-- latest slot that is /viable/
s' <- case searchFromTo (not . check) (unSlotNo lo) (unSlotNo lastSlot) of
Nothing -> genSlot lo lastSlot
Just succHi
| SlotNo succHi > lo -> genSlot lo $ SlotNo $ pred succHi
| otherwise -> error $
"Cannot find viable RealPBFT NodeJoinPlan: " ++
show (SlotNo succHi, 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 ccf0ef0

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