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.

86 <strong>Model</strong> Programs<br />

using System; // Math for Abs in CheckMessage<br />

using N<strong>Model</strong>;<br />

using N<strong>Model</strong>.Attributes;<br />

using N<strong>Model</strong>.Execution;<br />

namespace Reactive<br />

{<br />

static class Controller<br />

{<br />

// Types from implementation<br />

enum ControlEvent { Timeout, Message, Command, Exit }<br />

enum WaitFor { Timeout, Message }<br />

enum Sensor { OK, Error }<br />

// Types added for model<br />

enum Phase { WaitForEvent, HandleEvent }<br />

// Control state from implementation<br />

static ControlEvent cevent = ControlEvent.Timeout;<br />

static WaitFor waitfor = WaitFor.Timeout; // enable Reset<br />

static Sensor sensor = Sensor.Error; // enable Reset<br />

// Control state added for model<br />

// Alternate between waiting for events and handling events<br />

static Phase phase = Phase.WaitForEvent;<br />

// <strong>Model</strong> the timer and the sensor<br />

static bool TimeoutScheduled = true;<br />

static bool MessageRequested = false;<br />

// Data state from implementation<br />

static string buffer = OutOfRange;<br />

static double previous = Uninitialized;<br />

// Constants<br />

const string InRange = "99.9"; // for buffer<br />

const string OutOfRange = "999.9"; // for buffer<br />

const double Uninitialized = double.MaxValue; // for previous<br />

// continued ...<br />

Figure 5.12. Reactive system: model program (part 1).<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!