TryGetValue(element, out c);
return c;
}
public void Add(string element)
{
if (table.ContainsKey(element))
table[element] += 1;
else
table[element] = 1;
count += 1;
}
public void Delete(string element)
{
if (table.ContainsKey(element))
{
table[element] -= 1;
count -= 1;
}
}
public int Count
{
get
{
return count;
}
}
}
}
Figure 12.1. Bag implementation.
196 Testing Systems with Complex State
using System.Collections.Generic;
using NModel;
using NModel.Attributes;
namespace BagModel
{
static class Contract
{
static Bag
content = Bag.EmptyBag;
[Action]
static void Add(string element)
{
content = content.Add(element);
}
[Action]
static void Delete(string element)
{
content = content.Remove(element);
}
[Action]
static int Lookup(string element)
{
return content.CountItem(element);
}
[Action]
static int Count()
{
return content.Count;
}
}
}
Figure 12.2. Bag model.
possible input parameters is to provide a separate feature of the model that allows
only a fixed set of elements to occur as input arguments to the respective actions.
Such a feature is shown in Figure 12.3. This feature restricts the set of possible
elements to null, "", and "b". It uses the Domain attribute to associate a fixed set of
elements with each input parameter.
Systems with Complex State 197
using System.Collections.Generic;
using NModel;
using NModel.
Pages:
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266