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.

172 <strong>Model</strong>ing Systems with Structured State<br />

In the code snippets that follow, we will omit for brevity the RevisionControl<br />

namespace declaration that defines the model’s scope, but this can be assumed.<br />

Revision data type<br />

In addition to the int and string data types, we will use an additional data record<br />

to define the concept of a “revision.”<br />

enum Op { Add, Delete, Change }<br />

class Revision : CompoundValue<br />

{<br />

public readonly Op op;<br />

public readonly int revisionNumber;<br />

}<br />

public Revision(Op op, int revisionNumber)<br />

{<br />

this.op = op;<br />

this.revisionNumber = revisionNumber;<br />

}<br />

The enumeration Op defines the kind of edit operations provided by the revision<br />

control system. Edits may consist of adding a file, changing the contents of an existing<br />

file, or deleting a file.<br />

<strong>We</strong> define a new compound value type Revision that is a pair of values: an<br />

operation and a revision number that says in which version of the repository the<br />

change appears. This lets the repository keep accurate information about all previous<br />

versions.<br />

Repository file state<br />

The repository maintains a per-file record of each revision that been made. <strong>We</strong> can<br />

model the change list as a sequence of revisions. The database of changes is a map<br />

associating file names to change lists.<br />

partial static class Repository<br />

{<br />

static Map db =<br />

Map.EmptyMap;<br />

}<br />

The first element of a change log is the most recent revision.<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!