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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

}<br />

[Action]<br />

static void DeleteObject(string obj)<br />

{<br />

references = references.Remove(obj);<br />

}<br />

If you were to explore this model program you would notice that the following<br />

two traces result in the same end state:<br />

Trace 1 Trace 2<br />

AddReference("objA") AddReference("objA")<br />

RemoveReference("objA") AddReference("objA")<br />

AddReference("objA") RemoveReference("objA")<br />

RemoveReference("objA") RemoveReference("objA")<br />

DeleteObject("objA") DeleteObject("objA")<br />

Creating bags<br />

The easiest way to create a new bag is to list the elements in the constructor. The<br />

order in which arguments appear doesn’t matter, and duplicates will be used as many<br />

times as they appear:<br />

Bag cities = new Bag("Athens", "Rome", "Athens",<br />

"Paris", "New York", "Seattle");<br />

Assert.AreEqual(cities.Count, 6);<br />

You can also create a bag from an IEnumerable object:<br />

static Bag ConvertToBag(IEnumerable list)<br />

{<br />

return new Bag(list);<br />

}<br />

Like sets, bags implement the IEnumerable interface, so they can be used iteratively.<br />

If an element appears in a bag more than once, iteration will include it more<br />

than once. If you want to get access to the unique values found in a bag, you can<br />

use the Keys property.<br />

Iteration over bags occurs in an arbitrary order.<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!