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 Complex State 195<br />

using System.Collections.Generic;<br />

namespace BagImpl<br />

{<br />

public class BagImpl<br />

{<br />

Dictionary table = new Dictionary();<br />

int count = 0;<br />

}<br />

}<br />

public int Lookup(string element)<br />

{<br />

int c = 0;<br />

table.TryGetValue(element, out c);<br />

return c;<br />

}<br />

public void Add(string element)<br />

{<br />

if (table.ContainsKey(element))<br />

table[element] += 1;<br />

else<br />

table[element] = 1;<br />

count += 1;<br />

}<br />

public void Delete(string element)<br />

{<br />

if (table.ContainsKey(element))<br />

{<br />

table[element] -= 1;<br />

count -= 1;<br />

}<br />

}<br />

public int Count<br />

{<br />

get<br />

{<br />

return count;<br />

}<br />

}<br />

Figure 12.1. Bag implementation.<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!