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.

Systems with Finite <strong>Model</strong>s 65<br />

using N<strong>Model</strong>;<br />

using N<strong>Model</strong>.Attributes;<br />

using N<strong>Model</strong>.Execution;<br />

namespace NewsReader<br />

{<br />

static class NewsReaderUI<br />

{<br />

// Types for each state variable<br />

enum Page { Topics, Messages };<br />

enum Style { WithText, TitlesOnly };<br />

enum Sort { ByFirst, ByMostRecent };<br />

// State variables, initial state<br />

static Page page = Page.Topics;<br />

static Style style = Style.WithText;<br />

static Sort sort = Sort.ByMostRecent;<br />

// Actions: enabling condition, then action method<br />

static bool SelectMessagesEnabled()<br />

{<br />

return (page == Page.Topics);<br />

}<br />

[Action]<br />

static void SelectMessages()<br />

{<br />

page = Page.Messages;<br />

}<br />

static bool SelectTopicsEnabled()<br />

{<br />

return (page == Page.Messages);<br />

}<br />

[Action]<br />

static void SelectTopics()<br />

{<br />

page = Page.Topics;<br />

}<br />

// to be continued ...<br />

Figure 5.4. <strong>We</strong>b-based newsreader: model program (part 1).<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!