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.

250 <strong>Model</strong>ing Objects<br />

namespace Payroll1<br />

{<br />

class Employee : CompoundValue<br />

{<br />

public readonly int id;<br />

public Employee(int id) { this.id = id; }<br />

}<br />

}<br />

}<br />

static class Contract<br />

{<br />

static int nextId = 1;<br />

static Set allEmployees = Set.EmptySet;<br />

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

static Set NextEmployee()<br />

{<br />

return new Set(new Employee(nextId));<br />

}<br />

[Action]<br />

static void CreateEmployee([Domain("NextEmployee")] Employee emp)<br />

{<br />

nextId = nextId + 1;<br />

allEmployees = allEmployees.Add(emp);<br />

salary = salary.Add(emp, 0); // default salary<br />

}<br />

[Action]<br />

static void DeleteEmployee([Domain("allEmployees")] Employee emp)<br />

{<br />

allEmployees = allEmployees.Remove(emp);<br />

salary = salary.RemoveKey(emp);<br />

}<br />

[Action]<br />

static void SetSalary([Domain("allEmployees")] Employee emp, int x)<br />

{<br />

salary = salary.Override(emp, x);<br />

}<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!