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.

162 <strong>Model</strong>ing Systems with Structured State<br />

10.3.2 Maps<br />

Union, intersection, and difference<br />

Any two sets of the same type can be combined by union, intersection, and difference.<br />

Union produces the set with all of the elements. Intersection is the set of elements<br />

shared by the two sets. Difference is the set of elements from the first set that are<br />

not found in the second set.<br />

Set s1 = new Set(1, 2, 3, 4, 5, 6);<br />

Set s2 = new Set(1, 3, 5, 7, 9, 11);<br />

Set s3 = s1.Union(s2);<br />

Set s4 = s1.Intersect(s2);<br />

Set s5 = s1.Difference(s2);<br />

Assert.AreEqual(s3, new Set(1, 2, 3, 4, 5, 6, 7, 9, 11));<br />

Assert.AreEqual(s4, new Set(1, 3, 5));<br />

Assert.AreEqual(s5, new Set(2, 4, 6));<br />

You can write union as +, intersection as *, and difference as -.<br />

Set s1 = new Set(1, 2, 3, 4, 5, 6);<br />

Set s2 = new Set(1, 3, 5, 7, 9, 11);<br />

Set s3 = s1 + s2;<br />

Set s4 = s1 * s2;<br />

Set s5 = s1 - s2;<br />

Assert.AreEqual(s3, new Set(11, 3, 2, 9, 6, 5, 7, 4, 1));<br />

Assert.AreEqual(s4, new Set(3, 1, 5));<br />

Assert.AreEqual(s5, new Set(6, 4, 2));<br />

Maps associate unique keys with values. This is similar to the .NET Dictionary type,<br />

except that a map is an immutable value. Operations to add and remove elements<br />

result in new maps instead of making changes to the map given as the argument.<br />

Another difference between maps and the .NET dictionary type is structural<br />

equality. Two maps of the same type are equal if they contain the same key/value<br />

pairs. Dictionaries in .NET use reference equality instead of structural equality.<br />

Also, unlike the .NET dictionary type, the value null may be used as a key in a<br />

map.<br />

Appendix A.2.3 provides a list of map operations provided by the N<strong>Model</strong> library.<br />

Maps appear often in models with structured state. Maps may be used to represent<br />

dynamic functions, or key/value relationships that evolve during the run of the<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!