Skip to content

Commit

Permalink
Update state-machine.md
Browse files Browse the repository at this point in the history
fix a typo
  • Loading branch information
skaunov authored Jan 27, 2025
1 parent b844446 commit 2661602
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion book/src/proptest/state-machine.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ You also have to implement three associated functions:
fn transitions(state: &Self::State) -> BoxedStrategy<Self::Transition>
```

Most of the time, you'll use `prop_oneof!` here. If a transition takes some input parameters, you can generate those with a `Strategy` and `.prop_map` it to the `Transition` variant. In more complex state machines, the set of valid transitions may depend on the current state. To that end, you can use the `state` argument, possibly combined with `prop::sample::select` function that allows you to create a strategy that selects a random value from an array or an array-like collection (be careful not to call `select` on an empty array as that will make it fail in a somewhat obscure way). For example, if you want to remove one of the existing keys from a hash map, you can select one of the keys from the current state and map it into a transition. Note that when you do something like this, you'll also need to override the `fn preconditions`, which are explained in more detail below.
Most of the time, you'll use `prop_oneof!` here. If a transition takes some input parameters, you can generate those with a `Strategy` and `.prop_map` it to the `Transition` variant. In more complex state machines, the set of valid transitions may depend on the current state. To that end, you can use the `state` argument, possibly combined with `proptest::sample::select` function that allows you to create a strategy that selects a random value from an array or an array-like collection (be careful not to call `select` on an empty array as that will make it fail in a somewhat obscure way). For example, if you want to remove one of the existing keys from a hash map, you can select one of the keys from the current state and map it into a transition. Note that when you do something like this, you'll also need to override the `fn preconditions`, which are explained in more detail below.

- To apply the given transition on the reference state:

Expand Down

0 comments on commit 2661602

Please sign in to comment.