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.

Advanced Topics 227<br />

namespace SP<br />

{<br />

[Feature]<br />

class Credits<br />

{<br />

static Set window = new Set(0);<br />

static int maxId = 0;<br />

static Map requests = Map.EmptyMap;<br />

[Action("ReqSetup(m,c)")]<br />

[Action("ReqWork(m,c)")]<br />

static void Req(int m, int c)<br />

{<br />

requests = requests.Add(m, c);<br />

window = window.Remove(m);<br />

}<br />

[Requirement("Section ...: Message IDs must not be repeated")]<br />

static bool ReqEnabled(int m){return window.Contains(m);}<br />

[Requirement("Section ...: Requested credits must be > 0.")]<br />

static bool ReqEnabled(int m, int c){return c > 0;}<br />

[Action("ResSetup(m,c,_)")]<br />

[Action("ResWork(m,c,_)")]<br />

public static void Res(int m, int c)<br />

{<br />

for (int i = 1; i = c;}<br />

[AcceptingStateCondition]<br />

static bool IsAcceptingState() { return requests.IsEmpty; }<br />

[StateInvariant("Section ...: Client must have enough credits")]<br />

static bool ClientHasEnoughCredits()<br />

{<br />

if (requests.Count == 0) return window.Count > 0;<br />

else return true;<br />

}<br />

}<br />

}<br />

Figure 14.1. Credits feature model program.<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!