Skip to content

Commit

Permalink
Merge pull request #392 from tzemanovic/tomas/sm-transition-delete
Browse files Browse the repository at this point in the history
state-machine: don't limit number of transitions that can be deleted in shrinking
  • Loading branch information
tzemanovic authored Nov 22, 2023
2 parents 63ef67c + 4471dbc commit dfaa77a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
1 change: 1 addition & 0 deletions proptest-state-machine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

### Bug Fixes

- Removed the limit of number of transitions that can be deleted in shrinking that depended on the number the of transitions given to `prop_state_machine!` or `ReferenceStateMachine::sequential_strategy`.
- Fixed state-machine macro's inability to handle missing config
- Fixed logging of state machine transitions to be enabled when verbose config is >= 1. The "std" feature is added to proptest-state-machine as a default feature that allows to switch the logging off in non-std env.
48 changes: 20 additions & 28 deletions proptest-state-machine/src/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub trait ReferenceStateMachine {
/// `Shrink::DeleteTransition` and `Shrink::Transition`.
///
/// 1. We start by trying to delete transitions from the back of the list, until
/// we can do so no further (the list has reached the `min_size`).
/// we can do so no further (reached the beginning of the list).
/// We start from the back, because it's less likely to affect the state
/// machine's pre-conditions, if any.
/// 2. Then, we again iteratively attempt to shrink the individual transitions,
Expand Down Expand Up @@ -209,7 +209,6 @@ impl<
acceptable_transitions,
included_transitions,
shrinkable_transitions,
min_size,
max_ix,
// On a failure, we start by shrinking transitions from the back
// which is less likely to invalidate pre-conditions
Expand Down Expand Up @@ -271,8 +270,6 @@ pub struct SequentialValueTree<
included_transitions: VarBitSet,
/// The bit-set of transitions that can be shrunk further
shrinkable_transitions: VarBitSet,
/// The minimum number of `transitions`
min_size: usize,
/// The maximum index in the `transitions` vector (its size - 1)
max_ix: usize,
/// The next shrink operation to apply
Expand All @@ -293,32 +290,27 @@ impl<
/// applied.
fn try_simplify(&mut self) -> bool {
if let DeleteTransition(ix) = self.shrink {
if self.included_transitions.count() == self.min_size {
// Can't delete any more transitions, move on to shrinking them
self.shrink = Transition(0);
} else {
// Delete the index from the included transitions
self.included_transitions.clear(ix);
// Delete the index from the included transitions
self.included_transitions.clear(ix);

self.last_shrink = Some(self.shrink);
self.shrink = if ix == 0 {
// Reached the beginning of the list, move on to shrinking
Transition(0)
} else {
// Try to delete the previous transition next
DeleteTransition(ix - 1)
};
// If this delete is not acceptable, undo it and try again
if !self.check_acceptable(None) {
self.included_transitions.set(ix);
self.last_shrink = None;
return self.try_simplify();
}
// If the delete was accepted, remove this index from shrinkable
// transitions
self.shrinkable_transitions.clear(ix);
return true;
self.last_shrink = Some(self.shrink);
self.shrink = if ix == 0 {
// Reached the beginning of the list, move on to shrinking
Transition(0)
} else {
// Try to delete the previous transition next
DeleteTransition(ix - 1)
};
// If this delete is not acceptable, undo it and try again
if !self.check_acceptable(None) {
self.included_transitions.set(ix);
self.last_shrink = None;
return self.try_simplify();
}
// If the delete was accepted, remove this index from shrinkable
// transitions
self.shrinkable_transitions.clear(ix);
return true;
}

while let Transition(ix) = self.shrink {
Expand Down

0 comments on commit dfaa77a

Please sign in to comment.