<?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>Matthew Manela&#039;s Home Page &#187; testing</title>
	<atom:link href="http://matthewmanela.com/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewmanela.com</link>
	<description>The life and work of Matthew Manela</description>
	<lastBuildDate>Sun, 25 Jul 2010 18:00:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>OpenWithTest released on Visual Studio Gallery</title>
		<link>http://matthewmanela.com/2010/06/30/openwithtest-released-on-visual-studio-gallery/</link>
		<comments>http://matthewmanela.com/2010/06/30/openwithtest-released-on-visual-studio-gallery/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 23:59:00 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[Tools]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio Gallery]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">/b/matt/archive/2010/06/30/quot-open-with-test-quot-released-on-visual-studio-gallery.aspx</guid>
		<description><![CDATA[Download
Either download from the extension manager by searching OpenWithTest or go to the project page here.
Summary 
Open with Test is a Visual Studio extension which serves one simple task: To always open your test files and implementation files tog...]]></description>
			<content:encoded><![CDATA[<h3>Download</h3>

<p>Either download from the extension manager by searching OpenWithTest or go to the project page <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/40ed230b-067a-44c6-9a3b-93f661aa4ab6">here</a>.</p>

<h3>Summary</h3>

<p>Open with Test is a Visual Studio extension which serves one simple task: To always open your test files and implementation files together.</p>

<h3>Details</h3>

<p>When writing unit tested applications (especially while practicing TDD) you will often open an implementation file (i.e SomeClass.cs) followed by the test file(i.e. SomeClassTests.cs).  This extension makes this a one step process.</p>

<p>It works by detecting when you open a new file and attempting to find via convention the test file. It assumes that you create one test file per class.  So, if you create a class called Car in the file Car.cs then you will have a test file named CarTests.cs which tests the car class.</p>

<p>Currently, only C# (.cs) files are supported but I plan to expand this to other files types soon.</p>

<h3>Configuration</h3>

<p>Out of the box, this extension will assume a file is a test file if it ends with the suffix <strong>Test</strong>,<strong>Tests</strong>, <strong>Fact</strong> or <strong>Facts</strong>.  However, this can be configured.  To change these go to Tools -&gt; Options -&gt; Open With Test and you will see this screen:</p>

<p style="text-align: center;"><a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-89-61-metablogapi/6403.image_5F00_068513EA.png"></a><a href="http://matthewmanela.com/wp-content/uploads/2010/06/6403.image_068513EA.png"><img class="size-full wp-image-456 aligncenter" title="6403.image_068513EA" src="http://matthewmanela.com/wp-content/uploads/2010/06/6403.image_068513EA.png" alt="" width="600" height="349" /></a></p>

<p><br class="spacer_" /></p>

<h3><strong>Feedback</strong></h3>

<p>I would love to get feedback about features or suggestion so please feel free to leave a comment on this blog post or start a discussion post on the <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/40ed230b-067a-44c6-9a3b-93f661aa4ab6">Visual Studio Gallery page</a>.</p>

<p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=10033207" alt="" width="1" height="1" /></p>]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/2010/06/30/openwithtest-released-on-visual-studio-gallery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DRY and Unit Tests don’t mix well</title>
		<link>http://matthewmanela.com/2009/07/12/dry-and-unit-tests-don%e2%80%99t-mix-well/</link>
		<comments>http://matthewmanela.com/2009/07/12/dry-and-unit-tests-don%e2%80%99t-mix-well/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 06:08:50 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2009/07/12/dry-and-unit-tests-don-t-mix-well.aspx</guid>
		<description><![CDATA[When reading source code, I sometimes come across unappealing code(sometimes even my own).&#160; However, there is one kind of “bad code” I see quite frequently.&#160; It is a set of unit tests which have had the DRY (Don't Repeat Yourself) princip...]]></description>
			<content:encoded><![CDATA[<p>When reading<em> </em>source code, I sometimes come across unappealing code(sometimes even my own).&#160; However, there is one kind of “bad code” I see quite frequently.&#160; It is a set of unit tests which have had the <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" >DRY (Don't Repeat Yourself)</a> principle unduly forced upon them.&#160; DRY is the idea that you shouldn’t have to write the same code over and over; abstract it in a function or a class and just call the abstraction.&#160; This is all well and good in most cases, but I find it misguided when applied to a test case.&#160; </p>  <p>A test case should be like a simple short story.&#160; The characters are introduced, action/conflict occurs and then resolution takes place (sometimes with a moral).&#160; This (kind of) corresponds to the 3 steps of a unit test: arrange, act and assert.&#160; You arrange and setup what you need for your test to run, you perform the action that you are trying to test and then you assert the results. The issue I find is that a coder, in attempting to apply DRY to his test cases, will abstract away all of the arrange step into a function often with a name like SetupExpectations or just Setup.&#160; This goes against the point of a test case. A test case needs to be concise and tell me everything I need to know about how that one bit of functionality works. I don’t want to jump around the test class trying to read one test case. To me, this is like reading a book that says, “If you want to learn about the characters in this book please open this other book.”&#160; This doesn’t stop you from understanding the test, but it slows you down…and is just annoying.</p>  <p>&#160;</p>  <p>That is why I will come out and say <strong>do not apply DRY haphazardly to test cases</strong>. </p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9830902" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/2009/07/12/dry-and-unit-tests-don%e2%80%99t-mix-well/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DRY and Unit Tests don’t mix well</title>
		<link>http://matthewmanela.com/2009/07/12/dry-and-unit-tests-don%e2%80%99t-mix-well-2/</link>
		<comments>http://matthewmanela.com/2009/07/12/dry-and-unit-tests-don%e2%80%99t-mix-well-2/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 06:08:50 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">/b/matt/archive/2009/07/12/dry-and-unit-tests-don-t-mix-well.aspx</guid>
		<description><![CDATA[When reading source code, I sometimes come across unappealing code(sometimes even my own).&#160; However, there is one kind of “bad code” I see quite frequently.&#160; It is a set of unit tests which have had the DRY (Don't Repeat Yourself) princip...]]></description>
			<content:encoded><![CDATA[<p>When reading<em> </em>source code, I sometimes come across unappealing code(sometimes even my own).&#160; However, there is one kind of “bad code” I see quite frequently.&#160; It is a set of unit tests which have had the <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" >DRY (Don't Repeat Yourself)</a> principle unduly forced upon them.&#160; DRY is the idea that you shouldn’t have to write the same code over and over; abstract it in a function or a class and just call the abstraction.&#160; This is all well and good in most cases, but I find it misguided when applied to a test case.&#160; </p>  <p>A test case should be like a simple short story.&#160; The characters are introduced, action/conflict occurs and then resolution takes place (sometimes with a moral).&#160; This (kind of) corresponds to the 3 steps of a unit test: arrange, act and assert.&#160; You arrange and setup what you need for your test to run, you perform the action that you are trying to test and then you assert the results. The issue I find is that a coder, in attempting to apply DRY to his test cases, will abstract away all of the arrange step into a function often with a name like SetupExpectations or just Setup.&#160; This goes against the point of a test case. A test case needs to be concise and tell me everything I need to know about how that one bit of functionality works. I don’t want to jump around the test class trying to read one test case. To me, this is like reading a book that says, “If you want to learn about the characters in this book please open this other book.”&#160; This doesn’t stop you from understanding the test, but it slows you down…and is just annoying.</p>  <p>&#160;</p>  <p>That is why I will come out and say <strong>do not apply DRY haphazardly to test cases</strong>. </p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9830902" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/2009/07/12/dry-and-unit-tests-don%e2%80%99t-mix-well-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DRY and Unit Tests don’t mix well</title>
		<link>http://matthewmanela.com/2009/07/12/dry-and-unit-tests-don%e2%80%99t-mix-well-3/</link>
		<comments>http://matthewmanela.com/2009/07/12/dry-and-unit-tests-don%e2%80%99t-mix-well-3/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 06:08:50 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">/b/matt/archive/2009/07/12/dry-and-unit-tests-don-t-mix-well.aspx</guid>
		<description><![CDATA[When reading source code, I sometimes come across unappealing code(sometimes even my own).&#160; However, there is one kind of “bad code” I see quite frequently.&#160; It is a set of unit tests which have had the DRY (Don't Repeat Yourself) princip...]]></description>
			<content:encoded><![CDATA[<p>When reading<em> </em>source code, I sometimes come across unappealing code(sometimes even my own).&#160; However, there is one kind of “bad code” I see quite frequently.&#160; It is a set of unit tests which have had the <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" >DRY (Don't Repeat Yourself)</a> principle unduly forced upon them.&#160; DRY is the idea that you shouldn’t have to write the same code over and over; abstract it in a function or a class and just call the abstraction.&#160; This is all well and good in most cases, but I find it misguided when applied to a test case.&#160; </p>  <p>A test case should be like a simple short story.&#160; The characters are introduced, action/conflict occurs and then resolution takes place (sometimes with a moral).&#160; This (kind of) corresponds to the 3 steps of a unit test: arrange, act and assert.&#160; You arrange and setup what you need for your test to run, you perform the action that you are trying to test and then you assert the results. The issue I find is that a coder, in attempting to apply DRY to his test cases, will abstract away all of the arrange step into a function often with a name like SetupExpectations or just Setup.&#160; This goes against the point of a test case. A test case needs to be concise and tell me everything I need to know about how that one bit of functionality works. I don’t want to jump around the test class trying to read one test case. To me, this is like reading a book that says, “If you want to learn about the characters in this book please open this other book.”&#160; This doesn’t stop you from understanding the test, but it slows you down…and is just annoying.</p>  <p>&#160;</p>  <p>That is why I will come out and say <strong>do not apply DRY haphazardly to test cases</strong>. </p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9830902" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/2009/07/12/dry-and-unit-tests-don%e2%80%99t-mix-well-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Assumptions</title>
		<link>http://matthewmanela.com/2009/02/02/code-assumptions/</link>
		<comments>http://matthewmanela.com/2009/02/02/code-assumptions/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 07:13:42 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blogs.msdn.com/matt/archive/2009/02/01/code-assumptions.aspx</guid>
		<description><![CDATA[My co-workers and I recently came across a piece of code which exposed some assumptions we had about the “correct” behavior of two functions; these assumptions turned out to be false.&#160; The code dealt with determining if the IP of a&#160; reque...]]></description>
			<content:encoded><![CDATA[<p>My co-workers and I recently came across a piece of code which exposed some assumptions we had about the “correct” behavior of two functions; these assumptions turned out to be false.&#160; The code dealt with determining if the IP of a&#160; request coming into to a website matches a certain range of IP address. The range of IP address was defined in a config file and could look something like this:</p>  <p>156.27.1.2, 156.*.*.*, 127.0.0.* </p>  <p>Where the * acts as a wild card and each comma-separated IP format is matched against the incoming IP address. The code’s intended behavior is that specifying no IP address formats in the config would mean that no IP addresses would match the format.&#160; We noticed that this wasn’t holding true.&#160; We went to examine the code that was performing the matching (which none of us had written and sadly has NO test cases around it).&#160; The code boiled down to something like this:</p>  <p>&#160;</p>  <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">   <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">     <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">bool</span> DoesIPMatchIPFormat(<span style="color: #0000ff">string</span> incomingIpAddress, <span style="color: #0000ff">string</span> ipFormatsFromConfig)</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">foreach</span>(var ipFormat <span style="color: #0000ff">in</span> ipFormatsFromConfig.Split(<span style="color: #006080">','</span>))</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     {</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   5:</span>         Regex re = ConvertFormatIntoRegex(ipFormat);</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>         <span style="color: #0000ff">if</span>(rs.Match(incomingIpAddress).Success) <span style="color: #0000ff">return</span> <span style="color: #0000ff">true</span>;</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   7:</span>     }</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span> }</pre>
  </div>
</div>

<p>&#160;</p>

<p>Where ipFormatsFromConfig is the ip range of formats shown above separated by “,” or an empty string if no formats are given. On first glance we all were confused by why this didn’t work and then as we looked into it we realized we had made some incorrect assumptions.</p>

<p>First, we assumed that “”.Split(‘,’) would return a zero element array.&#160; This assumption is false. It returns a 1 element array containing the empty string.&#160; </p>

<p>After we learned this we encountered our second assumption.&#160; We assumed that a regular expression whose pattern was an empty string would not match anything. (ConvertFormatIntoRegex returned just that).&#160; This assumption is also false.&#160; After learning the true behavior, it makes sense why it behaves this way.&#160; (A DFA with only one state must accept every input. ) </p>

<p>Our assumptions about the “correct” behavior of functions reflect similar mistakes made by all programmers; assuming that you don’t make these kinds of assumptions is a very dangerous way to program and reinforces the importance of unit testing.</p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9389368" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/2009/02/02/code-assumptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Assumptions</title>
		<link>http://matthewmanela.com/2009/02/02/code-assumptions-2/</link>
		<comments>http://matthewmanela.com/2009/02/02/code-assumptions-2/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 07:13:42 +0000</pubDate>
		<dc:creator>MattManela</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">/b/matt/archive/2009/02/01/code-assumptions.aspx</guid>
		<description><![CDATA[My co-workers and I recently came across a piece of code which exposed some assumptions we had about the “correct” behavior of two functions; these assumptions turned out to be false.&#160; The code dealt with determining if the IP of a&#160; reque...]]></description>
			<content:encoded><![CDATA[<p>My co-workers and I recently came across a piece of code which exposed some assumptions we had about the “correct” behavior of two functions; these assumptions turned out to be false.&#160; The code dealt with determining if the IP of a&#160; request coming into to a website matches a certain range of IP address. The range of IP address was defined in a config file and could look something like this:</p>  <p>156.27.1.2, 156.*.*.*, 127.0.0.* </p>  <p>Where the * acts as a wild card and each comma-separated IP format is matched against the incoming IP address. The code’s intended behavior is that specifying no IP address formats in the config would mean that no IP addresses would match the format.&#160; We noticed that this wasn’t holding true.&#160; We went to examine the code that was performing the matching (which none of us had written and sadly has NO test cases around it).&#160; The code boiled down to something like this:</p>  <p>&#160;</p>  <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">   <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">     <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">bool</span> DoesIPMatchIPFormat(<span style="color: #0000ff">string</span> incomingIpAddress, <span style="color: #0000ff">string</span> ipFormatsFromConfig)</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> {</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">foreach</span>(var ipFormat <span style="color: #0000ff">in</span> ipFormatsFromConfig.Split(<span style="color: #006080">','</span>))</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>     {</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   5:</span>         Regex re = ConvertFormatIntoRegex(ipFormat);</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>         <span style="color: #0000ff">if</span>(rs.Match(incomingIpAddress).Success) <span style="color: #0000ff">return</span> <span style="color: #0000ff">true</span>;</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   7:</span>     }</pre>

    <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span> }</pre>
  </div>
</div>

<p>&#160;</p>

<p>Where ipFormatsFromConfig is the ip range of formats shown above separated by “,” or an empty string if no formats are given. On first glance we all were confused by why this didn’t work and then as we looked into it we realized we had made some incorrect assumptions.</p>

<p>First, we assumed that “”.Split(‘,’) would return a zero element array.&#160; This assumption is false. It returns a 1 element array containing the empty string.&#160; </p>

<p>After we learned this we encountered our second assumption.&#160; We assumed that a regular expression whose pattern was an empty string would not match anything. (ConvertFormatIntoRegex returned just that).&#160; This assumption is also false.&#160; After learning the true behavior, it makes sense why it behaves this way.&#160; (A DFA with only one state must accept every input. ) </p>

<p>Our assumptions about the “correct” behavior of functions reflect similar mistakes made by all programmers; assuming that you don’t make these kinds of assumptions is a very dangerous way to program and reinforces the importance of unit testing.</p><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9389368" width="1" height="1">]]></content:encoded>
			<wfw:commentRss>http://matthewmanela.com/2009/02/02/code-assumptions-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
