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.

20 <strong>Why</strong> <strong>We</strong> <strong>Need</strong> <strong>Model</strong>-<strong>Based</strong> <strong>Testing</strong><br />

namespace ClientServerImpl<br />

{<br />

// Temperature sensor simulator<br />

}<br />

public class Temperature<br />

{<br />

static int i = 0; // index for cycling through simulated data<br />

static double[] temperature = { 71.2, 71.3, 71.4 }; // simulated data<br />

}<br />

// Simulate acquiring sample from sensor, substitute for real sensor<br />

public double Sample()<br />

{<br />

return temperature[i++ % temperature.Length]; // cycle through data<br />

}<br />

public static double ConvertToCelsius(double temperature)<br />

{<br />

return 5*(temperature - 32.0)/9;<br />

}<br />

Figure 2.6. Remote instrument temperature sensor class.<br />

Each of our source files begins with the namespace declaration:<br />

namespace ClientServerImpl<br />

Every class (or other type) has a fully qualified name formed from the simple<br />

name that appears in its declaration and the namespace where it is declared. For<br />

example, Server is a simple name; the fully qualified name of our server class<br />

is ClientServerImpl.Server. Namespaces and fully qualified names make it possible<br />

to avoid name conflicts where other programs use the same simple names<br />

(Server, etc.). The namespace declaration is optional but should be used in code<br />

that you expect will be integrated into a larger system. The using statements identify<br />

the namespaces of other types used in the source program, so we can use their<br />

simple names (such as Socket) rather than their fully qualified names (such as<br />

System.Net.Sockets.Socket). During development, it is typical (but not required)<br />

to put files that declare different namespaces in different directories. This makes it<br />

possible to use the (short) simple names also as file names, without fear of creating<br />

file name conflicts.<br />

2.5 Applications<br />

Our two application programs Monitor and Logger (Figures 2.7 and 2.8) each contain<br />

a main method that calls methods in our libraries. The applications provide the<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!