<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Melle Koning Blog</title>
	<atom:link href="http://www.mellekoning.nl/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mellekoning.nl</link>
	<description>Programming and software development in a team</description>
	<lastBuildDate>Mon, 09 Apr 2012 16:53:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Monitor progress with the burnup chart</title>
		<link>http://www.mellekoning.nl/index.php/2012/04/09/monitor-progress-with-the-burnup-chart/</link>
		<comments>http://www.mellekoning.nl/index.php/2012/04/09/monitor-progress-with-the-burnup-chart/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 16:50:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mellekoning.nl/?p=515</guid>
		<description><![CDATA[Everybody working with scrum will be familiar with a burn-down chart. Showing all the work that is not yet DONE, thus pending. We also tried this at first but soon discovered that it did not show us a lot about &#8230; <a href="http://www.mellekoning.nl/index.php/2012/04/09/monitor-progress-with-the-burnup-chart/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- RSPEAK_STOP --> <a href='http://wr.readspeaker.com/webreader/webreader.php?cid=dd6262a4ba859cbb9032fa17f541664d&t=wordpress_free&url=http://www.mellekoning.nl/index.php/2012/04/09/monitor-progress-with-the-burnup-chart/&title=Monitor progress with the burnup chart' onclick='readpage(this.href, 515); return false;'> <img src='http://graphics.readspeaker.com/images/wr/listen_nl_nl.gif' style='border-style: none;' alt='Lees voor met webReader'></a><div id='WR_515'></div> <!-- RSPEAK_START --> <p>Everybody working with scrum will be familiar with a burn-down chart. Showing all the work that is not yet DONE, thus pending.</p>
<p>We also tried this at first but soon discovered that it did not show us a lot about progress during the sprint because the burndown chart often looks like this:</p>
<p><center><br />
<img src="http://www.mellekoning.nl/images/scrumburnup/scrumburndown.PNG"><br />
</center></p>
<p>Simply put: nothing is done in the beginning of the sprint because the team is busy on all the stuff, and only at the end of the sprint you start to see that things are done. Because only at the end of the sprint, the things are really done.</p>
<p>This is common when you are doing short cycle sprints, that is your sprints only take two or three weeks instead of two months. And you want your sprints to be short, so what is the use of a burndown chart than? Not much. Do we have something else? Sure we do.</p>
<h2>The alternative: the burn-up chart.</H2></p>
<p>Have a look at a burnUP chart below, taken from one of our sprints:</p>
<p><center><br />
<img src="http://www.mellekoning.nl/images/scrumburnup/burnup400.jpg"><br />
</center></p>
<p>The lines on the burnup chart reflect the number of story points <em>right of a particular column</em> on the taskboard.</p>
<p>Monitoring progress goes much better when you measure tasks going through your process! This is as easy as counting the number of cards on your taskboard, or even better, counting the number of <em>story points on the cards</em> for each column you have on your task board.</p>
<p>Please note the small arrows on the taskboard below, at the top of some of the columns. I have added the red arrow, as that one was unfortunately missing in the picture below <img src='http://www.mellekoning.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><center><br />
<a href="http://www.mellekoning.nl/images/scrumburnup/scrumboardburnupcolumnsBIG.png"><br />
<img src="http://www.mellekoning.nl/images/scrumburnup/scrumboardburnupcolumns.png"></a><br />
Click on image for a larger view.<br />
</center></p>
<p>Cards should go from left to right towards the &#8216;done&#8217; column. And if that is the case, your burnup will look like the burnup chart above.</p>
<p>However, when developers and testers are moving cards in the opposite direction, from right to left on the teams scrumboard, the graph might surprisingly look something like this:</p>
<p><center><br />
<img src="http://www.mellekoning.nl/images/scrumburnup/burnupwithtasksgoingbackwards.PNG"><br />
</center></p>
<p>It&#8217;s the green line, -all story points right of the test column- that has been <em>decreasing for three days in a row</em>!</p>
<p>This means that development work was considered done by developers, moved into the test column at first but when tested <em>put back to the dev-column</em> and thus something is going wrong in that process. Maybe the devs and the QA&#8217;s did not agree how the work should have been done? Seems that developers think they can put stories to the right from DEV to TEST and the ones who test the work are putting the cards back into the dev column! Above, the black &#8216;dev-line&#8217; has been increasing as well meaning more work was picked up while earlier work was not approved&#8230;</p>
<p>Not good, and something to talk about in the daily standup!</p>
<p>The good news with the burn-up chart is: at least you now know what is happing during the sprint instead of only afterwards when you have your retrospective!</p>
<p>PS: The burnup chart is exactly the same as the <A href="http://www.slideshare.net/yyeret/explaining-cumulative-flow-diagrams-cfd">CFD (Cumulative Flow Diagram) as discribed on this page</a> but the benefit of drawing it as a burnup next to your scrumboard is that it is in everybodies face <img src='http://www.mellekoning.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
 <!-- RSPEAK_STOP -->]]></content:encoded>
			<wfw:commentRss>http://www.mellekoning.nl/index.php/2012/04/09/monitor-progress-with-the-burnup-chart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scrum is impossible without quality</title>
		<link>http://www.mellekoning.nl/index.php/2012/01/06/scrum-is-impossible-without-quality/</link>
		<comments>http://www.mellekoning.nl/index.php/2012/01/06/scrum-is-impossible-without-quality/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 16:39:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mellekoning.nl/?p=508</guid>
		<description><![CDATA[Hi all, I would like to tell something about Scrum and how it is related to quality. As Uwe Friedrichsen clearly pointed out on codecentric.de Uwe Friedrichsen on #scrum: Leider laufen ganz viele selbsternannte agile “Experten” und “Evangelisten” herum, die &#8230; <a href="http://www.mellekoning.nl/index.php/2012/01/06/scrum-is-impossible-without-quality/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- RSPEAK_STOP --> <a href='http://wr.readspeaker.com/webreader/webreader.php?cid=dd6262a4ba859cbb9032fa17f541664d&t=wordpress_free&url=http://www.mellekoning.nl/index.php/2012/01/06/scrum-is-impossible-without-quality/&title=Scrum is impossible without quality' onclick='readpage(this.href, 508); return false;'> <img src='http://graphics.readspeaker.com/images/wr/listen_nl_nl.gif' style='border-style: none;' alt='Lees voor met webReader'></a><div id='WR_508'></div> <!-- RSPEAK_START --> <p>Hi all, I would like to tell something about Scrum and how it is related to quality. </p>
<p>As Uwe Friedrichsen clearly pointed out on <a href="http://blog.codecentric.de/2011/10/der-scrummaster-ist-nicht-dein-freund/#comment-10341">codecentric.de</a></p>
<p>Uwe Friedrichsen on  #scrum:<br />
<blockquote> Leider laufen ganz viele selbsternannte agile “Experten” und “Evangelisten” herum, die auf Konferenzen und anderweitig solche “Ihr seid das Team! Es zählt nur, was Ihr wollt! ‘Die’ haben Euch lange genug nicht ernst genommen! Nur Ihr seid wichtig! ‘Die da’ sollen gefälligst still sein und Euch machen lassen!” &#8211; <em>Parolen als Opium unter das Entwickler-Volk </em> streuen und sich entsprechender Beliebtheit erfreuen. </p></blockquote>
<p>That is, scrum is the opium of the developers community because it promises that we finally get time, as in being left alone, to produce quality software. </p>
<p>It&#8217;s a statement that I believe to be true. That is; developers do want to focus on their work to deliver quality software. The reality is that it goes both ways! If you turn the statement around: </p>
<p><b>If you can&#8217;t deliver quality then you can&#8217;t do scrum either.</b></p>
<p>What we realized when trying to introduce a fixed sprint lately is simply that you can not keep working only on the sprint tasks when the live product is not working as expected because of themprevious sprint. In our case it was as bad that it meant we had to do hotfixes and enhancements on the live sites as well as keeping pace on the current sprint. </p>
<p>The reality is that that&#8217;s just not scrum. It&#8217;s kanban as best because hotfixes are just tasks that take over the top priority tasks of your current sprint. And that is exactly what happened in our last sprint. Have a look at this imaginary scrum task board.</p>
<p><img src="http://www.mellekoning.nl/images/kanbanwithhotline.png"></p>
<p>Image of task board with a hotline on top.</p>
<p>We have got rows on our task board for each user story, sorted on priority.  The realization is that if your previous sprint had quality issues then your current sprint will have to deal with that earlier sprint one way or the other. Usually this involves heavy support patches and hot fixing.</p>
<p>The only way to get out of this loophole is to deliver quality. Only if the stories delivered are fully accepted and fully tested you will have somethig that&#8217;s shipable. </p>
<p>If you do not take the time or use the tools to deliver quality shipable software you will not reach scrum nirvana.</p>
 <!-- RSPEAK_STOP -->]]></content:encoded>
			<wfw:commentRss>http://www.mellekoning.nl/index.php/2012/01/06/scrum-is-impossible-without-quality/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The retrospective &#8211; seeing the patterns</title>
		<link>http://www.mellekoning.nl/index.php/2011/10/22/the-retrospective-seeing-the-patterns/</link>
		<comments>http://www.mellekoning.nl/index.php/2011/10/22/the-retrospective-seeing-the-patterns/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 20:17:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mellekoning.nl/?p=460</guid>
		<description><![CDATA[As I wrote just a few weeks ago in my blogpost going agile with scrum: the taskboard, a very important aspect of being a teamlead, or a &#8216;manager&#8217; of a team is to be able to monitor the work so &#8230; <a href="http://www.mellekoning.nl/index.php/2011/10/22/the-retrospective-seeing-the-patterns/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- RSPEAK_STOP --> <a href='http://wr.readspeaker.com/webreader/webreader.php?cid=dd6262a4ba859cbb9032fa17f541664d&t=wordpress_free&url=http://www.mellekoning.nl/index.php/2011/10/22/the-retrospective-seeing-the-patterns/&title=The retrospective &#8211; seeing the patterns' onclick='readpage(this.href, 460); return false;'> <img src='http://graphics.readspeaker.com/images/wr/listen_nl_nl.gif' style='border-style: none;' alt='Lees voor met webReader'></a><div id='WR_460'></div> <!-- RSPEAK_START --> <p>As I wrote just a few weeks ago in my blogpost <a href="http://www.mellekoning.nl/index.php/2011/10/08/going-agile-with-scrum-the-taskboard/">going agile with scrum: the taskboard</a>, a very important aspect of being a teamlead, or a &#8216;manager&#8217; of a team is to be able to <em>monitor the work</em> so that you are able to <em>look back afterwards</em>.</p>
<p>So what does <em>monitoring the work</em> actually mean? Well it is not about letting your team members write their daily hour sheets. That&#8217;s just a boring exercise for knowledge workers and does not have any positive effect at all, especially if no feedback whatsoever is returned to the team for the careful registration of those hours.</p>
<p>Monitoring is useful only when the team can look back and have an effective <em>retrospective</em>. This will get the team far more self aware. Before having a retrospective it is important to know a few things about how to have such a meeting. A very good book about this is from Esther Derby and Diana Larsen:</p>
<p><a href="http://www.amazon.com/gp/product/0977616649/ref=as_li_tf_il?ie=UTF8&#038;tag=wwwmellekonin-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399369&#038;creativeASIN=0977616649"><img border="0" src="http://www.mellekoning.nl/images/agileretrospectivesbook.jpg"></a></p>
<p>I highly recommend reading it. It tells you how to conduct a retrospective. Set aside enough time for the meeting; get out of the workplace so that you can&#8217;t get distracted by the frantic software factory. The book is pact with practical advice and has a full set of examples activities that can be done during a retrospective meeting. </p>
<h2>The retrospective&#8230;.</h2>
<p>To summarize, a retrospective has a few stages.<br />
1) Setting the stage<br />
2) Gathering data<br />
3) Generate insights<br />
4) Decide what to do<br />
5) Close the retrospective</p>
<p>In our first retrospective I first <em>set the stage</em> by shortly explaining what the goal of a retrospective is. This can stir some emotions because of people being unclear about the goal; don&#8217;t get distracted, repeat the goals and continue <img src='http://www.mellekoning.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>We then used the <em>timeline activity</em> to get a factual look back at what we did during the four weeks since we started an iteration of work. This was to gather the factual data. </p>
<p><center><img src="http://www.mellekoning.nl/images/retrospectivetimeline.PNG"><br /><em>a simple timeline, as an example</em></center></p>
<p>And because that timeline showed us how much we were actually busy with, namely lots of stuff, trying to handle multiple iterations at the same time as well as fire-fighting daily questions, it quickly made the team aware of the facts. It was hard to be focused as a team on one iteration when the other iterations were not finished yet! It&#8217;s hard to deliver quality when you have to jump from creating more features in the current iteration to helping testers getting earlier features out to production. </p>
<p>A good way to get an overview of the feelings was to set-up the next activity. We simply set-up a new flip over chart, divided that into two columns reading &#8216;glad&#8217; on the left side and &#8216;mad/sad&#8217; on the right. </p>
<p><center><img src="http://www.mellekoning.nl/images/gladsadmad.PNG"><br /><em>What was the team (not) happy about?</em></center></p>
<p>The timeline chart -with lots of data scribbled on it- was hanging next to the new flip over for the <em>generate insights activity</em>. </p>
<p>This generated the insights into the feelings we, as a team, were having about looking back at the particular time frame. Starting the activity as a &#8216;<em>brainstorm activity</em>&#8216; (see chapter 6.1 of the book) challenging the team to come up with 50 ideas or positive/negative feelings we soon got the flip chart filled with ideas plus emotions about the work that we were doing. This led us to the next stage in the retrospective: <em>Decide what to do</em>. The activity: define some reachable actions.</p>
<p>We did not aim too high with our actions. I pressed that the first actions we wrote down had to be achievable and take away a daily burden that the team felt. The simple actions we took were to<br />
help testers out and improve the standup meeting. Testers need to know what and how to test when issues are assigned to them. Also, we wanted to have a more effective and shorter standup meeting in the morning. This was because our morning meetings were going too far into the details and therefore took too long. The rules we made up for the team were that everybody should answer (only) the three usual standard questions of the <a href="http://en.wikipedia.org/wiki/Scrum_%28development%29#Daily_Scrum">daily-scrum</a>, and keep within one minute each. </p>
<p><center><img src="http://www.mellekoning.nl/images/retrospectivedecidewhattodo.PNG"><br /><i>Retrospective activity: decide what to do.</i></center></p>
<p>So, the team decided that if you wanted to say more that is still possible, but only after everybody got to have its turn and the standup meeting was finished when everybody had her say. This means people are free to wander off if the detailed discussions are not relevant for their work that day. </p>
<p>Second thing related to the standup is we decided was that we realised that we need a better room for our taskboard where we were having the daily scrums. The taskboard is currently in a separate room where other people are doing their work. We want our board to be in our development-room, one way or another.</p>
<p>We did not forget the last stage of the retrospective: <em>Closing</em>. Everybody mentioned the &#8216;return on time invested&#8217; and each individually said it was time very well spent: it&#8217;s good that as a team we took time to look back, spent some time on some frustrations and got happiness out of the things that are working well which we cherish, so to speak, like the time we invested in pair programming. In all, a succesfull retrospective it was!</p>
<h2>&#8230;&#8230;Seeing the patterns</h2>
<p>Of course, the team saw much more that should be achieved than the actions that we choose in the <em>decide what to do</em> part of the retrospective. Some of the actions that are defined are the <em>needs</em> of the team. And those needs can be outside of the teams control. Here is where the teamleads and management gets into play. To get the team work at its full potential we need to get all burdens and obstacles out of the way and have the organisation communicate to the team in a clear way what needs to be the focus for the next iteration.</p>
<p>One of the authors of <a href="http://www.amazon.com/gp/product/0977616649/ref=as_li_tf_tl?ie=UTF8&#038;tag=wwwmellekonin-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399369&#038;creativeASIN=0977616649">Agile Retrospectives: Making Good Teams Great</a><img src="http://www.assoc-amazon.com/e/ir?t=wwwmellekonin-20&#038;l=as2&#038;o=1&#038;a=0977616649&#038;camp=217145&#038;creative=399369" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> Esther Derby, makes a clear point of this in a recent interview: </p>
<blockquote><p>
[...] a critical role for middle managers and working across the organization to make sure that the organizational systems are working. Instead of just looking down at what my individual team needs and looking up to see what my manager needs they need to be looking across the organization looking to the right and left of them and understanding how work flows through the organization and how to create and adjust those systems so the work flows smoothly to the team and the policies and procedures and structures in the company enable the team to self-organize [...]<br />
<em><a href="http://www.infoq.com/interviews/esther-derby-systems-thinking">see full interview on InfoQ</a></em></p>
</blockquote>
<p>This of course is good stuff. As a teamlead / manager of the developmentteam one of the concrete ways to -at least try- to get more structure in the workflow, and thus iterations, is to be able to have clear ways of iterations, a backlog and make sure that when a new iteration can start, it&#8217;s clear what the team should work on. This means that before an iteration even starts we need to:</p>
<p>- Ask upfront priorities to stakeholders </p>
<p>That&#8217;s more easily said than done. Especially if the organisation switches its mind now and than about what is the most important thing to get delivered <img src='http://www.mellekoning.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  Anyway, whatever the priority that comes out, the team always needs to have clear goals by having:</p>
<p>- An organised backlog, keeping a wishlist of requested features and enhancements<br />
- Up-to-date priorities: Ask the stakeholders to check and sort the backlog scenario&#8217;s based on priority, on a regular basis<br />
- Feedback from delivered scenario&#8217;s: To keep spirit high the team needs to be energized by stakeholders on what was delivered.</p>
<p>And of course the team itself also wants to have a say on those priority lists; especially about what scenario&#8217;s in the backlog are easy to implement and which scenario&#8217;s aren&#8217;t or are seen as a waste of effort. A developmentteam needs to be part of the results; that&#8217;s what inspires and will come back as positive energy in retrospectives. Recognize a pattern already? <img src='http://www.mellekoning.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
 <!-- RSPEAK_STOP -->]]></content:encoded>
			<wfw:commentRss>http://www.mellekoning.nl/index.php/2011/10/22/the-retrospective-seeing-the-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Going agile with scrum: The taskboard</title>
		<link>http://www.mellekoning.nl/index.php/2011/10/08/going-agile-with-scrum-the-taskboard/</link>
		<comments>http://www.mellekoning.nl/index.php/2011/10/08/going-agile-with-scrum-the-taskboard/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 11:38:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mellekoning.nl/?p=438</guid>
		<description><![CDATA[A mayor deficiency of our and perhaps any IT software department is that it seems we just can&#8217;t make clear to our stakeholders what the !@## we are doing. How familiar do these remarks sound from your business and marketing &#8230; <a href="http://www.mellekoning.nl/index.php/2011/10/08/going-agile-with-scrum-the-taskboard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- RSPEAK_STOP --> <a href='http://wr.readspeaker.com/webreader/webreader.php?cid=dd6262a4ba859cbb9032fa17f541664d&t=wordpress_free&url=http://www.mellekoning.nl/index.php/2011/10/08/going-agile-with-scrum-the-taskboard/&title=Going agile with scrum: The taskboard' onclick='readpage(this.href, 438); return false;'> <img src='http://graphics.readspeaker.com/images/wr/listen_nl_nl.gif' style='border-style: none;' alt='Lees voor met webReader'></a><div id='WR_438'></div> <!-- RSPEAK_START --> <p>A mayor deficiency of our and perhaps any IT software department is that it seems we just can&#8217;t make clear to our stakeholders what the !@## we are doing. How familiar do these remarks sound from <em>your</em> business and marketing people to you? It might be the product owner who fires these questions:</p>
<p>- Hi Teamlead, who is going to work on feature X <strong>now</strong>?<br />
- You want to go live in 6 weeks with this? What about 14 days?<br />
- &#8220;But..? That feature should have been finished four weeks ago!&#8221; </p>
<p>These three examples are taken from real life; and no, I did not save these up from last few years, it&#8217;s just from the last few weeks&#8230; Is that a problem? Yes of course it is, and no, it&#8217;s not because our business people, marketeers or product owners don&#8217;t know anything about software development (well maybe), but the problem here is total lack of communication, publication, presentation and managing expectations about what the !@## it is that we are doing. </p>
<p>Should we make that more clear? Yes of course! </p>
<p>Point made? Great, but now how to solve that? How can you as a teamlead make clear what your team is doing? Here come scrum and agile to the rescue. It was only four weeks ago we decided that <em>we had to change this <strong>now</strong></em>. So we finally started.</p>
<p><center><strong>The first thing we did</strong>: We created our taskboard<P><br />
<img src="http://www.mellekoning.nl/images/taskboard.jpg"></center></p>
<p>Looks neat, doesn&#8217;t it? And you only need a board and either sticky notes or in our case plastic-magnetic cards where you can write on with markers. Luckily, we had these available so we did not have to ask for any funding to do this. If you don&#8217;t have a board: get the physical strongest developers of your team, go round in your office building and just grab a board from someone else <img src='http://www.mellekoning.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  Just make it happen; you are the factory of your organisation and if you need it to get your factory going than everyone else will understand, right?</p>
<p>We also asked the whole team to read up on our skills with <a href="http://www.infoq.com/minibooks/kanban-scrum-minibook">Kanban and scrum</a> by Kniberg and Skarin. Read it! It&#8217;s a very good introduction.</p>
<p>So what do you see on the taskboard? We decided to start with five columns, from left to right these are:<br />
- Analysis and design<br />
- Ready for development<br />
- In development<br />
- Ready for dev-stable<br />
- Ready for staging</p>
<p>To all software developers this will be easy to grasp. The leftmost column contains the items that still need to be thought about &#8216;how to implement&#8217;, and when that is ready we can move the item to ready-for-development. If a developer asks the teamlead for new work: she can pick up the task. Than the column in the middle <em>in development</em>. Here are the tasks that developers are currently working on. <em>Basicly the middle column defines our capacity</em>. When development is ready, we move the card to <em>ready for dev-stable</em> which means the software is to be integrated with other necessary modules and tested by a tester. And only if things have been approved on our dev-environment, we move the task-card to &#8216;ready for staging&#8217;, which is the environment where our stakeholders like marketeers or other business people who asked for the features test our work for the first time.</p>
<p>The last column also defines our <a href="http://www.youtube.com/watch?v=VgGJ0JuW44k#t=2m30s">definition of done</a>. </p>
<p><center><strong>The second thing we started</strong> was: daily standups at the board. </center><br />
Daily standups are easy and effective. Well, people have to get in at about the same time in the morning so that you can agree on an early start-time: that greatly helps as well. Three questions are answered by each individual developer:</p>
<p><center><br />
- What did you do yesterday?<br />
- What are you going to do today?<br />
- Are there any obstacles?<br />
</center></p>
<p>Doing the standup at the taskboard helped us moving cards from left to right on the board on a daily basis; if there is no flow for certain work items it immediately can be discussed at the board and help is offered to each other. </p>
<p>Introduction of the taskboard is not really a big change in the way of working but having the work items visible instead of only in a stale issuelist on the screen helped a lot with our communication; also it is now impossible that items stay in the same process step without anyone noticing&#8230; </p>
<p><strong>Third thing you need to do to effectively start agile and scrum</strong>: Keep track of the number of items in each column. Thus: <strong>Monitor progress.</strong><br />
<center><br />
In about two weeks this is our taskboard progress:<P><br />
<img src="http://www.mellekoning.nl/images/taskboardprogressweek39.png"><br />
</center></p>
<p>Keeping track enables the team to have a <em><a href="http://www.amazon.com/gp/product/0977616649/ref=as_li_tf_tl?ie=UTF8&#038;tag=wwwmellekonin-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399369&#038;creativeASIN=0977616649">retrospective</a><img src="http://www.assoc-amazon.com/e/ir?t=wwwmellekonin-20&#038;l=as2&#038;o=1&#038;a=0977616649&#038;camp=217145&#038;creative=399369" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><br />
</em> afterwards.<P></p>
<p>Earlier, we also kept track of progress by using the <a href="http://www.mellekoning.nl/index.php/2011/03/20/the-agile-estimation-sheet/">Agile estimation sheet</A> that works very good but having workitems visible on a taskboard works even better!</p>
<p>We suddenly realised that we could not make all items that we thought we would realize. So what we did was: We simply took those off the board and than our bottleneck became very, very clear: integration-testing! Nothing got approved and the business was pressing us to start more work&#8230;. but we haven&#8217;t finished our current work yet. &#8220;We&#8221; as in <em>we the organisation</em>. We got that clear to our stakeholders and are pulling them into our testing process because our tester was occupied firefighting live issues. Testing: that&#8217;s where the factory needs help from the business!<br />
<P><br />
Next time; a followup.. we have not yet done but will definitely do a <em><a href="http://www.amazon.com/gp/product/0977616649/ref=as_li_tf_tl?ie=UTF8&#038;tag=wwwmellekonin-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399369&#038;creativeASIN=0977616649">retrospective</a><img src="http://www.assoc-amazon.com/e/ir?t=wwwmellekonin-20&#038;l=as2&#038;o=1&#038;a=0977616649&#038;camp=217145&#038;creative=399369" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></em><br />
 with the team when the major features of this iteration get released to our live websites&#8230;. </p>
 <!-- RSPEAK_STOP -->]]></content:encoded>
			<wfw:commentRss>http://www.mellekoning.nl/index.php/2011/10/08/going-agile-with-scrum-the-taskboard/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Letterschuif! JavaScript for starters..</title>
		<link>http://www.mellekoning.nl/index.php/2011/10/02/letterschuif-javascript-for-starters/</link>
		<comments>http://www.mellekoning.nl/index.php/2011/10/02/letterschuif-javascript-for-starters/#comments</comments>
		<pubDate>Sun, 02 Oct 2011 20:30:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mellekoning.nl/?p=434</guid>
		<description><![CDATA[Een snel javascript paginaatje voor je kind in groep 3: Letterschuif! of klik hier op letterschuif!]]></description>
			<content:encoded><![CDATA[<!-- RSPEAK_STOP --> <a href='http://wr.readspeaker.com/webreader/webreader.php?cid=dd6262a4ba859cbb9032fa17f541664d&t=wordpress_free&url=http://www.mellekoning.nl/index.php/2011/10/02/letterschuif-javascript-for-starters/&title=Letterschuif! JavaScript for starters..' onclick='readpage(this.href, 434); return false;'> <img src='http://graphics.readspeaker.com/images/wr/listen_nl_nl.gif' style='border-style: none;' alt='Lees voor met webReader'></a><div id='WR_434'></div> <!-- RSPEAK_START --> <p>Een snel javascript paginaatje voor je kind in groep 3:<br />
<a href="https://twitter.com/mellekoning/status/120595213805817856">Letterschuif!</a></p>
<p><P><br />
of klik hier op <a href="http://www.mellekoning.nl/files/letterschuif.html">letterschuif!</a></p>
 <!-- RSPEAK_STOP -->]]></content:encoded>
			<wfw:commentRss>http://www.mellekoning.nl/index.php/2011/10/02/letterschuif-javascript-for-starters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WII Sports Table Tennis</title>
		<link>http://www.mellekoning.nl/index.php/2011/07/28/wii-sports-table-tennis/</link>
		<comments>http://www.mellekoning.nl/index.php/2011/07/28/wii-sports-table-tennis/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 20:41:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mellekoning.nl/?p=418</guid>
		<description><![CDATA[WII Sports table tennis is way cool! After alot of matches I finally reached the final stage, going crazy against the champion! Unfortunately, lost the match with 6 to 1.. is it possible to beat the WII Sports table tennis &#8230; <a href="http://www.mellekoning.nl/index.php/2011/07/28/wii-sports-table-tennis/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- RSPEAK_STOP --> <a href='http://wr.readspeaker.com/webreader/webreader.php?cid=dd6262a4ba859cbb9032fa17f541664d&t=wordpress_free&url=http://www.mellekoning.nl/index.php/2011/07/28/wii-sports-table-tennis/&title=WII Sports Table Tennis' onclick='readpage(this.href, 418); return false;'> <img src='http://graphics.readspeaker.com/images/wr/listen_nl_nl.gif' style='border-style: none;' alt='Lees voor met webReader'></a><div id='WR_418'></div> <!-- RSPEAK_START --> <p>WII Sports table tennis is way cool! After alot of matches I finally reached the final stage, going crazy against the champion!</p>
<p><iframe width="425" height="349" src="http://www.youtube.com/embed/OpeDehY8h5Q?hl=nl&#038;fs=1" frameborder="0" allowfullscreen></iframe></p>
<p>Unfortunately, lost the match with 6 to 1.. is it possible to beat the WII Sports table tennis champion?</p>
<p>a month later&#8230;</p>
<p>YES! It is possible! Won 7 to 5, it was a close match!<br />
<center><br />
<img src="http://www.mellekoning.nl/images/ttbeatchampion.png"></p>
<p></center><br />
<P><br />
Must say that I did not use any of the tactics that I saw on other video&#8217;s on youtube; people who were able to smash the champion around; it was a very tactic game with lots of switches between back- and topspin. Especially the second topspin, totally aimed to the left, right after a few backspins were the trick; the champion could not reach those balls <img src='http://www.mellekoning.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
 <!-- RSPEAK_STOP -->]]></content:encoded>
			<wfw:commentRss>http://www.mellekoning.nl/index.php/2011/07/28/wii-sports-table-tennis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make branching visible to your team</title>
		<link>http://www.mellekoning.nl/index.php/2011/07/12/make-branching-visible-to-your-team/</link>
		<comments>http://www.mellekoning.nl/index.php/2011/07/12/make-branching-visible-to-your-team/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 20:23:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mellekoning.nl/?p=395</guid>
		<description><![CDATA[Source code control is key to an effective team. Having multiple experienced developers in your team will also result in some developers working on different issues, some of which will take some more time to develop. And with the current &#8230; <a href="http://www.mellekoning.nl/index.php/2011/07/12/make-branching-visible-to-your-team/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- RSPEAK_STOP --> <a href='http://wr.readspeaker.com/webreader/webreader.php?cid=dd6262a4ba859cbb9032fa17f541664d&t=wordpress_free&url=http://www.mellekoning.nl/index.php/2011/07/12/make-branching-visible-to-your-team/&title=Make branching visible to your team' onclick='readpage(this.href, 395); return false;'> <img src='http://graphics.readspeaker.com/images/wr/listen_nl_nl.gif' style='border-style: none;' alt='Lees voor met webReader'></a><div id='WR_395'></div> <!-- RSPEAK_START --> <p>Source code control is key to an effective team. Having <a href="http://www.mellekoning.nl/index.php/2009/01/07/climbing-the-skill-hill/">multiple experienced developers in your team</a> will also result in some developers working on different issues, some of which will take some more time to develop. And with the current frantic release pressures in the software factory and the risks involved in building new <em>features</em> you will have different developers work on different branches.</p>
<p>Don&#8217;t waste time having developers sit on their hands, <em>just branch and code on</em>! Therefore, <a href="http://www.mellekoning.nl/index.php/2008/09/19/using-the-subversion-revision-graph/">branching is cool</A>. Now if you use your source code control system to the full extent like we do, then as a teamlead you will eventually end up having to inform the team about all the branching and <em>merging</em> that goes on.</p>
<p>That&#8217;s ok, but how to communicate this effectively to your team? You might try to do that by simply sending an e-mail. Like this..</p>
<blockquote><p>Hi all,</p>
<p>Kees volunteered to merge the 2.7.3 code changes (including the last 2.7.2 hotfix C changes that are in there) to the trunk. When that is finished, AND the trunk build is GREEN, only then we will create a 2.7.4 branch for the database-split. Meanwhile Henk also fixed a hot-issue on 2.7.3, which is then also to be merged to trunk (2.7.4 if it is there). And now that we are on STAGING with 2.7.3, All the fixes for 2.7.3 that will be needed are then also to be merged to both trunk / 2.7.4. Only if the 2.7.4 branch has been created, Gundi is allowed to change the trunk with all the experiences he has from the 2.8 Refactor branch, not sooner&#8230;.</p>
<p>Thanks,<br />
Melle<br />
Teamlead
</p></blockquote>
<p>Well if your team of Kees, Henk and Gundi grasp these kinds of quick e-mail notes all praise to your team but it might be better if you take the time to draw a nice diagram with that.</p>
<p><center><br />
<a href="http://www.mellekoning.nl/images/branchingPaint.png"><img src="http://www.mellekoning.nl/images/branchcomplexity.png"></a><br />
Click on image for a redrawing of this image.<br />
</center></p>
<p>Now be honest: this <em>is</em> much clearer then the email, right? </p>
<p>The above example was used in our SVN based repository, but visibility is universal. You can use it both for a centralized based repository (CVS) like subversion and a decentralized/distributed version control system (DVCS) like Git. Have a look at <a href="http://nvie.com/posts/a-successful-git-branching-model/">another beautiful explanation of the git-branching model here</a>. Visibility shows.</p>
<h3>Making branching visible to your organisation</h3>
<p>As developers we know what branching involves. We are so close to the code that we know from the top of our heads what functionality is in what branch-number. Sometimes developers even know what detailed issue-numbers are (not) in what branch. That&#8217;s all cool but we are writing the software for the entire organisation, our clients, not only ourselves. To make branching visible to your organisation it is vital to <em>use clear names for your branches</em>. Not in the version control system, but in the communication. That way it will be clear what functionality a certain branch contains. As an example:</p>
<ul>
<li>2.7.2 hotfix C &#8211; CreditCard Entry
<li>2.7.3 LowCost
<li>2.7.4 database split
</ul>
<p>As you see, we try to attach a name with the version number that marketing and brand managers <del datetime="2011-07-17T10:02:17+00:00">might</del> will understand. Especially when a release to live is done the announcement of &#8220;2.7.3 is live!&#8221; will be too cryptic. &#8220;2.7.3 LowCost is live!&#8221; at least denotes the functional meaning of the release. Of course, releases often contain more then just one new item or fix. That means that it might be hard to come up with a proper name for a certain release; just pick the main feature in that case. </p>
<p>More links about branching:<br />
Swapping release dates and thus swapping whole API changes is cumbersome. <a href="http://martinfowler.com/bliki/FeatureBranch.html">Martin Fowler has already written a very nice no-FeatureBranch article</a> about that. </p>
 <!-- RSPEAK_STOP -->]]></content:encoded>
			<wfw:commentRss>http://www.mellekoning.nl/index.php/2011/07/12/make-branching-visible-to-your-team/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Viewing dependencies with NDepend</title>
		<link>http://www.mellekoning.nl/index.php/2011/07/03/viewing-dependencies-with-ndepend/</link>
		<comments>http://www.mellekoning.nl/index.php/2011/07/03/viewing-dependencies-with-ndepend/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 20:11:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mellekoning.nl/?p=372</guid>
		<description><![CDATA[In an earlier post I already mentioned the importance of looking at the dependencies within your codebase. I used a beautifull small tool from Jamie Penney that could generate a file containing graph-information, that in turn could be used with &#8230; <a href="http://www.mellekoning.nl/index.php/2011/07/03/viewing-dependencies-with-ndepend/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- RSPEAK_STOP --> <a href='http://wr.readspeaker.com/webreader/webreader.php?cid=dd6262a4ba859cbb9032fa17f541664d&t=wordpress_free&url=http://www.mellekoning.nl/index.php/2011/07/03/viewing-dependencies-with-ndepend/&title=Viewing dependencies with NDepend' onclick='readpage(this.href, 372); return false;'> <img src='http://graphics.readspeaker.com/images/wr/listen_nl_nl.gif' style='border-style: none;' alt='Lees voor met webReader'></a><div id='WR_372'></div> <!-- RSPEAK_START --> <p>In an <a href="http://www.mellekoning.nl/index.php/2010/03/11/project-references-in-ddd/">earlier post I already mentioned the importance of looking at the dependencies within your codebase</a>. I used a beautifull small tool from Jamie Penney that could generate a file containing graph-information, that in turn could be used with the open source version of GraphViz to finally get a drawing of the project references. </p>
<p>Of course, that way of investigating your dependencies is quite cumbersome. If you need to look at dependencies for professional software, it&#8217;s time to use a professional tool like <a href="http://www.ndepend.com">NDepend</a>.</p>
<p>With NDepend you can add project assemblies by simply dragging them into the tool. For example, here is a picture that shows when I added a subset of projects from a very big framework application that we happen to use at work.</p>
<p><center><br />
<img src="http://www.mellekoning.nl/images/NDependProjectview.PNG"><br />
</center><br />
At the left are the compiled assemblies (the *.dll files) that I dragged into the NDepend project, on the right NDepend has automatically added all the assemblies where mine are depend <em>upon</em>. This includes .NET assemblies; do not worry about that though, as you can discard these automaticly added assemblies later if you do not want to include them in your investigation.</p>
<p>Pressing (F5) or <run> will start the analysis of NDepend. </p>
<p>Now viewing a graph of dependencies does not, at first, show what I want:<br />
<center><br />
<img src="http://www.mellekoning.nl/images/NdependGraphAllAssemblies.PNG"><br />
</center><br />
By default, NDepend shows -all- the assemblies that are part of the NDepend project. So, that includes the automatic added related assemblies that were added when we dragged our own assemblies into NDepend. However, going to the graph matrix view, we can change this behaviour of NDepend by selecting only the assemblies we would really like to see. Holding the shift key we select our own assemblies again:<br />
<center><br />
<img src="http://www.mellekoning.nl/images/NDependSelectOwnAssemblies.PNG"><br />
</center><br />
Now press a small button at the top of the screen to export the matrix dependencies to graph.</p>
<p><center><br />
<img src="http://www.mellekoning.nl/images/NDependExportMatrixDependenciesToGraph.PNG"><br />
</center></p>
<p>Now after we pressed the <em>&#8216;select graph</em>&#8216; button you eventually will end up with something like this:<br />
<center><br />
<img src="http://www.mellekoning.nl/images/NDependAssembliesThatuseNHibernate.PNG"><br />
</center><br />
Above is the result of right-clicking NHibernate and selecting <em>&#8216;keep only nodes that use me&#8217;</em>, which shows what assemblies are referring to NHibernate. Which turns out more then I thought, oops.</p>
<p>This way, you can actually find out what assemblies are <em>relying on your infrastructure</em>, and thus what <em>domain assemblies</em> still have to change so that those are <em>infrastructure-independent</em>.</p>
<p>Unfortunately, in the above graph there are some domain assemblies (maybe indirectly) dependent on NHibernate. The domain (like airtrade.business) should not depend on the infrastructure as that would give the <a href="http://www.udidahan.com/2007/04/23/fetching-strategy-design/">domain a reason to change if the infrastructure changes as explained by Udi Dahan in his Fetching Strategy Post</a>. </p>
<p>Not what we want. <strong>The domain should be able to change totally independent of the infrastructure</strong>. Getting out of this mess will mean trying to remove the dependency from the <em>business</em> domain assembly on NHibernate. Before that is possible, we might need to change a LOT of code&#8230; For example, as locations is also indirectly coupled with NHibernate, we might need to change code in that assembly as well before we can remove the link from business to NHibernate. Ouch! Luckily NDepend easily uses your PDB (program debug files) to enable clicking directly from NDepend into your source code! That sounds promising, doesn&#8217;t it?</p>
<p>Find out more on <a href="http://www.ndepend.com/">www.ndepend.com</a></p>
 <!-- RSPEAK_STOP -->]]></content:encoded>
			<wfw:commentRss>http://www.mellekoning.nl/index.php/2011/07/03/viewing-dependencies-with-ndepend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows7 has sticky notes!</title>
		<link>http://www.mellekoning.nl/index.php/2011/06/15/windows7-has-sticky-notes/</link>
		<comments>http://www.mellekoning.nl/index.php/2011/06/15/windows7-has-sticky-notes/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 19:36:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mellekoning.nl/?p=366</guid>
		<description><![CDATA[Fast, less memory footprint. Works faster then XP on a 8 year old Dell Dimension 2400 pentium 4 machine, has sticky notes and a snipping-tool built in. What else do you need? Windows7 is great. No additional comments&#8230;]]></description>
			<content:encoded><![CDATA[<!-- RSPEAK_STOP --> <a href='http://wr.readspeaker.com/webreader/webreader.php?cid=dd6262a4ba859cbb9032fa17f541664d&t=wordpress_free&url=http://www.mellekoning.nl/index.php/2011/06/15/windows7-has-sticky-notes/&title=Windows7 has sticky notes!' onclick='readpage(this.href, 366); return false;'> <img src='http://graphics.readspeaker.com/images/wr/listen_nl_nl.gif' style='border-style: none;' alt='Lees voor met webReader'></a><div id='WR_366'></div> <!-- RSPEAK_START --> <p><img src="/images/Windows7Capture.PNG"></p>
<p>Fast, less memory footprint. Works faster then XP on a 8 year old Dell Dimension 2400 pentium 4 machine, has sticky notes and a snipping-tool built in. What else do you need? Windows7 is great. No additional comments&#8230;</p>
 <!-- RSPEAK_STOP -->]]></content:encoded>
			<wfw:commentRss>http://www.mellekoning.nl/index.php/2011/06/15/windows7-has-sticky-notes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beautiful Code &#8211; binary search</title>
		<link>http://www.mellekoning.nl/index.php/2011/05/30/beautiful-code-binary-search/</link>
		<comments>http://www.mellekoning.nl/index.php/2011/05/30/beautiful-code-binary-search/#comments</comments>
		<pubDate>Mon, 30 May 2011 19:26:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mellekoning.nl/?p=334</guid>
		<description><![CDATA[Somewhere in chapter seven of the book Beautiful Code the following challenge is given: If you have never implemented binary search, or haven&#8217;t done so in a few years, I suggest you try that yourself before going forward; it will &#8230; <a href="http://www.mellekoning.nl/index.php/2011/05/30/beautiful-code-binary-search/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- RSPEAK_STOP --> <a href='http://wr.readspeaker.com/webreader/webreader.php?cid=dd6262a4ba859cbb9032fa17f541664d&t=wordpress_free&url=http://www.mellekoning.nl/index.php/2011/05/30/beautiful-code-binary-search/&title=Beautiful Code &#8211; binary search' onclick='readpage(this.href, 334); return false;'> <img src='http://graphics.readspeaker.com/images/wr/listen_nl_nl.gif' style='border-style: none;' alt='Lees voor met webReader'></a><div id='WR_334'></div> <!-- RSPEAK_START --> <p>Somewhere in chapter seven of the book Beautiful Code the following challenge is given:</p>
<blockquote><p>
If you have never implemented binary search, or haven&#8217;t done so in a few years, I suggest you try that yourself before going forward; it will give you greater appreciation for what follows.
</p></blockquote>
<p>Well, binary search? What was that again? Well, it is explained before the challenge is given, let&#8217;s go back and read up:</p>
<blockquote><p>As a quick refresher, a binary search is a simple and effective algorithm (but, as we’ll see, tricky to implement correctly) to determine whether a presorted array of numbers x[0..n-1] contains a target element t. If the array contains t, the program returns its position in the array; otherwise, it returns -1.</p></blockquote>
<p>That looks easy. It means that if we have an array of numbers like this:</p>
<table>
<tr>
<td>Array-index</td>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>&#8230;</td>
<td>n</td>
</tr>
<tr>
<td>Value</td>
<td>10</td>
<td>12</td>
<td>13</td>
<td>13</td>
<td>16</td>
<td>18</td>
<td>&#8230;</td>
<td>42</td>
</tr>
</table>
<p>&#8230;let&#8217;s suppose our target is 12, the algorithm should return &#8217;1&#8242; as the index-value that contains our targetvalue. If our target was 11, the algorithm to be implemented should return -1, meaning no index could be found because the value could not be found in the sorted array. The problem is easy to describe and follow, indeed.</p>
<p>On with the book, it even describes the algorithm before challenging us:</p>
<blockquote><p>
Binary search solves the problem by keeping track of the range within the array that holds t (if t is anywhere in the array). Initially, the range is the entire array. The range is shrunk by comparing its middle element to t and discarding half the range. The process continues until t is discovered in the array or until the range in which it must lie is known to be empty.</p>
<p>Most programmers think that with the above description in hand, writing the code is easy. They are wrong. The only way to believe this is by putting down this column right now and writing the code yourself. Try it.</p>
<p>If you have never implemented binary search, or haven&#8217;t done so in a few years, I suggest you try that yourself before going forward; it will give you greater appreciation for what follows.</p></blockquote>
<p>What? Not easy to implement? Of course, as an experienced programmer, I took on this challenge. But I&#8217;m warned, so I will not write the algorithm from the top-of-my head. I know that off-by-one errors can catch me, so let&#8217;s do this by using TDD. That means the first thing we do, is write a simple test that calls the (not yet written) algorithm, and checks if the algorithm works. Here we go with our  &#8216;<a href="http://en.wikipedia.org/wiki/Kata_%28programming%29">coding kata</a>&#8216;</p>
<h2>Start coding all right!</h2>
<p>With TDD, we start easy, so let&#8217;s simply start with a list of one item that holds our target.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="C#"><div class="devcodeoverflow"><ol><li> <span style="color: #008000;">&#91;</span>TestFixture<span style="color: #008000;">&#93;</span></li><li> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> BinarySearchTest</li><li> <span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp; <span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li>&nbsp;&nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> OneItem_TargetExists_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp; <span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// this is our target</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;sortedArray<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> targetValue<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// set value of first item to our target</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Execute</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, targetIndex, <span style="color: #666666;">&quot;0 should have been the result!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp; <span style="color: #008000;">&#125;</span></li><li><span style="color: #008000;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>The first implementation of MyBinarySearch is easy. With TDD, we keep our code as simple as possible to pass the test:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="C#"><div class="devcodeoverflow"><ol><li><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyBinarySearch</li><li><span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> Execute<span style="color: #008000;">&#40;</span>List<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&gt;</span> arrayList, <span style="color: #6666cc; font-weight: bold;">int</span> targetValue<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// just return the first index as result</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li><span style="color: #008000;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Well, in this case the code is too simple, that did not really do much as we did not even used the inserted array or even the targetValue at all! But that&#8217;s how we do it with TDD: start easy. The test is green, so let&#8217;s also add another test and refactor the code if necessary:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="C#"><div class="devcodeoverflow"><ol><li><span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> OneItem_TargetDoesNotExists_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li><span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp; <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray&nbsp;&nbsp;<span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// this is our target</span></li><li>&nbsp;&nbsp; sortedArray<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// value will not be found </span></li><li>&nbsp;&nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Execute</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp; Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">1</span>, targetIndex, <span style="color: #666666;">&quot;-1 should have been the result!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li><span style="color: #008000;">&#125;</span></li><li>&nbsp;</li><li><span style="color: #008080; font-style: italic;">// running the above test results in a failure, so we</span></li><li><span style="color: #008080; font-style: italic;">// refactor.</span></li><li><span style="color: #008080; font-style: italic;">// We need to change the binarySearch class,</span></li><li><span style="color: #008080; font-style: italic;">// to support the case for not-found:</span></li><li><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyBinarySearch</li><li><span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> Execute<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray, <span style="color: #6666cc; font-weight: bold;">int</span> targetValue<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sortedArray<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">==</span> targetValue<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>&nbsp;&nbsp;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// target not found</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li><span style="color: #008000;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>This still works, the value is either found or not-found, so it&#8217;s time to add some more tests! Let&#8217;s start by adding two tests that have lists of more then just one item. We keep it simple and add two tests with just two items:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="C#"><div class="devcodeoverflow"><ol><li></li><li><span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> TwoItems_TargetExists_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li><span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp; <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <span style="color: #FF0000;">10</span>, <span style="color: #FF0000;">20</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// this is our target</span></li><li>&nbsp;&nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp; Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span>, targetIndex, <span style="color: #666666;">&quot;index 1 should have been the result!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li><span style="color: #008000;">&#125;</span></li><li>&nbsp;</li><li><span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> TwoItems_TargetDoesNotExists_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li><span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp; <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">&#123;</span> <span style="color: #FF0000;">10</span>, <span style="color: #FF0000;">20</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// this is our target</span></li><li>&nbsp;&nbsp; <span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp; Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">1</span>, targetIndex, <span style="color: #666666;">&quot;-1 should have been the result!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li><span style="color: #008000;">&#125;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Ok, this is great. Both of these new tests will fail for sure! As you see, I have already prepared to go to a different Entry method, called.. Entry, instead of Execute. This is because our current BinarySearch class only works for lists of one item. Eventually, we have to do something smart anyway, and we already know that we have to dive deep because we need some kind of recursion, so that is why I want to enter the BinarySearch class with a different Entry method.</p>
<p>Let&#8217;s also add a third new test that actually uses an array of 100 items, and we want to find one target, something like this:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="C#"><div class="devcodeoverflow"><ol><li></li><li>&nbsp;&nbsp; <span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> HundredItems_TargetExists_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">100</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">for</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i<span style="color: #008000;">=</span><span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>i<span style="color: #008000;">&lt;=</span><span style="color: #FF0000;">99</span><span style="color: #008000;">;</span>i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sortedArray<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> i<span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">39</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">39</span>, targetIndex, <span style="color: #666666;">&quot;Expected to find the target at index 39&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>This last added test will also fail with the current code, and just adding alot of if-statements in the MyBinarySearch class won&#8217;t work either. We will really need a recursive method before continuing.</p>
<h2>Writing a recursive method to zoom-in</h2>
<p>So how to write a recursive method? With recursion, we usually have an entry-method and the recursive method itself that is called from the Entry-method. As the description of binarySearch explains, the recursive method should &#8216;zoom-in&#8217; into the sub-range of the array where the targetValue should be. To keep track of the subRange, we must have markers that tell us what is the lower-end of the subRange, as well as the higher-end of the subrange. </p>
<p>Also, a recursive method always needs a stop-condition, or else we might end up with an indefinite loop&#8230;let&#8217;s rewrite the MyBinarySearch class, and after that re-run all of the tests! People who have never seen a recursive method, one that calls into itself, might feel a little awkard reading the next code-bit, but the ones that have already written some recursive methods will not be too surprised with the following first try&#8230;.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="C#"><div class="devcodeoverflow"><ol><li></li><li><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyBinarySearch</li><li><span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> Entry<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray, <span style="color: #6666cc; font-weight: bold;">int</span> targetValue<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// determine low and high</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> low <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> high <span style="color: #008000;">=</span> sortedArray<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">return</span> SearchTarget<span style="color: #008000;">&#40;</span>sortedArray, targetValue, low, high<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// recursive method:</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// the return is the index of the targetvalue we search for,</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// or -1 if the targetvalue is not found</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> SearchTarget<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray, <span style="color: #6666cc; font-weight: bold;">int</span> targetValue, <span style="color: #6666cc; font-weight: bold;">int</span> low, <span style="color: #6666cc; font-weight: bold;">int</span> high<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// stop condition.. we re-use the earlier code of the Execute method:</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>high <span style="color: #008000;">&lt;=</span> low<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// range has shortened to (almost?) nothing:</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sortedArray<span style="color: #008000;">&#91;</span>low<span style="color: #008000;">&#93;</span> <span style="color: #008000;">==</span> targetValue<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">return</span> low<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// index found!</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// target not found</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// high &gt; low means we can cut the range in half</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// but what half? the peakpoint should be the middle of low and high:</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> currentPeakPoint <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>high <span style="color: #008000;">-</span> low<span style="color: #008000;">&#41;</span><span style="color: #008000;">/</span><span style="color: #FF0000;">2</span> <span style="color: #008000;">+</span> low<span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sortedArray<span style="color: #008000;">&#91;</span>currentPeakPoint<span style="color: #008000;">&#93;</span> <span style="color: #008000;">&lt;</span> targetValue<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// we must search upper half:</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;low <span style="color: #008000;">=</span> currentPeakPoint<span style="color: #008000;">;</span> </li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">return</span> SearchTarget<span style="color: #008000;">&#40;</span>sortedArray, targetValue, low, high<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">else</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// we must search lower half:</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;high <span style="color: #008000;">=</span> currentPeakPoint<span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">return</span> SearchTarget<span style="color: #008000;">&#40;</span>sortedArray, targetValue, low, high<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// I do not expect we will ever get here:</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;something went wrong!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Ok, above is a first try. Of course, all tests need to be changed, they should now call the Entry() method instead of the Execute() method, that in turn will call the recursive method SearchTarget()&#8230;</p>
<p>So, I run the tests&#8230; but when I run my tests, I got a stack-overflow exception for the TwoItems_TargetExists_Success() test! How on earth did that happen?</p>
<p>Let&#8217;s debug&#8230; The code was continuously trying for the subRange 0..1, and again, 0..1, and again 0..1, the low-high-range was not altered at all. low did not get higher then 0, and high did not get lower then 1. in other words, &#8216;low&#8217; was never increased. So the easiest thing to fix this is what I did below: I changed that one line of code from:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="C#"><div class="devcodeoverflow"><ol><li></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;low <span style="color: #008000;">=</span> currentPeakPoint<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// &lt;-- goes wrong</span></li><li><span style="color: #008080; font-style: italic;">// to</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;low <span style="color: #008000;">=</span> currentPeakPoint<span style="color: #008000;">+</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> </li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>And also added some debugging statements to see what was actually happening in the recursive loop, and found that I could refactor the internal call to SearchTarget at the end of the method a bit. It is not needed to call it in both the internal if&#8230;else.. branches, one time at the end is good enough. I ended up with the following recursive method:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="C#"><div class="devcodeoverflow"><ol><li></li><li> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">int</span> SearchTarget<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray, <span style="color: #6666cc; font-weight: bold;">int</span> targetValue, <span style="color: #6666cc; font-weight: bold;">int</span> low, <span style="color: #6666cc; font-weight: bold;">int</span> high<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;target {0}, low {1}, high {2}&quot;</span>,targetValue,low,high<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// stop condition</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>high <span style="color: #008000;">&lt;=</span> low<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sortedArray<span style="color: #008000;">&#91;</span>low<span style="color: #008000;">&#93;</span> <span style="color: #008000;">==</span> targetValue<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">return</span> low<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// index found!</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;target {0} does not match value {1} at index {2}&quot;</span>, targetValue, sortedArray<span style="color: #008000;">&#91;</span>low<span style="color: #008000;">&#93;</span>, low<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// target not found</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// high &gt; low means we can cut the range in half</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// but what half? the peakpoint should be the middle of low and high:</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> currentPeakPoint <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>high <span style="color: #008000;">-</span> low<span style="color: #008000;">&#41;</span><span style="color: #008000;">/</span><span style="color: #FF0000;">2</span> <span style="color: #008000;">+</span> low<span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Peaking at:{0}&quot;</span>,currentPeakPoint<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>sortedArray<span style="color: #008000;">&#91;</span>currentPeakPoint<span style="color: #008000;">&#93;</span> <span style="color: #008000;">&lt;</span> targetValue<span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// we must search upper half:</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;low <span style="color: #008000;">=</span> currentPeakPoint <span style="color: #008000;">+</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// this +1`I did not have at first.</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">else</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008080; font-style: italic;">// we must search lower half:</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;high <span style="color: #008000;">=</span> currentPeakPoint<span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">return</span> SearchTarget<span style="color: #008000;">&#40;</span>sortedArray, targetValue, low, high<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>And, all tests green!</p>
<h2>Even more tests!</h2>
<p>Of course, I added more tests, this time real tests with larger lists, edge-cases, values that are outside the bounds of the sorted-array&#8230; just to be sure the method I wrote worked. But the additional tests never broke the code. I present all the other tests that I wrote here just for completeness-sake&#8230;</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="C#"><div class="devcodeoverflow"><ol><li></li><li>&nbsp;&nbsp; <span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> HundredItems_TargetExists_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">100</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">for</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i<span style="color: #008000;">=</span><span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>i<span style="color: #008000;">&lt;=</span><span style="color: #FF0000;">99</span><span style="color: #008000;">;</span>i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sortedArray<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> i<span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">39</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">39</span>, targetIndex, <span style="color: #666666;">&quot;Expected to find the target at index 39&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> HundredItems_TargetDoesNotExists_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">100</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">99</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sortedArray<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> i<span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">139</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">1</span>, targetIndex, <span style="color: #666666;">&quot;Expected to not find the target&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> UnEvenItems_TargetExists_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">99</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">98</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sortedArray<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> i<span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">50</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span>sortedArray<span style="color: #008000;">&#91;</span>targetIndex<span style="color: #008000;">&#93;</span>, targetValue, <span style="color: #666666;">&quot;Expected to find the target&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> HundredItems_TargetDoesNotExists_ButWithinRange_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">100</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">99</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sortedArray<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> i<span style="color: #008000;">*</span><span style="color: #FF0000;">2</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">139</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">1</span>, targetIndex, <span style="color: #666666;">&quot;Expected to not find the target&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;</li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> TenThousandItems_TargetExists_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">10000</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">9999</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sortedArray<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> i <span style="color: #008000;">*</span> <span style="color: #FF0000;">3</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">1234</span><span style="color: #008000;">*</span><span style="color: #FF0000;">3</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span>sortedArray<span style="color: #008000;">&#91;</span>targetIndex<span style="color: #008000;">&#93;</span>,targetValue, <span style="color: #666666;">&quot;Expected to find the target&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> EdgeTargetLow_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">100</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">99</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sortedArray<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> i <span style="color: #008000;">*</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span>sortedArray<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span>, targetValue, <span style="color: #666666;">&quot;Expected to find the target&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> EdgeTargetHigh_Success<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">100</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">99</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sortedArray<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> i <span style="color: #008000;">*</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">99</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span>sortedArray<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">99</span><span style="color: #008000;">&#93;</span>, targetValue, <span style="color: #666666;">&quot;Expected to find the target&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> TargetBelowLowest_DoesNotExist<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">100</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">99</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sortedArray<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> i <span style="color: #008000;">*</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span>targetIndex,<span style="color: #008000;">-</span><span style="color: #FF0000;">1</span>, <span style="color: #666666;">&quot;Expected to not find the target&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#91;</span>Test<span style="color: #008000;">&#93;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> TargetAboveHighest_DoesNotExist<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> sortedArray <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">100</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">99</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#123;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sortedArray<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> i <span style="color: #008000;">*</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetValue <span style="color: #008000;">=</span> <span style="color: #FF0000;">99</span><span style="color: #008000;">*</span><span style="color: #FF0000;">2</span><span style="color: #008000;">+</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #6666cc; font-weight: bold;">int</span> targetIndex <span style="color: #008000;">=</span> MyBinarySearch<span style="color: #008000;">.</span><span style="color: #0000FF;">Entry</span><span style="color: #008000;">&#40;</span>sortedArray, targetValue<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span>targetIndex, <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span>, <span style="color: #666666;">&quot;Expected to not find the target&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000;">&#125;</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>And as an example, the satisfying output from the 10.000 search:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="C#"><div class="devcodeoverflow"><ol><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">0</span>, high <span style="color: #FF0000;">9999</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">4999</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">0</span>, high <span style="color: #FF0000;">4999</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">2499</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">0</span>, high <span style="color: #FF0000;">2499</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">1249</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">0</span>, high <span style="color: #FF0000;">1249</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">624</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">625</span>, high <span style="color: #FF0000;">1249</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">937</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">938</span>, high <span style="color: #FF0000;">1249</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">1093</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">1094</span>, high <span style="color: #FF0000;">1249</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">1171</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">1172</span>, high <span style="color: #FF0000;">1249</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">1210</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">1211</span>, high <span style="color: #FF0000;">1249</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">1230</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">1231</span>, high <span style="color: #FF0000;">1249</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">1240</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">1231</span>, high <span style="color: #FF0000;">1240</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">1235</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">1231</span>, high <span style="color: #FF0000;">1235</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">1233</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">1234</span>, high <span style="color: #FF0000;">1235</span></li><li>Peaking at<span style="color: #008000;">:</span><span style="color: #FF0000;">1234</span></li><li>target <span style="color: #FF0000;">3702</span>, low <span style="color: #FF0000;">1234</span>, high <span style="color: #FF0000;">1234</span></li><li></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>With these tests, I&#8217;m pretty confident I was succesfull to the challenge I got from the book, and I&#8217;m happy to read on in Beautiful code&#8230;</p>
<h2>After reading the chapter</h2>
<p>I must say I was rather dissapointed. The presented solution was not using a recursive loop at all, but a for loop instead. While recursion is so elegant as you don&#8217;t need to take care of a stack yourself&#8230; oh well..<br />
must say that except for a few chapters, the rest of the 30 chapters of the book were not that gleaming either. Most of the chapters are clearly from developers  who are very proud of their code; that&#8217;s ok, but did they always keep their reader in mind?  </p>
<p>And with this blog-article, you also have my review about the contents of the book&#8230; decide for yourselves! <a href="http://www.amazon.com/gp/product/0596510047/ref=as_li_tf_tl?ie=UTF8&#038;tag=wwwmellekonin-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399353&#038;creativeASIN=0596510047">Beautiful Code: Leading Programmers Explain How They Think (Theory in Practice (O&#8217;Reilly))</a><img src="http://www.assoc-amazon.com/e/ir?t=wwwmellekonin-20&#038;l=as2&#038;o=1&#038;a=0596510047&#038;camp=217145&#038;creative=399349" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /><label id=showTextCategoryLinkPreview_l1> (See all </label><a href="http://www.amazon.com/General-Programming-Computers-Internet-Books/b/ref=as_li_tf_tl?ie=UTF8&#038;tag=wwwmellekonin-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399357&#038;creativeASIN=0596510047&#038;ie=UTF8&#038;node=171114">Computer Programmer Books</a>)<img src="http://www.assoc-amazon.com/e/ir?t=wwwmellekonin-20&#038;l=as2&#038;o=1&#038;a=0596510047&#038;camp=217145&#038;creative=399357" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></p>
 <!-- RSPEAK_STOP -->]]></content:encoded>
			<wfw:commentRss>http://www.mellekoning.nl/index.php/2011/05/30/beautiful-code-binary-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

