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.

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

12.2 Implementation, model and stepper<br />

For the example in this chapter we use an implementation of a bag, shown in<br />

Figure 12.1, as a sample IUT throughout this section to illustrate various techniques<br />

that can be used for on-the-fly testing. This example is small and easy to understand<br />

while it naturally leads to a model program with complex state and infinite behavior.<br />

It helps to illustrate on a smaller scale many of the properties of more complex<br />

model programs that use state variables with unbounded data types.<br />

12.2.1 Implementation<br />

12.2.2 <strong>Model</strong><br />

A bag is an unordered collection of elements. An element can be added to the bag,<br />

deleted from the bag, and looked up in the bag. The multiplicity of an element is the<br />

number of times it occurs in the bag. Looking up an element in the bag returns the<br />

multiplicity of that element. An element is not in the bag if and only if its multiplicity<br />

is zero. You can also count the total number of elements in the bag. Unlike the bag<br />

data type in the modeling library, the bag implementation is not a value type.<br />

The bag model has an action vocabulary that corresponds to the methods of the bag<br />

implementation. The model program is shown in Figure 12.2. The following action<br />

trace is an example of a correct behavior of the bag:<br />

Add("elem1")<br />

Add("elem1")<br />

Count_Start()<br />

Count_Finish(2)<br />

Lookup_Start("elem1")<br />

Lookup_Finish(2)<br />

Lookup_Start("elem2")<br />

Lookup_Finish(0)<br />

Delete("elem1")<br />

Lookup_Start("elem1")<br />

Lookup_Finish(1)<br />

The content variable is the only state variable of the model program. In the<br />

initial state, the value of content is the empty bag. The bag model program defines<br />

an infinite state machine because the input parameter domains of the actions are<br />

unbounded and the size of the bag is unbounded. One way to constrain the set 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!