Book of Red Gate 2010 - Red Gate Software
Book of Red Gate 2010 - Red Gate Software
Book of Red Gate 2010 - Red Gate Software
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
2. Give a test case that shows this code is broken.<br />
static int BinarySearch(IList items, int<br />
target)<br />
{<br />
int lower = 0;<br />
int upper = items.Count;<br />
while (lower != upper - 1)<br />
{<br />
int mid = (lower + upper)/2;<br />
if (target < items[mid])<br />
upper = mid;<br />
else<br />
lower = mid;<br />
}<br />
if (items[lower] == target)<br />
return lower;<br />
return -1;<br />
}<br />
3. This always throws an exception, right?<br />
A foo = null;<br />
foo.Bar();<br />
Continued over the page...<br />
102