<?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"
	>

<channel>
	<title>On Programming</title>
	<atom:link href="http://op.closedformodification.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://op.closedformodification.com</link>
	<description>A practical view on programming, software development in general, and anything that is related in sometimes surprising ways</description>
	<pubDate>Thu, 17 May 2007 16:57:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>The Law of Code Attraction</title>
		<link>http://op.closedformodification.com/2007/05/17/the-law-of-code-attraction/</link>
		<comments>http://op.closedformodification.com/2007/05/17/the-law-of-code-attraction/#comments</comments>
		<pubDate>Thu, 17 May 2007 09:39:57 +0000</pubDate>
		<dc:creator>Wolfgang</dc:creator>
		
		<category><![CDATA[Law of Attraction]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[TDD]]></category>

		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://op.closedformodification.com/2007/05/17/the-law-of-code-attraction/</guid>
		<description><![CDATA[I have made an observation the other day about a curious correlation between Test Driven Development (TDD) and what is nowadays called the &#8220;Law of Attraction&#8221;. This law roughly states that you will attract into your life whatever things or circumstances you repeatedly think about and desire. While I don&#8217;t agree with how this concept [...]]]></description>
			<content:encoded><![CDATA[<p>I have made an observation the other day about a curious correlation between <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test Driven Development</a> (TDD) and what is nowadays called the <a href="http://en.wikipedia.org/wiki/Law_of_Attraction">&#8220;Law of Attraction&#8221;</a>. This law roughly states that you will attract into your life whatever things or circumstances you repeatedly think about and desire. While I don&#8217;t agree with how this concept is very aggressively marketed today, I tend to believe that it works.</p>

<p>A key element in the law of attraction is faith. If you repeatedly think about something that you would like to have (or have happen), and you have absolute faith in getting it, you will get it, the law says. This technique can be put to use most efficiently by repeatedly thinking about the desired thing as if it would already exist (thereby exercising absolute faith). 
For example (modern examples for this law seem to be notoriously monetary), instead of saying, &#8220;I have faith that I will have a million dollars&#8221;, one would rather say, &#8220;I have a million dollars&#8221;, ideally repeating this several times a day.</p>

<p>By stating the object of our desire as if it were already a reality, we create a strong tension between the current reality (not having whatever we desire) and the desired reality. Our persistent and absolute faith then compels us to take action that will resolve this tension, by moving us towards the reality that we desire. Depending on your believe system you might also say that this action is guided by god, the universe, your subconscious mind, the divine, your muse, inspiration, etc.</p>

<p>If you are a programmer, and you are still reading, congratulations! Because now, let&#8217;s think about Test Driven Development, where usually one goes about writing a test first, that is, before the code that would make it pass even exists. So by writing this test, we pretend that the code that will make it pass (or even compile) is already there. Our test talks about the desired object, the code, as if it were already written. In other words, we express absolute faith that the code will eventually be written.  In fact, our failing test starts to attract the code that will make it pass.<br />
Now, after we clearly stated what we want, we run our compiler and/or test framework and immediately get in touch with the current reality. The test will fail. Since we have a desire to make it pass, and absolute faith that we can make it pass, the tension between the current reality and our desired reality will compel us to write the code necessary to make the test pass. Every test becomes a mini-fulfillment of a clearly stated desire. That might just be the reason why writing failing tests and making them pass is so satisfying.</p>
]]></content:encoded>
			<wfw:commentRss>http://op.closedformodification.com/2007/05/17/the-law-of-code-attraction/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Game Developer Rant</title>
		<link>http://op.closedformodification.com/2006/09/21/game-developer-rant/</link>
		<comments>http://op.closedformodification.com/2006/09/21/game-developer-rant/#comments</comments>
		<pubDate>Thu, 21 Sep 2006 09:46:07 +0000</pubDate>
		<dc:creator>Wolfgang</dc:creator>
		
		<category><![CDATA[Gaming]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[c++]]></category>

		<category><![CDATA[gamedev]]></category>

		<category><![CDATA[games industry]]></category>

		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://op.closedformodification.com/2006/09/21/game-developer-rant/</guid>
		<description><![CDATA[Yesterday I listened to  &#8216;Burning Down the House: Game Developers Rant&#8217;, available here. It is the recording of a  panel that was held last year at the Game Developers Conference and it became very popular, because big game industry names were cursing our industry, and they also used &#8220;fuck&#8221; a lot, apparently previously [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I listened to  &#8216;Burning Down the House: Game Developers Rant&#8217;, available <a href="http://cmpmedia.vo.llnwd.net/o1/gdcradio-net/GDCR/gdcr_010.mp3">here</a>. It is the recording of a  panel that was held last year at the Game Developers Conference and it became very popular, because big game industry names were cursing our industry, and they also used &#8220;fuck&#8221; a lot, apparently previously being encouraged to do so. So, I decided, to write a rant myself. Keeping with tradition, it will contain the occasional swearword, so your discretion is advised.</p>

<p><span id="more-35"></span></p>

<p><strong>Rant Start</strong></p>

<p>So we hear this year our AAA projects will cost 10 million dollars to make and next year they will cost 15 and in 5 years it will be a gazillion. Why? Well hmm, let&#8217;s see, the hardware is getting more complex, content creation becomes so much harder, photo realism, content pipelines, episodic content, oh my!</p>

<p>The real reason for exploding costs in game development is incompetent software developers. I am sorry to say. It&#8217;s not the big, all encompassing, unrelenting and unchangeable advancement of technology and refinement of consumer taste and expectations, neither is it those &#8220;risk averse&#8221; publishers who wont finance your creative idea. No, it is simply incompetence. Our skill in devising reliable and flexible software architectures is, to put it mildly, severely lacking. The advanced hardware and those pesky creative designers have created an environment that requires excellence, an environment we can&#8217;t possibly keep up with using our current skillz (sic).
<br />Programmers are the least trusted individuals in the industry. Why? Because we are poor and misunderstood individuals? Because we work so hard and are tired all the time and therefore make mistakes every now and then? No. It is because we can&#8217;t code for shit. We have no clue about the simplest and oldest principles of software development. We consistently violate well established principles and practices of object oriented programming, while cranking out one class after the other in our &#8220;oh we started out with some classes but then it got out of hand uhuhuhu&#8221;-piece-of-shit-hacked-together system, which sometimes, but not always, through brute force, individual genius, or sheer luck finds it&#8217;s way onto the shelves. And then we go on complaining about those long hours &#8220;they&#8221; put us through, when in reality, it is our crap code that has us sit there, debugging deep into our utterly untested systems, looking at the same functionality in 10 places and treading to add another line to that one forbidden include file, that will send the time of our next build cycle through the roof. But hey, more time for coffee and bitching about management in the kitchen!</p>

<p>The designer walks up to us and asks us to do a simple thing that would enhance his game, and we tell him that it will take, oh, hmm, days or maybe a week, and we will not be sure how it will affect all the other systems and therefore we can&#8217;t say if the game will behave the same as before the change, look out for those side effects, testers! The designer looks at us funny, and we roll our eyes, hidden or otherwise, because how can she possibly understand the intricate goings on in our wonderful and complex software and oh how hard it is to do this cool (and sexy) programming thing but don&#8217;t worry, we got it! After all, we are your heroes. Right? Right?? And they keep throwing these change requests at us .. can&#8217;t they make up their mind! Do it right the first time, for fucks sake!
<br />We add a feature to your game, but we just can&#8217;t tell you if we broke it or not! I mean What. The. Fuck! Dear designers, dear artists, dear producers, we have fooled you. We have stringed you along. We somehow convinced you that this is the way it goes, that software development just IS THAT WAY. No, sorry, we are full of shit. We lied to you. We lied to you because we wanted to hide our own lack of software development competency. And some of us are really good at hiding that behind shiny graphics and oh those mind blowing physics. And we usually do this by crunching our asses off and burning out in our twenties.</p>

<p>So, we need software architecture you say? You mean the thing where you write those small classes with only 3 members or something, uh, and you, like, test them, and, like, your classes have as little responsibility as possible, so you can test them in isolation, and then in the end you plug your well tested small classes together, yielding a well tested and reliable layer of functionality, ready to carry your next layer, which you can build with confidence and the courage to display excellence? 
<br />Are you, like, gay or something? Oh and  ..  you can&#8217;t use virtual functions because on the 360 this will cause cache misses and our performance uh uh uh uh. 
Well fuck cache misses. Tell your programmers to learn how  to write tested and reusable software first, and then have them go and profile those 20% of the code that is exercised 80% of the execution time. They might find out how to get past the same 20% of problems they run into over and over again, using 80% of your budget.</p>

<p>So here we are, blaming Walmart and EA and those evil money wielding publishers in general, and oh the risk it is nowadays with all that money involved.
<br />Or, rather, with all those incompetent developers involved. They build you software which will be hard to maintain and hard to change. They build you software of which they will not be able to tell you if it works the same tomorrow or 10 minutes later. They build you software that will drag them back to their desks for 80 hours a week, spending most of their time in their favorite tool, the debugger. They build you software full of non-commitments and guilty conscience. Producers, have a look at those C++ files in the elusive &#8220;Code&#8221; folder of your multimillion project,  and look at the lines beginning with // or /*. You might get a feeling for how your developers feel about their work. Search for &#8220;fuck&#8221; and &#8220;shit&#8221; and &#8220;crap&#8221; or &#8220;god&#8221;, &#8220;OMG&#8221; and &#8220;sucks&#8221;. You will see comments throughout the code saying &#8220;oh .. this sucks but I put it here&#8221; or &#8220;shit! This is sooo bad but for now it is good enough. NEED TO CHANGE LATER&#8221;.  Or, my favorite one, which I read personally in the source code of a Triple-A title: &#8220;I have no shame left&#8221;. 
<br />That is right. We, your developers, have no shame left. We walk around in your office, our penises tangling, scratching our balls, and providing you with a heap of shit that you are to use for your creative ideas and dreams, and that you are to market to a hopeful crowd of gamers, which is growing more and more frustrated. Please show us the way to the closet where we left our pants and send us back to programming school.</p>

<p><strong>Rant End</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://op.closedformodification.com/2006/09/21/game-developer-rant/feed/</wfw:commentRss>
<enclosure url="http://cmpmedia.vo.llnwd.net/o1/gdcradio-net/GDCR/gdcr_010.mp3" length="14215168" type="audio/mpeg" />
		</item>
		<item>
		<title>From manual to automatic testing - A case study</title>
		<link>http://op.closedformodification.com/2006/08/14/from-manual-to-automatic-testing-a-case-study/</link>
		<comments>http://op.closedformodification.com/2006/08/14/from-manual-to-automatic-testing-a-case-study/#comments</comments>
		<pubDate>Mon, 14 Aug 2006 18:21:05 +0000</pubDate>
		<dc:creator>Wolfgang</dc:creator>
		
		<category><![CDATA[Doom3]]></category>

		<category><![CDATA[Gaming]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[TDD]]></category>

		<category><![CDATA[c++]]></category>

		<category><![CDATA[idsoftware]]></category>

		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://op.closedformodification.com/2006/08/14/from-manual-to-automatic-testing-a-case-study/</guid>
		<description><![CDATA[I recently implemented "picking" in the publicly available parts of the Doom 3 engine.
Picking in 3D games (or applications) means that the mouse cursor position is mapped to the 3D world in such a way that the mouse can be used to "pick" up objects in 3D space. In this post I would like to [...]]]></description>
			<content:encoded><![CDATA[<p>I recently implemented "picking" in the publicly available parts of the Doom 3 engine.
Picking in 3D games (or applications) means that the mouse cursor position is mapped to the 3D world in such a way that the mouse can be used to "pick" up objects in 3D space. In this post I would like to describe how I used testing in implementing this technique,
by first implementing a "spike" solution with visual testing, and then using data from this solution to implement
a piece of code that is fully tested without manual intervention. This is an exercise in arriving from an unreliable testing method, that is,
looking at the screen, to a reliable one, using data that a machine can process automatically. I briefly touched on the same topic <a href="http://op.closedformodification.com/2006/03/07/testing-practice-use-your-eyes-when-necessary/">here</a>.</p>

<p><span id="more-29"></span></p>

<h2>The spike</h2>

<p>In <a href="http://www.extremeprogramming.org/">"Extreme Programming"</a> the term <a href="http://c2.com/cgi/wiki?SpikeSolution">"Spike Solution"</a> basically means venturing out into the untested waters and "hacking"
together a piece of code which roughly does what we want, in order to learn about the problem as well as the solution.
So I did exactly that. I found a convenient place to implement my picking code in the update loop of the game. The code
would shoot a ray from the mouse curser position into the world, and intersect it with the geometry, providing me with
the intersection point (if any). As a visual indication, I would render a sphere of some size at the intersection point. 
If the mouse cursor appears to be always in the center of the sphere, I assume my code is correct.</p>

<p>After a few iterations over the code, and some grappling with high school trigonometry, I arrive at a satisfactory solution.
Visually, everything looks correct, the data in the (occasionally invoked) debugger also looks good. Here is an actual screenshot, with a wireframe sphere indicating the point of 
intersection on the ceiling, close to the viewer:</p>

<p><a class="imagelink" href="http://op.closedformodification.com/wp-content/uploads/2006/08/shot00007.jpg" title="Manual testing using a debug sphere"><img id="image28" src="http://op.closedformodification.com/wp-content/uploads/2006/08/shot00007.thumbnail.jpg" alt="Manual testing using a debug sphere" /></a></p>

<p>Now that I have some code which does roughly what I want, it is time to put it under test. After all, I will get tired of staring at my sphere to test
my code for correctness whenever I change it.</p>

<h2>The failing test</h2>

<p>To put my code under test, I first write a failing test. The code I have written so far essentially calculates the end-point for a ray which will be tested 
for intersections with the game geometry, the start-point being the location of the viewer. In the game, I am interested in that intersection point, to find 
out what is in the game world at this point, in order to operate on it in a certain manner. In the test, I am really only interested in the end-point of the ray 
- if this point is correct, I assume the rest of the operation will be fine. My goal here is to use data that a computer can verify 
(in my case, a vector consisting of three floating point numbers), as opposed to the visual cues I have gotten so far, which need the human eye to judge (approximate) correctness.</p>

<p>So now, having rid myself of any dependency on the game data, which is expensive and time consuming to load, my test simply has some inputs, and an expected output,
and will run completely independent of the game.</p>

<p>My inputs are (for completeness sake):</p>

<ul>
<li>The screen coordinates of the mouse cursor</li>
<li>The horizontal and the vertical field of view</li>
<li>The view matrix</li>
<li>The eye point (position of the viewer)</li>
</ul>

<p>My output is another 3D point, the end-point of the ray which is shot in the view-direction, distorted accordingly using the field of view variables.
So, I put the code I have "hacked" into the game into a class, and put this class under test. This test lives in a seperate project from the game project, 
and is run independently (and cheaply). The first version of my test looks like this:</p>

<div class="igBar"><span id="lcode-6"><a href="#" onclick="javascript:showPlainTxt('code-6'); return false;">PLAIN TEXT</a></span></div>

<div class="syntax_hilite"><span class="langName">CODE:</span><br /><div id="code-6">
<div class="code"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#define FLT_EQUAL<span style="color:#006600; font-weight:bold;">&#40;</span>x, y, tol<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>idMath::<span style="">Fabs</span><span style="color:#006600; font-weight:bold;">&#40;</span>x-y<span style="color:#006600; font-weight:bold;">&#41;</span> &lt;= tol<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">TEST<span style="color:#006600; font-weight:bold;">&#40;</span>pickRayEval<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Pickray ray<span style="color:#006600; font-weight:bold;">&#40;</span>SCREEN_WIDTH, SCREEN_HEIGHT<span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float mouseX = <span style="color:#800000;color:#800000;">1</span>.0f;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float mouseY = <span style="color:#800000;color:#800000;">2</span>.0f;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float fovX = <span style="color:#800000;color:#800000;">3</span>.0f;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float fovY = <span style="color:#800000;color:#800000;">4</span>.0f;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; idMat3 viewMatrix<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;color:#800000;">1</span>, <span style="color:#800000;color:#800000;">2</span>, <span style="color:#800000;color:#800000;">3</span>, <span style="color:#800000;color:#800000;">4</span>, <span style="color:#800000;color:#800000;">5</span>, <span style="color:#800000;color:#800000;">6</span>, <span style="color:#800000;color:#800000;">7</span>, <span style="color:#800000;color:#800000;">8</span>, <span style="color:#800000;color:#800000;">9</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; idVec3 start<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;color:#800000;">10</span>, <span style="color:#800000;color:#800000;">11</span>, <span style="color:#800000;color:#800000;">12</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; idVec3 expectedEnd<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;color:#800000;">13</span>, <span style="color:#800000;color:#800000;">14</span>, <span style="color:#800000;color:#800000;">15</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ray.<span style="">eval</span><span style="color:#006600; font-weight:bold;">&#40;</span>mouseX, mouseY, fovX, fovY, viewMatrix, start<span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; assertTrue<span style="color:#006600; font-weight:bold;">&#40;</span>FLT_EQUAL<span style="color:#006600; font-weight:bold;">&#40;</span>ray.<span style="">getEnd</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>, expectedEnd<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;idMath::<span style="">FLT_EPSILON</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; assertTrue<span style="color:#006600; font-weight:bold;">&#40;</span>FLT_EQUAL<span style="color:#006600; font-weight:bold;">&#40;</span>ray.<span style="">getEnd</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, expectedEnd<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;idMath::<span style="">FLT_EPSILON</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; assertTrue<span style="color:#006600; font-weight:bold;">&#40;</span>FLT_EQUAL<span style="color:#006600; font-weight:bold;">&#40;</span>ray.<span style="">getEnd</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>, expectedEnd<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;idMath::<span style="">FLT_EPSILON</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div></li></ol></div>
</div></div>

<p><br /></p>

<p>As you can see, I set up some fantasy data, put it through a function in my new "Pickray" class, which is a copy of my spike code,
and check if the result is equivalent to another fantasy 3D point (taking a small epsilon into account).
Of course the test fails. This, in the words of Kent Beck, is progress. Because now I know exactly what to do
next: I need to make this test pass. How do I make it pass? By feeding it the correct pairs of input data and expected output data. Where do I get this data?
Why, by exercising the code that I have put into the game, the code which was visually verified to be correct.</p>

<h2>Sampling data</h2>

<p>So, back in the game code, I add some lines that print the inputs and the expected outputs I am interested in. Since I am really excited at this point, I don't
bother much with formatting. The obvious idea of formatting the output so it becomes correct C++ code ready to be pasted directly into my test eludes me at this point.
That's ok though, I remembered it early enough later on. At any rate, an early version of the output code looks like this:</p>

<div class="igBar"><span id="lcode-7"><a href="#" onclick="javascript:showPlainTxt('code-7'); return false;">PLAIN TEXT</a></span></div>

<div class="syntax_hilite"><span class="langName">CODE:</span><br /><div id="code-7">
<div class="code"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// picking code has produced a vector 'end', using mouse, </span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// fov, view matrix and eye point as input..</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">gameLocal.<span style="">Printf</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"Picking: Mx = %.20f My = %.20f "</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#CC0000;">"FovX = %.20f FovY = %.20f<span style="color:#000099; font-weight:bold;">\n</span>"</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mx, my, fovx, fovy<span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">gameLocal.<span style="">Printf</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"Picking: View Matrix = (%.20f %.20f %.20f)"</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#CC0000;">"(%f.20 %.20f %.20f)(%.20f %.20f %.20f)<span style="color:#000099; font-weight:bold;">\n</span>"</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewMatrix<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>,viewMatrix<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewMatrix<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewMatrix<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>,viewMatrix<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewMatrix<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewMatrix<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>,viewMatrix<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewMatrix<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">gameLocal.<span style="">Printf</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"Picking: Ray Start = (%.20f %.20f %.20f) "</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#CC0000;">"Ray End = (%.20f %.20f %.20f)<span style="color:#000099; font-weight:bold;">\n</span>"</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;start.<span style="">x</span>, start.<span style="">y</span>, start.<span style="">z</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end.<span style="">x</span>, end.<span style="">y</span>, end.<span style="">z</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div></li></ol></div>
</div></div>

<p><br /></p>

<p>This code dumps the current data  whenever I move the mouse (and whenever a certain console variable is set to 1). The high precision in the output is
necessary to avoid imprecise results in the test - so the more digits after the comma I can grab, the better.
I fire up the game, move the cursor around a bit, and I get a lot of "real world" data to choose from. A few copy and paste operations later, and some reformatting, 
and the fantasy data in my test is now replaced with one set of this real world data. One version of my first passing test looks like this:</p>

<div class="igBar"><span id="lcode-8"><a href="#" onclick="javascript:showPlainTxt('code-8'); return false;">PLAIN TEXT</a></span></div>

<div class="syntax_hilite"><span class="langName">CODE:</span><br /><div id="code-8">
<div class="code"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">TEST<span style="color:#006600; font-weight:bold;">&#40;</span>pickRayEval<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Pickray ray<span style="color:#006600; font-weight:bold;">&#40;</span>SCREEN_WIDTH, SCREEN_HEIGHT<span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float mouseX = <span style="color:#800000;color:#800000;">307</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>.0f;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float mouseY = <span style="color:#800000;color:#800000;">255</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>.0f;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float fovX = <span style="color:#800000;color:#800000;">90</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>.0f;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float fovY = <span style="color:#800000;color:#800000;">73</span>.<span style="color:#800000;color:#800000;">73979187011718800000</span>.0f;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; idMat3 viewMatrix<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">57064485549926758000</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">82073915004730225000</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">02741646952927112600</span>,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">82104778289794922000</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">57085943222045898000</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">01565095037221908600</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">02251023240387439700</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">99962407350540161000</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; idVec3 start<span style="color:#006600; font-weight:bold;">&#40;</span>-<span style="color:#800000;color:#800000;">832</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">64</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">68</span>.<span style="color:#800000;color:#800000;">24997711181640600000</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; idVec3 expectedEnd<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;color:#800000;">5200</span>.<span style="color:#800000;color:#800000;">66308593750000000000</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-<span style="color:#800000;color:#800000;">7900</span>.<span style="color:#800000;color:#800000;">92822265625000000000</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-<span style="color:#800000;color:#800000;">674</span>.<span style="color:#800000;color:#800000;">48846435546875000000</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ray.<span style="">eval</span><span style="color:#006600; font-weight:bold;">&#40;</span>mouseX, mouseY, fovX, fovY, viewMatrix, start<span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; assertTrue<span style="color:#006600; font-weight:bold;">&#40;</span>FLT_EQUAL<span style="color:#006600; font-weight:bold;">&#40;</span>ray.<span style="">getEnd</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>, expectedEnd<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;idMath::<span style="">FLT_EPSILON</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; assertTrue<span style="color:#006600; font-weight:bold;">&#40;</span>FLT_EQUAL<span style="color:#006600; font-weight:bold;">&#40;</span>ray.<span style="">getEnd</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, expectedEnd<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;idMath::<span style="">FLT_EPSILON</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; assertTrue<span style="color:#006600; font-weight:bold;">&#40;</span>FLT_EQUAL<span style="color:#006600; font-weight:bold;">&#40;</span>ray.<span style="">getEnd</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>, expectedEnd<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;idMath::<span style="">FLT_EPSILON</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div></li></ol></div>
</div></div>

<p><br /></p>

<p>This looks pretty good already: I can get the game to output data which I can use in my test, testing the exact code that the game gives me
output samples from. By now I am confident enough to replace the "loose" code in the game with the class I have since put under test. I have
moved my tested code already to "production". Always a great feeling.</p>

<p>At this point I am ready to refactor my test for using multiple data samples. I add a little infrastructure in the test, enabling me to add
an arbitrary amount of samples for testing. My test now looks something like this:</p>

<div class="igBar"><span id="lcode-9"><a href="#" onclick="javascript:showPlainTxt('code-9'); return false;">PLAIN TEXT</a></span></div>

<div class="syntax_hilite"><span class="langName">CODE:</span><br /><div id="code-9">
<div class="code"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">struct PickraySample</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; PickraySample<span style="color:#006600; font-weight:bold;">&#40;</span>float mX, float mY, float fovX, float fovY,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const idMat3&amp; viewMatrix, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const idVec3&amp; start,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const idVec3&amp; expectedEnd<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; : mMouseX<span style="color:#006600; font-weight:bold;">&#40;</span>mX<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; , mMouseY<span style="color:#006600; font-weight:bold;">&#40;</span>mY<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; , mFovX<span style="color:#006600; font-weight:bold;">&#40;</span>fovX<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; , mFovY<span style="color:#006600; font-weight:bold;">&#40;</span>fovY<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; , mViewMatrix<span style="color:#006600; font-weight:bold;">&#40;</span>viewMatrix<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; , mStart<span style="color:#006600; font-weight:bold;">&#40;</span>start<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; , mExpectedEnd<span style="color:#006600; font-weight:bold;">&#40;</span>expectedEnd<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; void runTest<span style="color:#006600; font-weight:bold;">&#40;</span>PickRay&amp; ray<span style="color:#006600; font-weight:bold;">&#41;</span> const</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; ray.<span style="">eval</span><span style="color:#006600; font-weight:bold;">&#40;</span>mMouseX, mMouseY, mFovX, mFovY, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mViewMatrix, mStart<span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; assertTrue<span style="color:#006600; font-weight:bold;">&#40;</span>FLT_EQUAL<span style="color:#006600; font-weight:bold;">&#40;</span>ray.<span style="">getEnd</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>, mExpectedEnd<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;idMath::<span style="">FLT_EPSILON</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; assertTrue<span style="color:#006600; font-weight:bold;">&#40;</span>FLT_EQUAL<span style="color:#006600; font-weight:bold;">&#40;</span>ray.<span style="">getEnd</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>, mExpectedEnd<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;idMath::<span style="">FLT_EPSILON</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; assertTrue<span style="color:#006600; font-weight:bold;">&#40;</span>FLT_EQUAL<span style="color:#006600; font-weight:bold;">&#40;</span>ray.<span style="">getEnd</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>, mExpectedEnd<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;idMath::<span style="">FLT_EPSILON</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float mMouseX;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float mMouseY;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float mFovX;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; float mFovY;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; idMat3 mViewMatrix;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; idVec3 mStart;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; idVec3 mExpectedEnd;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">class PickrayTester</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">public:</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; void addSample<span style="color:#006600; font-weight:bold;">&#40;</span>float mX, float mY, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;float fovX, float fovY, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const idMat3&amp; viewMatrix, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const idVec3&amp; start, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const idVec3&amp; expectedEnd<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; mSamples.<span style="">push_back</span><span style="color:#006600; font-weight:bold;">&#40;</span>PickraySample<span style="color:#006600; font-weight:bold;">&#40;</span>mX, mY, fovX, fovY, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;viewMatrix, start, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;expectedEnd<span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; void runTests<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; PickRay ray<span style="color:#006600; font-weight:bold;">&#40;</span>SCREEN_WIDTH, SCREEN_HEIGHT<span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; for<span style="color:#006600; font-weight:bold;">&#40;</span>Samples::<span style="">const_iterator</span> it = mSamples.<span style="">begin</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; it!=mSamples.<span style="">end</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; ++it<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span>*it<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="">runTest</span><span style="color:#006600; font-weight:bold;">&#40;</span>ray<span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">private:</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; typedef std::<span style="">vector</span>&lt;PickraySample&gt; Samples;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Samples mSamples;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">TEST<span style="color:#006600; font-weight:bold;">&#40;</span>pickRayEval<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; PickrayTester tester;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; tester.<span style="">addSample</span><span style="color:#006600; font-weight:bold;">&#40;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#800000;color:#800000;">362</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>, <span style="color:#800000;color:#800000;">192</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#800000;color:#800000;">90</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>, <span style="color:#800000;color:#800000;">73</span>.<span style="color:#800000;color:#800000;">73979187011718800000</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; idMat3<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">06865774095058441200</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">98074030876159668000</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">18285137414932251000</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">99755853414535522000</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">06983511894941330000</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">01276944763958454100</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">18240495026111603000</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">0</span>.<span style="color:#800000;color:#800000;">98314058780670166000</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; idVec3<span style="color:#006600; font-weight:bold;">&#40;</span>-<span style="color:#800000;color:#800000;">832</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">64</span>.<span style="color:#800000;color:#800000;">00000000000000000000</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#800000;color:#800000;">68</span>.<span style="color:#800000;color:#800000;">24997711181640600000</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; idVec3<span style="color:#006600; font-weight:bold;">&#40;</span>-<span style="color:#800000;color:#800000;">1435</span>.<span style="color:#800000;color:#800000;">56396484375000000000</span>, </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-<span style="color:#800000;color:#800000;">10108</span>.<span style="color:#800000;color:#800000;">66894531250000000000</span>, </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-<span style="color:#800000;color:#800000;">285</span>.<span style="color:#800000;color:#800000;">55285644531250000000</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// and many more lines like this...</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; tester.<span style="">runTests</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div></li></ol></div>
</div></div>

<p><br /></p>

<p>The class PickrayTester takes care of collecting samples and running the tests. Meanwhile, the code in the game that outputs my samples has been
changed to produce correct C++ code, nameley a block of code starting with <code>tester.addSample...</code> which I can directly paste into my test, for every
data sample I want, and for as much samples I want.</p>

<p>The final thing I want to do is to remove some of the remaining manual tedium. Also, my test starts looking a bit fat, depending on how many data
samples I use. 
So, approaching the inevitable happy end, I change my sample output code in the game to directly write into a cpp file, which is in the same directory as my test. 
I call it PickraySamples.cpp. This file now solely contains a list of <code>tester.addSample..</code> blocks.
In my test, I replace the inlined sample data with an <code>#include</code> statement that includes the generated file:</p>

<div class="igBar"><span id="lcode-10"><a href="#" onclick="javascript:showPlainTxt('code-10'); return false;">PLAIN TEXT</a></span></div>

<div class="syntax_hilite"><span class="langName">CODE:</span><br /><div id="code-10">
<div class="code"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//-----------------------------------------------------------------------------</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">TEST<span style="color:#006600; font-weight:bold;">&#40;</span>pickRayEndpointSamples<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">//-----------------------------------------------------------------------------</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; PickrayTester tester;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9933; font-style:italic;">// These samples are generated by the game</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#include <span style="color:#CC0000;">"PickRaySamples.cpp"</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; tester.<span style="">runTests</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div></li></ol></div>
</div></div>

<p><br /></p>

<p>At this point I declare my mission to be accomplished - I can now change my picking code with the safety net of an automated test. Obviously, there is more to picking
up 3D objects than just shooting a ray into the world. But the automatically asserted correctness of this integral part is already a nice and solid foundation to build on.</p>
]]></content:encoded>
			<wfw:commentRss>http://op.closedformodification.com/2006/08/14/from-manual-to-automatic-testing-a-case-study/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Unit testing within Doom 3</title>
		<link>http://op.closedformodification.com/2006/07/03/unit-testing-within-doom-3/</link>
		<comments>http://op.closedformodification.com/2006/07/03/unit-testing-within-doom-3/#comments</comments>
		<pubDate>Mon, 03 Jul 2006 11:38:05 +0000</pubDate>
		<dc:creator>Wolfgang</dc:creator>
		
		<category><![CDATA[Doom3]]></category>

		<category><![CDATA[Gaming]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[TDD]]></category>

		<category><![CDATA[c++]]></category>

		<category><![CDATA[idsoftware]]></category>

		<guid isPermaLink="false">http://op.closedformodification.com/2006/07/03/unit-testing-within-doom-3/</guid>
		<description><![CDATA[Allow me to gleefully report that I have integrated my unit testing framework into the Doom 3 engine.

I have previously used this framework to run unit tests via a simple text interface. Tests are easily defined using a simple set of macros and automatically enumerated.  Now, whenever my modified version of Doom 3 starts [...]]]></description>
			<content:encoded><![CDATA[<p>Allow me to gleefully report that I have integrated my unit testing framework into the <a href="http://en.wikipedia.org/wiki/Doom_3">Doom 3</a> engine.</p>

<p>I have previously used this framework to run unit tests via a simple text interface. Tests are easily defined using a simple set of macros and automatically enumerated.  Now, whenever my modified version of Doom 3 starts up, it will do the same, it will enumerate tests wherever they have been implemented in the code, and I can operate those tests via the in-game console. Have a look:</p>

<p><a class="imagelink" href="http://op.closedformodification.com/wp-content/uploads/2006/07/tdd_in_d31_cropped.gif" title="TDD in the Doom3 Engine, Exhibit 2"><img id="image22" src="http://op.closedformodification.com/wp-content/uploads/2006/07/tdd_in_d31_cropped.thumbnail.gif" alt="TDD in the Doom3 Engine, Exhibit 2" /></a></p>

<p><a class="imagelink" href="http://op.closedformodification.com/wp-content/uploads/2006/07/tdd_in_d32_cropped.gif" title="TDD in the Doom3 Engine, Exhibit 1"><img id="image24" src="http://op.closedformodification.com/wp-content/uploads/2006/07/tdd_in_d32_cropped.thumbnail.gif" alt="TDD in the Doom3 Engine, Exhibit 1" /></a></p>

<p>Now, why did I do this? I will of course also have a seperate program with a lot of unit tests, as I develop my software test by test. However, I will want to write tests that will need the game running in some stage, and part of the beauty of all <a href="http://en.wikipedia.org/wiki/Id_software">id Software</a> engines is that they make it extremely easy to hook in any kind of custom code that is readily executable in the game at any time, via custom <a href="http://en.wikipedia.org/wiki/PC_game_console">console</a> commands, thus opening up an extensible command line interface to the running game. And so I not only have the environment in which to run my tests, it also hosts them and provides an interface to them. That, I think, is quite beautiful.</p>

<p>I am not working for Id Software, in case you were wondering. I am using the publicly available tools and source code for modifying the original game.</p>
]]></content:encoded>
			<wfw:commentRss>http://op.closedformodification.com/2006/07/03/unit-testing-within-doom-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>X-Macros</title>
		<link>http://op.closedformodification.com/2006/06/18/x-macros/</link>
		<comments>http://op.closedformodification.com/2006/06/18/x-macros/#comments</comments>
		<pubDate>Sun, 18 Jun 2006 11:30:14 +0000</pubDate>
		<dc:creator>Wolfgang</dc:creator>
		
		<category><![CDATA[Preprocessor]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[TDD]]></category>

		<category><![CDATA[X-Macros]]></category>

		<category><![CDATA[c++]]></category>

		<guid isPermaLink="false">http://op.closedformodification.com/2006/06/18/x-macros/</guid>
		<description><![CDATA[When looking for X-Macros on Google, the only reference I came across was this one (ddj.com), which is also the place where I happened across X-Macros by accident (in the printed version of the magazine). I have since put them to great use in production code.
What are X-Macros? They are basically a clever way to [...]]]></description>
			<content:encoded><![CDATA[<p>When looking for X-Macros on Google, the only reference I came across was <a href="http://www.ddj.com/dept/cpp/184401387">this one (ddj.com)</a>, which is also the place where I happened across X-Macros by accident (in the printed version of the magazine). I have since put them to great use in production code.
What are X-Macros? They are basically a clever way to avoid code duplication, using the C/C++ preprocessor. They come in very handy whenever you would normally need to hunt down and hand-edit multiple places in your code after expanding or modifying some lower level layer which this code depends upon. Let's look at some examples to find out what X-Macros might be able to do for you.</p>

<p><span id="more-19"></span></p>

<h2>The "Enum Example"</h2>

<p>Let's say you have an enum, and you would like to associate a string with each element, to provide a readable name. A common way to do this is as follows:</p>

<div class="igBar"><span id="lcpp-16"><a href="#" onclick="javascript:showPlainTxt('cpp-16'); return false;">PLAIN TEXT</a></span></div>

<div class="syntax_hilite"><span class="langName">C++:</span><br /><div id="cpp-16">
<div class="cpp"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#include &lt;iostream&gt;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #0000ff;">enum</span> IDs</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #000000;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;ID0 = <span style="color: #0000dd;color:#800000;">0</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;ID1,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;ID2,&nbsp; &nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;NUM_IDS</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span>* idStrings<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> = </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #666666;">"ID 0"</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #666666;">"ID 1"</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #666666;">"ID 2"</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">NULL</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">int</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; std::<span style="color: #0000dd;">cout</span> &lt;&lt;<span style="color: #666666;">"ID0 -&gt; "</span> &lt;&lt;idStrings<span style="color: #000000;">&#91;</span>ID0 <span style="color: #000000;">&#93;</span> &lt;&lt;std::<span style="color: #00eeff;">endl</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; std::<span style="color: #0000dd;">cout</span> &lt;&lt;<span style="color: #666666;">"ID1 -&gt; "</span> &lt;&lt;idStrings<span style="color: #000000;">&#91;</span>ID1 <span style="color: #000000;">&#93;</span> &lt;&lt;std::<span style="color: #00eeff;">endl</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; std::<span style="color: #0000dd;">cout</span> &lt;&lt;<span style="color: #666666;">"ID2 -&gt; "</span> &lt;&lt;idStrings<span style="color: #000000;">&#91;</span>ID2 <span style="color: #000000;">&#93;</span> &lt;&lt;std::<span style="color: #00eeff;">endl</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #0000ff;">return</span> <span style="color: #0000dd;color:#800000;">0</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span> </div></li></ol></div>
</div></div>

<p><br /></p>

<p>The output of this program is:</p>

<pre><code>ID0 -&gt; ID 0
ID1 -&gt; ID 1
ID2 -&gt; ID 2
</code></pre>

<p>Now, whenever you add an element to <code>IDs</code> you will have to remember to add an element to <code>idStrings</code>. The compiler wont tell you about your omission, and things could get nasty only very late at runtime. Even more so, if you have code that operates on all members of the enum, you have to add to this code as well, as you would have to in the above example, where we output all the string names on standard output.</p>

<p>X-Macros relieve you of all that. Let's rewrite our code like this:</p>

<div class="igBar"><span id="lcpp-17"><a href="#" onclick="javascript:showPlainTxt('cpp-17'); return false;">PLAIN TEXT</a></span></div>

<div class="syntax_hilite"><span class="langName">C++:</span><br /><div id="cpp-17">
<div class="cpp"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#include &lt;iostream&gt;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">// (1) Define code generating macro</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#define GENERATE_IDS&nbsp; &nbsp; \</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; X<span style="color: #000000;">&#40;</span>ID0, <span style="color: #666666;">"ID 0"</span><span style="color: #000000;">&#41;</span>&nbsp; &nbsp; &nbsp; \</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; X<span style="color: #000000;">&#40;</span>ID1, <span style="color: #666666;">"ID 1"</span><span style="color: #000000;">&#41;</span>&nbsp; &nbsp; &nbsp; \</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; X<span style="color: #000000;">&#40;</span>ID2, <span style="color: #666666;">"ID 2"</span><span style="color: #000000;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">// (2) Define X-Macro for generating enum members</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#define X(id, idString) id,</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">enum</span> IDs</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#123;</span>&nbsp; &nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">// To be on the safe side, </span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">// force ID's to start at 0</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; ID_LOWERBOUND = -<span style="color: #0000dd;color:#800000;">1</span>,</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; GENERATE_IDS</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; NUM_IDS</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#125;</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#undef X</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">// (3) Define X-Macro for generating string names</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#define X(id, idString) idString,</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">char</span>* iDStrings<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> = </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#123;</span>&nbsp; &nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; GENERATE_IDS</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">NULL</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#125;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#undef X</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">int</span> main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; std::<span style="color: #0000dd;">cout</span> &lt;&lt;<span style="color: #666666;">"ID0 -&gt; "</span> &lt;&lt;idStrings<span style="color: #000000;">&#91;</span>ID0 <span style="color: #000000;">&#93;</span> &lt;&lt;std::<span style="color: #00eeff;">endl</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; std::<span style="color: #0000dd;">cout</span> &lt;&lt;<span style="color: #666666;">"ID1 -&gt; "</span> &lt;&lt;idStrings<span style="color: #000000;">&#91;</span>ID1 <span style="color: #000000;">&#93;</span> &lt;&lt;std::<span style="color: #00eeff;">endl</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; std::<span style="color: #0000dd;">cout</span> &lt;&lt;<span style="color: #666666;">"ID2 -&gt; "</span> &lt;&lt;idStrings<span style="color: #000000;">&#91;</span>ID2 <span style="color: #000000;">&#93;</span> &lt;&lt;std::<span style="color: #00eeff;">endl</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #0000ff;">return</span> <span style="color: #0000dd;color:#800000;">0</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span> </div></li></ol></div>
</div></div>

<p><br /></p>

<p>Let's examine what is happening here. At (1) we define a macro which expands to a set of "X-Macros". In our case, the X-Macro has 2 Parameters. At this point in the code, they are not expanded. Note that this uses the fact that the preprocessor will not expand macros embedded in other macros, before the "parent" macro is expanded. Therefore it does not matter that, at this point, X is not defined to anything.
At (2) the whole magic happens. The X-Macro is defined. It will expand to its first parameter (ID0, ID1, ID2) and a colon.<br />
Now, inside the enum definition, we expand <code>GENERATE_IDS</code>. This will now also expand the current definition of our X-Macro, and, voila, an enum is generated. At (3) we do the same thing, only this time, we expand the X-Macro to something else, namely, it's second parameter and a colon, resulting in a list of strings generated by <code>GENERATE_IDS</code>, fitting nicely into our array definition. Note that the definition of <code>X</code> had to be undefined before we could define it again.<br />
Now, whenever we want to add an enum, all we have to do is add a line to the definition of <code>GENERATE_IDS</code>, with the enum value, and the enum string name. There is no need to edit multiple places in the code any longer. The output of the new program will be exactly the same as the first one.</p>

<h2>Beyond Enums</h2>

<p>While the above example demonstrates a useful technique to avoid code duplication in a particular implementation, X-Macros can be put to use in many different scenarios. I would like to give one more example in this post. Let's say you want to have a class which has many different data members, and the frequency of adding, removing, or changing those members is currently very high. Here is how I would implement such a class using X-Macros:</p>

<div class="igBar"><span id="lcpp-18"><a href="#" onclick="javascript:showPlainTxt('cpp-18'); return false;">PLAIN TEXT</a></span></div>

<div class="syntax_hilite"><span class="langName">C++:</span><br /><div id="cpp-18">
<div class="cpp"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#include &lt;string&gt;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#include &lt;iostream&gt;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#define assertEquals(exp1, exp2) \</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; _assertEquals<span style="color: #000000;">&#40;</span>__LINE__, exp1, exp2<span style="color: #000000;">&#41;</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">namespace</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">// Implement a minimal testing framework</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">int</span> gErrorCount = <span style="color: #0000dd;color:#800000;">0</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">template&lt;class T, <span style="color: #0000ff;">class</span> U&gt;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">void</span> _assertEquals<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">int</span> line, T exp1, U exp2<span style="color: #000000;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span>exp1!=exp2<span style="color: #000000;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#123;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; std::<span style="color: #0000dd;">cout</span> &lt;&lt;<span style="color: #666666;">"Error: Line "</span> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;&lt;line &lt;&lt;<span style="color: #666666;">"; "</span> </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;&lt;exp1 &lt;&lt;<span style="color: #666666;">"!="</span>&nbsp; &lt;&lt;exp2 </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&lt;&lt;std::<span style="color: #00eeff;">endl</span>;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; gErrorCount++;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">// (1) The code generation macro. Each X-Macro therein</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">// receives the type and the name of the new member</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#define GENERATE_PROPS&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">X<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">int</span>, IntValue1<span style="color: #000000;">&#41;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">X<span style="color: #000000;">&#40;</span>std::<span style="color: #00eeff;">string</span>, StringValue1<span style="color: #000000;">&#41;</span>&nbsp; &nbsp; \</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">X<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">float</span>, FloatValue1<span style="color: #000000;">&#41;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">X<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">int</span>, IntValue2<span style="color: #000000;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">// (2) This is the class that will hold all our members</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">class</span> Properties</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span>&nbsp; &nbsp; </div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">public</span>: </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">// (3) The constructor: Set all members to their default</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#define X(tp, name) m_##name = tp();</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Properties<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#123;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; GENERATE_PROPS</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#undef X</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">// (4) The getters, setters and members themselves </span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #339900;">#define X(tp, name)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">public</span>:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-w