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.

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

This kind of model program is finitely branching. In other words, there are only<br />

a finite number of transitions available in each state. As the example shows, even a<br />

finitely branching model may have a computationally infeasible number of states.<br />

<strong>We</strong> will show in Chapter 11 how to adapt our analysis techniques to cases like this.<br />

In this chapter we’ll focus on how to write model programs that benefit from the<br />

descriptive power of richer structural data types.<br />

It is also possible to write model programs that are not finitely branching. Surprisingly,<br />

this does not necessarily mean that the number of states is unbounded. For<br />

example, here is a model program with only five states that has (computationally)<br />

infinite branching:<br />

namespace Counter2<br />

{<br />

static class Contract<br />

{<br />

static int counter = 0;<br />

}<br />

}<br />

[Action]<br />

static void ModularIncrement(int x)<br />

{ counter = (counter + x) % 5; }<br />

This model program is infinitely branching because in every state there are an<br />

“infinite” (very large) number of integer values for the parameter x. There are only<br />

five states because the modulus operator % in this example limits the counter to five<br />

values.<br />

The previous two examples illustrate one of the main differences between model<br />

programs and finite state machines (FSMs). FSMs always have a finite number<br />

of states and transitions, while model programs may represent systems with an<br />

unbounded number of states and transitions.<br />

You can understand this difference by analogy. Consider the relationship between<br />

the string array type string[] and an enumerator of strings IEnumerator.<br />

Conceptually, the two types are similar, but the string array is a finite type that<br />

provides a Length operation and random, indexed access. The enumerator, on the<br />

other hand, has a more limited interface that does not support querying for the<br />

number of elements or for random access. Instead, the enumerator allows you to get<br />

the first element in the enumeration and each successive element in turn. There is<br />

no requirement that the number of elements in the enumerator be finite.<br />

Similarly, a data structure for an FSM provides operations that allow you to query<br />

for the number of states and transitions. A model program, in contrast, has a more<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!