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.

Advanced Topics 255<br />

namespace PayrollImpl<br />

{<br />

class XyzEmployee<br />

{<br />

int salary = 0;<br />

bool active = true;<br />

public void SetSalary(int x) { this.salary = x; }<br />

public void Delete() { this.active = false; }<br />

static public XyzEmployee Create() { return new XyzEmployee(); }<br />

}<br />

class Stepper : IStepper<br />

{<br />

static Dictionary employees =<br />

new Dictionary();<br />

public CompoundTerm DoAction(CompoundTerm action)<br />

{<br />

switch (action.Name)<br />

{<br />

case "CreateEmployee":<br />

XyzEmployee emp = XyzEmployee.Create();<br />

employees.Add(action[0], emp);<br />

return null;<br />

}<br />

}<br />

case "DeleteEmployee":<br />

XyzEmployee emp2 = employees[action[0]];<br />

emp2.Delete();<br />

return null;<br />

case "SetSalary":<br />

XyzEmployee emp3 = employees[action[0]];<br />

int value = (int) action[1];<br />

emp3.SetSalary(value);<br />

return null;<br />

default:<br />

throw new Exception("Unknown action");<br />

public void Reset() { employees.Clear(); }<br />

}<br />

}<br />

Figure 15.3. Implementation and harness for Payroll2.<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!