<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Alexey Online - Development</title>
    <link>http://www.alexeyonline.com/Blog/</link>
    <description>To Blog or not to Blog? This is my answer!</description>
    <language>en-us</language>
    <copyright>Alexey Kouzmitch</copyright>
    <lastBuildDate>Fri, 16 Jan 2009 22:01:23 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.7174.0</generator>
    <managingEditor>arexey@gmail.com</managingEditor>
    <webMaster>arexey@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.alexeyonline.com/Blog/Trackback.aspx?guid=4f7db646-d7df-4f60-b6ea-1b29f7eb5fc0</trackback:ping>
      <pingback:server>http://www.alexeyonline.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.alexeyonline.com/Blog/PermaLink,guid,4f7db646-d7df-4f60-b6ea-1b29f7eb5fc0.aspx</pingback:target>
      <dc:creator>Alexey Kouzmitch</dc:creator>
      <wfw:comment>http://www.alexeyonline.com/Blog/CommentView,guid,4f7db646-d7df-4f60-b6ea-1b29f7eb5fc0.aspx</wfw:comment>
      <wfw:commentRss>http://www.alexeyonline.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=4f7db646-d7df-4f60-b6ea-1b29f7eb5fc0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I use Visual Studio 2008 in combination with MSTest to do Test Driven Development.
One of the most important and frequent tasks when practicing TDD is running your tests.
Much has been said about NUnit’s better fit with TDD (in great part due to their standalone
test runner that simply re-runs all your tests when the assembly is rebuilt), but
it doesn’t have to be as bad as it may be out of the box with only a few tricks and
tweaks to Visual Studio.
</p>
        <p>
Firstly, it’s extremely important to know your keyboard shortcuts. It always amazes
me when I see developers write a whole bunch of code using both hands on the keyboard
and then reach for the mouse to click the green Play button to run it. Ctrl-F5 runs
your code, F5 debugs it; it’s that simple. With TDD, however, there is another step
between writing and running your code. It is running your tests. Visual Studio’s approach
to test management is very QA oriented, but it does have the simpler commands for
running tests within the current context as well as ALL tests and they have keyboard
shortcuts defined by default. Here they are and they all perform a build first if
necessary as well:
</p>
        <table border="1" cellspacing="0" cellpadding="2" width="400">
          <tbody>
            <tr>
              <td valign="top" width="200">
                <strong>Shortcut</strong>
              </td>
              <td valign="top" width="200">
                <strong>Command</strong>
              </td>
            </tr>
            <tr>
              <td valign="top" width="200">
Ctrl-R A</td>
              <td valign="top" width="200">
Run all Tests</td>
            </tr>
            <tr>
              <td valign="top" width="200">
Ctrl-R T</td>
              <td valign="top" width="200">
Run Tests in Current Context</td>
            </tr>
            <tr>
              <td valign="top" width="200">
Ctrl-R Ctrl-A</td>
              <td valign="top" width="200">
Debug all Tests</td>
            </tr>
            <tr>
              <td valign="top" width="200">
Ctrl-R Ctrl-T</td>
              <td valign="top" width="200">
Debug Tests in Current Context</td>
            </tr>
          </tbody>
        </table>
        <br />
        <p>
          <em>Note that these in fact are keystroke macros and mean that you first press Ctrl-R
and then press A by itself.</em>
        </p>
        <p>
Sometimes, a complete rebuild is required to flush old binary artifacts and this by
default requires going into the menus. Ctrl-Shift-B shortcut builds the solution so
I find it useful to map Ctrl-Alt-Shift-B to the Rebuild Solution command. You can
do this easily from the Tools-&gt;Options Menu:
</p>
        <p>
          <a href="http://www.alexeyonline.com/Blog/content/binary/WindowsLiveWriter/VSTestRunnerTDDTricks_C5D4/image_6.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Bind Rebuild Solution Command in Options Dialog" border="0" alt="Bind Rebuild Solution Command in Options Dialog" src="http://www.alexeyonline.com/Blog/content/binary/WindowsLiveWriter/VSTestRunnerTDDTricks_C5D4/image_thumb_2.png" width="244" height="143" />
          </a>
          <br />
          <em>Click to enlarge</em>
        </p>
        <p>
