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.

Systems with Complex State 169<br />

Bag properties and queries<br />

Bags support all of the set operations. The behavior of these operations is similar to<br />

that of sets, except that multiplicity is respected. For example, the Union operation<br />

for a bag adds the multiplicities of each element.<br />

Bags have a few operations that are not available on sets. For example, you can<br />

find out the multiplicity of an element in a bag with the CountItem method. You can<br />

find out the number of distinct elements in the bag using the CountUnique property.<br />

The Count property returns to total number of elements, including multiples.<br />

10.3.6 Pairs and triples<br />

A pair is a data record with two elements. A pair is an immutable value with<br />

structural equality.<br />

Pair nameId = new Pair(1, "Alice");<br />

Assert.AreEqual(nameId.First, 1);<br />

Assert.AreEqual(nameId.Second, "Alice");<br />

The pair constructor takes the paired values as its argument. The properties First<br />

and Second give access to contents of the pair.<br />

A triple is a data record with three elements. Like pairs, triples are immutable<br />

values with structural equality.<br />

Triple nameIdPay =<br />

new Triple(1, "Alice", 2000.0);<br />

Assert.AreEqual(nameId.First, 1);<br />

Assert.AreEqual(nameId.Second, "Alice");<br />

Assert.AreEqual(nameId.Third, 2000.0);<br />

The triple constructor takes three values as its arguments. The properties First,<br />

Second, and Third give access to contents of the data record.<br />

Pairs and triples work well with sets, maps, sequences, and bags. For example,<br />

a set of pairs represents a binary relation. Binary relations occur often in systems<br />

with dynamic relationships between entities.<br />

10.4 Case study: revision control system<br />

In this section we present a case study for a revision control system that uses some<br />

of the data types introduced in the preceding sections.<br />

A revision control system is a distributed software application that helps programmers<br />

work together on a common source base. Each user edits a local copy of<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!