Attributes;
namespace BagModel
{
[Feature]
static class ElementRestriction
{
readonly static Set
E = new Set(null,"","b");
[Action]
static void Add([Domain("E")]string e)\verb+{}+
[Action]
static void Delete([Domain("E")]string e)\verb+{}+
[Action]
static void Lookup_Start([Domain("E")]string e)\verb+{}+
[AcceptingStateCondition]
static bool IsAcceptingState() {return Contract.content.IsEmpty;}
}
public static class Factory
{
public static ModelProgram CreateScenario()
{
return new LibraryModelProgram(typeof(Contract).Assembly,
"BagModel", new Set("ElementRestriction"));
}
}
}
Figure 12.3. A feature of the bag model and a scenario including the feature.
The factory method CreateScenario creates a restricted model where the input
parameters to the actions are restricted to the given elements. The method uses
the LibraryModelProgram constructor that takes an assembly, a namespace that
identifies a model program in the assembly, and a set of feature names within that
198 Testing Systems with Complex State
model program as arguments. Notice that the ElementRestriction feature has a
void Lookup Start method as opposed to a Lookup method that returns an integer.
This is because the feature does not need to restrict the return values. Using features
to restrict parameter domains is one possible use of features. We discuss more
about the use of features in forthcoming sections.
Pages:
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267