Finally, the test-runner window could become cluttered with test results once the
number of tests increases significantly. This makes finding the failed test somewhat
painful. If you look at the 4 possible Result values for the tests—Pending, In Progress,
Failed, and Passed—you may notice that all but Passed have an ‘i’ in them and we only
care about tests that don’t pass. So if you filter the Test Result window to only
show tests with an ‘i’ in the Result you get a list of all tests in Progress or Pending
but which filters out the successful tests and leaves only the Failed ones behind
after the test run is done.
</p>
        <p>
          <a href="http://www.alexeyonline.com/Blog/content/binary/WindowsLiveWriter/VSTestRunnerTDDTricks_C5D4/image_8.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.alexeyonline.com/Blog/content/binary/WindowsLiveWriter/VSTestRunnerTDDTricks_C5D4/image_thumb_3.png" width="244" height="46" />
          </a>
          <br />
          <em>Click to enlarge</em>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
Unfortunately, the filter setting doesn’t stick between VS restarts and you have to
repeat the process but it’s quick and simple.
</p>
        <p>
With these settings I find writing and running tests a breeze in Visual Studio. 
These suggestions will work in Visual Studio 2005 as well although VS 2005 test runner’s
performance issues are a mroe difficult issue to overcome.
</p>
        <img width="0" height="0" src="http://www.alexeyonline.com/Blog/aggbug.ashx?id=4f7db646-d7df-4f60-b6ea-1b29f7eb5fc0" />
      </body>
      <title>Visual Studio Test Runner Tricks for Test Driven Development</title>
      <guid isPermaLink="false">http://www.alexeyonline.com/Blog/PermaLink,guid,4f7db646-d7df-4f60-b6ea-1b29f7eb5fc0.aspx</guid>
      <link>http://www.alexeyonline.com/Blog/2009/01/16/VisualStudioTestRunnerTricksForTestDrivenDevelopment.aspx</link>
      <pubDate>Fri, 16 Jan 2009 22:01:23 GMT</pubDate>
      <description>&lt;p&gt;
I use Visual Studio 2008 in combination with MSTest to do Test Driven Development.
One of the most important and frequent tasks when practicing TDD is running your tests.
Much has been said about NUnit’s better fit with TDD (in great part due to their standalone
test runner that simply re-runs all your tests when the assembly is rebuilt), but
it doesn’t have to be as bad as it may be out of the box with only a few tricks and
tweaks to Visual Studio.
&lt;/p&gt;
&lt;p&gt;
Firstly, it’s extremely important to know your keyboard shortcuts. It always amazes
me when I see developers write a whole bunch of code using both hands on the keyboard
and then reach for the mouse to click the green Play button to run it. Ctrl-F5 runs
your code, F5 debugs it; it’s that simple. With TDD, however, there is another step
between writing and running your code. It is running your tests. Visual Studio’s approach
to test management is very QA oriented, but it does have the simpler commands for
running tests within the current context as well as ALL tests and they have keyboard
shortcuts defined by default. Here they are and they all perform a build first if
necessary as well:
&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="2" width="400"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
&lt;strong&gt;Shortcut&lt;/strong&gt;&lt;/td&gt;
&lt;td valign="top" width="200"&gt;
&lt;strong&gt;Command&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
Ctrl-R A&lt;/td&gt;
&lt;td valign="top" width="200"&gt;
Run all Tests&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
Ctrl-R T&lt;/td&gt;
&lt;td valign="top" width="200"&gt;
Run Tests in Current Context&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
Ctrl-R Ctrl-A&lt;/td&gt;
&lt;td valign="top" width="200"&gt;
Debug all Tests&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="200"&gt;
Ctrl-R Ctrl-T&lt;/td&gt;
&lt;td valign="top" width="200"&gt;
Debug Tests in Current Context&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;br&gt;
&lt;p&gt;
&lt;em&gt;Note that these in fact are keystroke macros and mean that you first press Ctrl-R
and then press A by itself.&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
Sometimes, a complete rebuild is required to flush old binary artifacts and this by
default requires going into the menus. Ctrl-Shift-B shortcut builds the solution so
I find it useful to map Ctrl-Alt-Shift-B to the Rebuild Solution command. You can
do this easily from the Tools-&amp;gt;Options Menu:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.alexeyonline.com/Blog/content/binary/WindowsLiveWriter/VSTestRunnerTDDTricks_C5D4/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Bind Rebuild Solution Command in Options Dialog" border="0" alt="Bind Rebuild Solution Command in Options Dialog" src="http://www.alexeyonline.com/Blog/content/binary/WindowsLiveWriter/VSTestRunnerTDDTricks_C5D4/image_thumb_2.png" width="244" height="143"&gt;&lt;/a&gt; 
&lt;br&gt;
&lt;em&gt;Click to enlarge&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
Finally, the test-runner window could become cluttered with test results once the
number of tests increases significantly. This makes finding the failed test somewhat
painful. If you look at the 4 possible Result values for the tests—Pending, In Progress,
Failed, and Passed—you may notice that all but Passed have an ‘i’ in them and we only
care about tests that don’t pass. So if you filter the Test Result window to only
show tests with an ‘i’ in the Result you get a list of all tests in Progress or Pending
but which filters out the successful tests and leaves only the Failed ones behind
after the test run is done.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.alexeyonline.com/Blog/content/binary/WindowsLiveWriter/VSTestRunnerTDDTricks_C5D4/image_8.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.alexeyonline.com/Blog/content/binary/WindowsLiveWriter/VSTestRunnerTDDTricks_C5D4/image_thumb_3.png" width="244" height="46"&gt;&lt;/a&gt; 
&lt;br&gt;
&lt;em&gt;Click to enlarge&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Unfortunately, the filter setting doesn’t stick between VS restarts and you have to
repeat the process but it’s quick and simple.
&lt;/p&gt;
&lt;p&gt;
With these settings I find writing and running tests a breeze in Visual Studio.&amp;nbsp;
These suggestions will work in Visual Studio 2005 as well although VS 2005 test runner’s
performance issues are a mroe difficult issue to overcome.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.alexeyonline.com/Blog/aggbug.ashx?id=4f7db646-d7df-4f60-b6ea-1b29f7eb5fc0" /&gt;</description>
      <comments>http://www.alexeyonline.com/Blog/CommentView,guid,4f7db646-d7df-4f60-b6ea-1b29f7eb5fc0.aspx</comments>
      <category>Development</category>
      <category>TDD</category>
      <category>Technical</category>
    </item>
    <item>
      <trackback:ping>http://www.alexeyonline.com/Blog/Trackback.aspx?guid=de1eb9e8-8394-4359-ae72-228818ea101e</trackback:ping>
      <pingback:server>http://www.alexeyonline.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.alexeyonline.com/Blog/PermaLink,guid,de1eb9e8-8394-4359-ae72-228818ea101e.aspx</pingback:target>
      <dc:creator>Alexey Kouzmitch</dc:creator>
      <wfw:comment>http://www.alexeyonline.com/Blog/CommentView,guid,de1eb9e8-8394-4359-ae72-228818ea101e.aspx</wfw:comment>
      <wfw:commentRss>http://www.alexeyonline.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=de1eb9e8-8394-4359-ae72-228818ea101e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am playing around with the <a href="http://creators.xna.com" target="_blank">XNA
