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.

10.3.1 Sets<br />

Systems with Complex State 159<br />

The data fields of a value are not variable locations of memory like typical instances<br />

of class types.<br />

Note that compound values, although they may be tree-structured, are by construction<br />

not allowed to contain circular references.<br />

The CompoundValue base class provides the necessary support for structural equality,<br />

hash coding, and several other services required by the modeling framework.<br />

The N<strong>Model</strong> framework includes several families of compound values as built-in<br />

types. These are documented in Appendix A and in the N<strong>Model</strong> package itself.<br />

These types are used frequently in software models. In the following sections, we<br />

will describe these built-in types for sets, maps, sequences, bags, pairs, and triples.<br />

All of these built-in types are immutable value types, like the string type. If you<br />

can program using strings, you should be able to master the modeling collection<br />

types.<br />

A set is an unordered collection of distinct elements. Sets are immutable values but<br />

you can construct new sets by operations such as union and intersection, just as you<br />

can construct .NET string values by concatenation. Appendix A.2.2 provides a list<br />

of set operations provided by the N<strong>Model</strong> library.<br />

You will find that sets, which are unordered, are preferable to ordered sequences<br />

in many modeling examples because they reduce the number of states that must be<br />

considered for design analysis and testing. States that use sets are more abstract than<br />

states that use ordered data structures like sequences.<br />

Two sets that contain the same elements are equal, regardless of the order in<br />

which their elements were added. Sequences, on the other hand, are not equal if<br />

their elements appear in different orders.<br />

For example, consider a network model where there are some clients communicating<br />

with a server. Clients may join and leave the session at any time. If the model<br />

of the server state uses a set to keep track of active clients, then the order in which<br />

clients arrive will not matter. This is a useful abstraction, especially if no operations<br />

of the system depend on the order of client entry.<br />

static Set clients = Set.EmptySet;<br />

[Action]<br />

static void AddClient(string client)<br />

{<br />

clients = clients.Add(client);<br />

}<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!