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.

Systems with Complex State 157<br />

limited interface. The model program allows you to get the initial state and produce<br />

transitions that take you to subsequent states. Like an enumerator, you can’t find out<br />

how many states a model program has without exploring it step by step.<br />

<strong>Model</strong> programs with large numbers of states and transitions are not just a<br />

theoretical curiosity. Using values with large domains like strings and integers turns<br />

out to be very useful for modeling real world systems. Data types like int and string<br />

provide descriptive power. <strong>We</strong>’ll see this with an example later in this chapter. For<br />

now, let’s review the kinds of data types that can be used in writing model programs.<br />

10.2 Types for model programs<br />

You may only use certain types for state variables and action parameters in model<br />

programs that work with the tools we describe. 1 This is necessary because exploration<br />

using these tools can only determine whether two states are equal when the<br />

state variables belong to these types.<br />

Any of the following .NET-provided types may be used for state variables and<br />

action parameters: bool, byte, char, double, float, int, long, short, string as well<br />

as any enum type defined by the model program.<br />

In addition to these built-in types, you may also use the structured types and<br />

collection types described in the rest of this chapter and the object types that we will<br />

introduce later in Chapter 15. 2<br />

10.3 Compound values<br />

Extending our model program with strings and integers doesn’t change the way we<br />

do state comparison. Just as in the previous chapters, two states are equal if their<br />

variables contain the same values. The string data type is compatible with this kind<br />

of equality: two strings are equal if they contain the same characters. Whether the<br />

two strings share the same location in memory doesn’t matter when asking if they<br />

are equal. This kind of equality is called structural equality. It is the kind of equality<br />

that matters for state comparison.<br />

1 For the purposes of this chapter we use the term model program to mean a model program<br />

written in C# source, compiled into a .NET assembly and loaded as a Library<strong>Model</strong>Program<br />

data type. The N<strong>Model</strong> package allows extenders to implement other kinds of model programs<br />

that need not rely on .NET types for internal state.<br />

2 The modeling framework provides an interface called IAbstractValue for extending the range<br />

of types permitted in model programs. This is documented in the N<strong>Model</strong> package. Most users<br />

will not need to do this kind of extension. Creating subclasses of CompoundValue is the easiest<br />

way to add data types.<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!