Framework</a> and in the process of writing a game, I need to perform in essence a
graph traversal. Given a 3D board (of w x h x d cells), I need to from a starting
position and "up" direction to go around the board and figure out all reachable locations.
So If you have a cube in space and you start on one of the faces, I need to get all
cells on the surface of the cube. It gets a bit more complicated once you throw in
rules like "you can't traverse through walls" and "if you reach an edge, you in essence
go over it and rotate" (sort of like going around the globe, but around a cube...
if that makes sense).
</p>
        <p>
Anyway... I am trying to do as much Test Driven Development as possible and this problem
got me thinking. It's nothing new to write some code that will iterate through a graph,
keeping track of visited cells and figuring out others, but I was trying to figure
out how to do this in a testable manner without exposing all kinds of internals about
the traversal class. After all, if it's private, it's an implementation detail. But
I needed to say "do one pass and show me the node list" type of thing. So I decided
to use .Net 2.0 iterator method instead. It allows you to create a function that returns
an IEnumerable&lt;T&gt; and the iterate over the results within a foreach loop. Within
the method you can use yield return statements to return values as they are generated
and the method execution will continue with IEnumerable&lt;T&gt;.MoveNext() method
is called. When there are no more results to return, a yield break statement is used
to end the iteration process.
</p>
        <p>
Here's what a method that returns nothing looks like.
</p>
        <pre class="code">
          <span style="color: rgb(0,0,255)">internal</span>
          <span style="color: rgb(43,145,175)">IEnumerable</span>&lt;<span style="color: rgb(43,145,175)">StarLocationInfo</span>&gt;
GetStarLocations() { <span style="color: rgb(0,0,255)">yield</span><span style="color: rgb(0,0,255)">break</span>;
}</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
As I progressed through writing various tests, I could simulate conditions such as
"when on a plane, return the current position and four children next to it". In the
spirit of TDD it could look something like this:
</p>
        <p>
        <span style="color: rgb(0,0,255)">internal</span><span style="color: rgb(43,145,175)">IEnumerable</span>&lt;<span style="color: rgb(43,145,175)">StarLocationInfo</span>&gt;
