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.

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

reward += ((double)newC / (double)(newC + oldC));<br />

}<br />

return reward;<br />

}<br />

}<br />

Notice the special case when GetCoverage always returns a bag with a single<br />

coverage point p, for example, if GetVocabularyCoverage is being used as the<br />

GetCoverage function. The reward will in this case be 1/(1 + m), where m is the<br />

number of times that p has been visited before.<br />

Finally, we need to override the method DoAction that records that a given action<br />

is taken, because it needs to update the state variable coveragePoints by including<br />

all the new coverage points and by increasing the counts of all the previously covered<br />

coverage points.<br />

partial class CustomStrategy<br />

{<br />

public override void DoAction(Action a)<br />

{<br />

coveragePoints = coveragePoints.Union(GetCoverage(CurrentState, a));<br />

base.DoAction(a);<br />

}<br />

}<br />

In order to illustrate the effect of using GetVocabularyCoverage, let us add the<br />

statement<br />

Console.WriteLine("reward: " + bestRewardSoFar + " actions: "<br />

+ bestActionsSoFar);<br />

right before the return statement of the SelectAction method. <strong>We</strong> also need to<br />

provide a creator method for the custom strategy. Assume also that the custom<br />

strategy has been compiled into an assembly CustomStrategy.dll and uses the<br />

namespace CustomStrategy. Consider the following settings for ct defined in a<br />

settings file named args.txt.<br />

# references<br />

/r:Bag<strong>Model</strong>.dll /r:BagImpl.dll /r:CustomStrategy.dll<br />

# factory method of the model<br />

Bag<strong>Model</strong>.Factory.CreateScenario<br />

# factory method of the strategy<br />

/strategy:CustomStrategy.CustomStrategy.CreateStrategy<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!