The strategy stores the current state of the model and it knows, by using the model
program, which actions are currently enabled, that is, which actions are enabled in
the current state. The strategy can use additional state to record history, for example,
previously taken actions, in order to implement a particular algorithm for selecting
the next action to be executed.
12.3.1 Default strategy
A default or basic strategy for a given model program is provided by the Strategy
class. The basic strategy has no additional tester state, it implements a so-called
memoryless action selection strategy; a call to SelectAction computes, in the current
state, the set of all enabled actions with the given action symbols and returns a
randomly chosen action from among those, or null if the set is empty.
We can use the conformance tester ct to run the restricted bag model program
against the bag stepper. As it happens, the very first test fails with a trace consisting
of a single action Lookup Start(null) with a failure reason that null cannot be a
key in the dictionary that is used to implement the bag. We can fix that bug easily
by counting null values separately and not trying to insert null or to look it up in
the dictionary. For now let us assume that the set of parameters is restricted to ""
and "b"; that is, we change the definition of E in Figure 12.3 to
readonly static Set
E = new Set("","b");
Systems with Complex State 203
After a couple of executions of ct we get another failure trace:
TestResult(2, Verdict("Failure"),
"Action ??™Count_Finish(1)??™ not enabled in the model
Unexpected return value of finish action, expected: Count_Finish(2)
Unexpected finish action",
Trace(
Count_Start(),
Count_Finish(0),
Delete(""),
Add(""),
Add("b"),
Add(""),
Delete("b"),
Delete("b"),
Count_Start(),
Count_Finish(1)
)
)
Here the error is that the last call to Count returns 1 instead of 2.
Pages:
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274