GetStarLocations()<br />
        {<br />
            <span style="color: rgb(0,0,255)">yield</span><span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">StarLocationInfo</span>(startPosition);<br />
            <span style="color: rgb(0,0,255)">yield</span><span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">StarLocationInfo</span>(startPosition
+ <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Vector3</span>(1,
0, 0));<br />
            <span style="color: rgb(0,0,255)">yield</span><span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">StarLocationInfo</span>(startPosition
+ <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Vector3</span>(0,
1, 0));<br />
            <span style="color: rgb(0,0,255)">yield</span><span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">StarLocationInfo</span>(startPosition
+ <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Vector3</span>(-1,
0, 0));<br />
            <span style="color: rgb(0,0,255)">yield</span><span style="color: rgb(0,0,255)">return</span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">StarLocationInfo</span>(startPosition
+ <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Vector3</span>(0,
-1, 0));<br />
            <span style="color: rgb(0,0,255)">yield</span><span style="color: rgb(0,0,255)">break</span>;<br />
        }
</p>
        <p>
So all of this allowed me to write tests like this:
</p>
        <pre class="code">        [<span style="color: rgb(43,145,175)">Test</span>] <span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,255)">void</span> OnPlaneFourChildrenAreReturned()
{ <span style="color: rgb(43,145,175)">GameBoard</span> testBoard = CreatePlane(); <span style="color: rgb(43,145,175)">GameBoardStarTraverser</span> traverser
= <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">GameBoardStarTraverser</span>(testBoard, <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Vector3</span>(2,
2, 0), <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">Vector3</span>(0,
0, -1)); <span style="color: rgb(43,145,175)">List</span>&lt;<span style="color: rgb(43,145,175)">StarLocationInfo</span>&gt;
expectedList = <span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">List</span>&lt;<span style="color: rgb(43,145,175)">StarLocationInfo</span>&gt;(5);
expectedList.Add(<span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">StarLocationInfo</span>(2,
2, 0)); expectedList.Add(<span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">StarLocationInfo</span>(1,
2, 0)); expectedList.Add(<span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">StarLocationInfo</span>(3,
2, 0)); expectedList.Add(<span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">StarLocationInfo</span>(2,
1, 0)); expectedList.Add(<span style="color: rgb(0,0,255)">new</span><span style="color: rgb(43,145,175)">StarLocationInfo</span>(2,
3, 0)); RunTraversalAndVerifyExpectations(traverser, expectedList); }</pre>
        <a href="http://11011.net/software/vspaste">
        </a>
        <p>
where the last function basically runs through the results of traverser.GetStartLocations()
with a foreach loop and removes items from the expected list as it gets them from
the enumerator. It also makes sure that all of the expected values were recorded.
</p>
        <p>
In the end I ended up with a traversal algorithm that much resembles a typical graph
traversal (its breadth first) and all of its details hidden away in a iterative method,
yet I can test its behavior by setting the start conditions and essentially inspect
its results as they come out. To sum up:
</p>
        <ul>
          <li>
I was able to use TDD methods to drive the behavior of the algorithm 
</li>
          <li>
I kept the details of the implementation hidden, since all it takes to invoke the
"traverser" is a single function call. 
</li>
          <li>
I used a neat feature of .Net 2.0.</li>
        </ul>
        <p>
Note: this can be done with .Net 1.1 of course, but it's not as neat as one would
need to implement both an IEnumerable and IEnumerator interfaces in a couple of classes.
</p>
        <img width="0" height="0" src="http://www.alexeyonline.com/Blog/aggbug.ashx?id=de1eb9e8-8394-4359-ae72-228818ea101e" />
      </body>
      <title>TDD a graph traversal algorithm</title>
      <guid isPermaLink="false">http://www.alexeyonline.com/Blog/PermaLink,guid,de1eb9e8-8394-4359-ae72-228818ea101e.aspx</guid>
      <link>http://www.alexeyonline.com/Blog/2007/11/08/TDDAGraphTraversalAlgorithm.aspx</link>
      <pubDate>Thu, 08 Nov 2007 05:40:31 GMT</pubDate>
      <description>&lt;p&gt;
