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.

206 <strong>Testing</strong> Systems with Complex State<br />

Transition coverage. Another widely used notion of behavioral coverage is to<br />

visit all the different transitions of the state machine. You can implement a<br />

transition coverage function as follows. It is useful to map states to their hash<br />

codes here, rather than keeping around full states.<br />

Bag GetTransitionCoverage(IState s, Action a)<br />

{<br />

return new Bag(Term.Create("Cp",<br />

new Literal(s.GetHashCode()),a));<br />

}<br />

Notice that it is not necessary to compute the actual target state of the<br />

transition, because it is uniquely determined by the source state and the action,<br />

and would therefore not affect the coverage.<br />

12.4.2 Action selection<br />

Our custom strategy derives from the basic strategy. It takes a given model program<br />

model and a given coverage function getCoverage.<br />

partial class CustomStrategy : Strategy<br />

{<br />

CoverageFunction GetCoverage;<br />

}<br />

public CustomStrategy(<strong>Model</strong>Program model,<br />

{<br />

}<br />

this.GetCoverage = getCoverage;<br />

CoverageFunction getCoverage) : base(model)<br />

The custom strategy uses a history variable coveragePoints, which also happens<br />

to be a bag, that keeps count of the total number of occurrences of all the coverage<br />

points seen so far. Initially the bag is empty.<br />

partial class CustomStrategy<br />

{<br />

Bag coveragePoints = Bag.EmptyBag;<br />

}<br />

The main purpose of the custom strategy is to provide a particular implementation<br />

of the method SelectAction. The idea is that an action is selected in such a way<br />

that its reward is maximized. The GetReward function is defined below. If there are<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!