27.07.2013 Views

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

196 <strong>Testing</strong> Systems with Complex State<br />

using System.Collections.Generic;<br />

using N<strong>Model</strong>;<br />

using N<strong>Model</strong>.Attributes;<br />

namespace Bag<strong>Model</strong><br />

{<br />

static class Contract<br />

{<br />

static Bag content = Bag.EmptyBag;<br />

}<br />

}<br />

[Action]<br />

static void Add(string element)<br />

{<br />

content = content.Add(element);<br />

}<br />

[Action]<br />

static void Delete(string element)<br />

{<br />

content = content.Remove(element);<br />

}<br />

[Action]<br />

static int Lookup(string element)<br />

{<br />

return content.CountItem(element);<br />

}<br />

[Action]<br />

static int Count()<br />

{<br />

return content.Count;<br />

}<br />

Figure 12.2. Bag model.<br />

possible input parameters is to provide a separate feature of the model that allows<br />

only a fixed set of elements to occur as input arguments to the respective actions.<br />

Such a feature is shown in Figure 12.3. This feature restricts the set of possible<br />

elements to null, "", and "b". It uses the Domain attribute to associate a fixed set of<br />

elements with each input parameter.<br />

more free ebooks download links at:<br />

http://www.ebook-x.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!