I am playing around with the &lt;a href="http://creators.xna.com" target="_blank"&gt;XNA
Framework&lt;/a&gt; and in the process of writing a game, I need to perform in essence a
graph traversal. Given a 3D board (of w x h x d cells), I need to from a starting
position and "up" direction to go around the board and figure out all reachable locations.
So If you have a cube in space and you start on one of the faces, I need to get all
cells on the surface of the cube. It gets a bit more complicated once you throw in
rules like "you can't traverse through walls" and "if you reach an edge, you in essence
go over it and rotate" (sort of like going around the globe, but around a cube...
if that makes sense).
&lt;/p&gt;
&lt;p&gt;
Anyway... I am trying to do as much Test Driven Development as possible and this problem
got me thinking. It's nothing new to write some code that will iterate through a graph,
keeping track of visited cells and figuring out others, but I was trying to figure
out how to do this in a testable manner without exposing all kinds of internals about
the traversal class. After all, if it's private, it's an implementation detail. But
I needed to say "do one pass and show me the node list" type of thing. So I decided
to use .Net 2.0 iterator method instead. It allows you to create a function that returns
an IEnumerable&amp;lt;T&amp;gt; and the iterate over the results within a foreach loop. Within
the method you can use yield return statements to return values as they are generated
and the method execution will continue with IEnumerable&amp;lt;T&amp;gt;.MoveNext() method
is called. When there are no more results to return, a yield break statement is used
to end the iteration process.
&lt;/p&gt;
&lt;p&gt;
Here's what a method that returns nothing looks like.
&lt;/p&gt;
&lt;pre class="code"&gt;        &lt;span style="color: rgb(0,0,255)"&gt;internal&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;&amp;gt;
GetStarLocations() { &lt;span style="color: rgb(0,0,255)"&gt;yield&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;break&lt;/span&gt;;
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
As I progressed through writing various tests, I could simulate conditions such as
"when on a plane, return the current position and four children next to it". In the
spirit of TDD it could look something like this:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;internal&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;&amp;gt;
GetStarLocations()&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;yield&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;(startPosition);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;yield&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;(startPosition
+ &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Vector3&lt;/span&gt;(1,
0, 0));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;yield&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;(startPosition
+ &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Vector3&lt;/span&gt;(0,
1, 0));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;yield&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;(startPosition
+ &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Vector3&lt;/span&gt;(-1,
0, 0));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;yield&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;(startPosition
+ &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Vector3&lt;/span&gt;(0,
-1, 0));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: rgb(0,0,255)"&gt;yield&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;break&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
So all of this allowed me to write tests like this:
&lt;/p&gt;
&lt;pre class="code"&gt;        [&lt;span style="color: rgb(43,145,175)"&gt;Test&lt;/span&gt;] &lt;span style="color: rgb(0,0,255)"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0,0,255)"&gt;void&lt;/span&gt; OnPlaneFourChildrenAreReturned()
{ &lt;span style="color: rgb(43,145,175)"&gt;GameBoard&lt;/span&gt; testBoard = CreatePlane(); &lt;span style="color: rgb(43,145,175)"&gt;GameBoardStarTraverser&lt;/span&gt; traverser
= &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;GameBoardStarTraverser&lt;/span&gt;(testBoard, &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Vector3&lt;/span&gt;(2,
2, 0), &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Vector3&lt;/span&gt;(0,
0, -1)); &lt;span style="color: rgb(43,145,175)"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;&amp;gt;
expectedList = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;&amp;gt;(5);
expectedList.Add(&lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;(2,
2, 0)); expectedList.Add(&lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;(1,
2, 0)); expectedList.Add(&lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;(3,
2, 0)); expectedList.Add(&lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;(2,
1, 0)); expectedList.Add(&lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StarLocationInfo&lt;/span&gt;(2,
3, 0)); RunTraversalAndVerifyExpectations(traverser, expectedList); }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; 
&lt;p&gt;
where the last function basically runs through the results of traverser.GetStartLocations()
with a foreach loop and removes items from the expected list as it gets them from
the enumerator. It also makes sure that all of the expected values were recorded.
&lt;/p&gt;
&lt;p&gt;
In the end I ended up with a traversal algorithm that much resembles a typical graph
traversal (its breadth first) and all of its details hidden away in a iterative method,
yet I can test its behavior by setting the start conditions and essentially inspect
its results as they come out. To sum up:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
I was able to use TDD methods to drive the behavior of the algorithm 
&lt;li&gt;
I kept the details of the implementation hidden, since all it takes to invoke the
"traverser" is a single function call. 
&lt;li&gt;
I used a neat feature of .Net 2.0.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Note: this can be done with .Net 1.1 of course, but it's not as neat as one would
need to implement both an IEnumerable and IEnumerator interfaces in a couple of classes.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.alexeyonline.com/Blog/aggbug.ashx?id=de1eb9e8-8394-4359-ae72-228818ea101e" /&gt;</description>
      <comments>http://www.alexeyonline.com/Blog/CommentView,guid,de1eb9e8-8394-4359-ae72-228818ea101e.aspx</comments>
      <category>Development</category>
      <category>TDD</category>
    </item>
  </channel>
</rss>