Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't shrink the action chosen in state machine testing #415

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions hedgehog/src/Hedgehog/Internal/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ module Hedgehog.Internal.Gen (
-- ** Choice
, constant
, element
, element_
, choice
, frequency
, recursive
Expand Down Expand Up @@ -1186,6 +1187,20 @@ element = \case
n <- integral $ Range.constant 0 (length xs - 1)
pure $ xs !! n

-- | Randomly selects one of the elements in the list.
--
-- This generator does not shrink the choice of element.
--
-- /The input list must be non-empty./
--
element_ :: MonadGen m => [a] -> m a
element_ = \case
[] ->
error "Hedgehog.Gen.element: used with empty list"
xs -> do
n <- integral_ $ Range.constant 0 (length xs - 1)
pure $ xs !! n

-- | Randomly selects one of the generators in the list.
--
-- This generator shrinks towards the first generator in the list.
Expand Down
4 changes: 2 additions & 2 deletions hedgehog/src/Hedgehog/Internal/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ action commands =
Context state0 _ <- get

Command mgenInput exec callbacks <-
Gen.element $ filter (\c -> commandGenOK c state0) commands
Gen.element_ $ filter (\c -> commandGenOK c state0) commands

input <-
case mgenInput state0 of
Expand Down Expand Up @@ -579,7 +579,7 @@ genActions range commands ctx = do

-- | A sequence of actions to execute.
--
data Sequential m state =
newtype Sequential m state =
Sequential {
-- | The sequence of actions.
sequentialActions :: [Action m state]
Expand Down