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

<channel>
	<title>AlecMcE.com &#187; tdd</title>
	<atom:link href="http://alecmce.com/category/tdd/feed" rel="self" type="application/rss+xml" />
	<link>http://alecmce.com</link>
	<description>Coding on the Flash Platform</description>
	<lastBuildDate>Thu, 12 Aug 2010 21:32:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Gotcha &#8211; transform.matrix and scaleX/Y</title>
		<link>http://alecmce.com/as3/gotcha-transform-scale</link>
		<comments>http://alecmce.com/as3/gotcha-transform-scale#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:00:47 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[gotcha]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=720</guid>
		<description><![CDATA[I came across this gotcha for the first time today. Praise-be to ASUnit, without which this could have been extremely difficult to unearth: // given two sprites called &#34;a&#34; and &#34;b&#34;... a.transform.matrix = new Matrix(-.5, 0, 0, -.5, a.x, a.y); b.scaleX = b.scaleY = -.5; trace(a.scaleX, a.scaleY, b.scaleX, b.scaleY); // outputs: 0.5, 0.5, -0.5, -0.5 [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this gotcha for the first time today. Praise-be to <a href="http://asunit.org/">ASUnit</a>, without which this could have been extremely difficult to unearth:</p>
<pre class="brush: as3;">
// given two sprites called &quot;a&quot; and &quot;b&quot;...

a.transform.matrix = new Matrix(-.5, 0, 0, -.5, a.x, a.y);
b.scaleX = b.scaleY = -.5;

trace(a.scaleX, a.scaleY, b.scaleX, b.scaleY); // outputs: 0.5, 0.5, -0.5, -0.5
</pre>
<p>Both clips have been scaled by -0.5, but because the transform was used to produce the scale for a, the scaleX/Y variables do not reflect the object&#8217;s true scale.</p>
<p>Now, just to confuse yourself, add a third sprite to the stage:</p>
<pre class="brush: as3;">
// given another sprite called &quot;c&quot;...

c.transform.matrix = new Matrix(-.5, 0, 0, -.5, c.x, c.y);
c.scaleX = c.scaleY = -.5;
</pre>
<p>Curiouser and curiouser! This needed a more complete experimentation&#8230;</p>
<div style="text-align: center;">

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="550" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2010/02/scaleAndTransform.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2010/02/scaleAndTransform.swf" width="550" height="400">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

</div>
<p>The source for this experiment can be found here: <a href='http://alecmce.com/wp-content/uploads/2010/02/scaleAndTransform.zip'>scaleAndTransform</a>. The buttons call the following methods:</p>
<pre class="brush: as3;">
function onGo(event:Event):void
{
	a.transform.matrix = new Matrix(-.5, 0, 0, -.5, a.x, a.y);

	b.scaleX = b.scaleY = -.5;

	c.transform.matrix = new Matrix(-.5, 0, 0, -.5, c.x, c.y);
	c.scaleX = c.scaleY = -.5;
}

function onResetScale(event:Event):void
{
	a.scaleX = a.scaleY = 1;
	b.scaleX = b.scaleY = 1;
	c.scaleX = c.scaleY = 1;
}

function onResetTransform(event:Event):void
{
	a.transform.matrix = new Matrix(1, 0, 0, 1, a.x, a.y);
	b.transform.matrix = new Matrix(1, 0, 0, 1, b.x, b.y);
	c.transform.matrix = new Matrix(1, 0, 0, 1, c.x, c.y);
}
</pre>
<h2>What Is Going On?</h2>
<p>If you apply a transformation matrix then a scale, the magnitude of the scale is applied, but the direction is determined by the product of the transformation and the scalar&#8230; which is to say that:</p>
<pre class="brush: as3;">a.realScaleX = (a.transform.matrix.a * a.scaleX &gt; 0 ? 1 : -1) * a.scaleX;</pre>
<p>If however you apply a scale then a transformation, the scale is defined by the transformation only!</p>
<pre class="brush: as3;">a.realScaleX = a.transform.matrix.a;</pre>
<h2>Bug?</h2>
<p>Does this qualify as a bug? I haven&#8217;t thought about this for long enough. The conditions in which a transformation matrix rotates and skews the MovieClip confuse me; how would I define scaleX and scaleY in that scenario? I need to give this some thought; perhaps you the community can give me some help! I am reluctant to call anything a bug immediately now, after my experience with my <a href="http://alecmce.com/as3/the-problem-with-vector">The Problem With Vector.&lt;T&gt;</a> post, where I was just plain wrong!</p>
<p>A similar bug exists in Adobe JIRA: <a href="http://bugs.adobe.com/jira/browse/SDK-25247"> UIComponent.scaleX, scaleY differ from transform.matrix.a,d</a>. You&#8217;ll need an account to look at this &#8211; it&#8217;s free, and once you&#8217;ve got it you can pester Adobe with your bugs too.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/gotcha-transform-scale/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>RobotLegsPong Part 1 &#8211; Overview</title>
		<link>http://alecmce.com/as3/robotlegspong1</link>
		<comments>http://alecmce.com/as3/robotlegspong1#comments</comments>
		<pubDate>Tue, 19 Jan 2010 07:01:23 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[as3signals]]></category>
		<category><![CDATA[asunit]]></category>
		<category><![CDATA[RobotLegs]]></category>
		<category><![CDATA[Ticker]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=649</guid>
		<description><![CDATA[Introduction RobotLegsPong attempts to combine RobotLegs application framework with the as3signals event model and a Frame-Ticker (as well as a pinch of ASUnit unit-testing) to create a &#8216;game&#8217;. It is an open-source project, available on GitHub as an example of using RobotLegs together with these other technologies. Source Code: github/alecmce/RobotLegsPong RobotLegsPong is not a very [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>RobotLegsPong attempts to combine RobotLegs application framework with the as3signals event model and a Frame-Ticker (as well as a pinch of ASUnit unit-testing) to create a &#8216;game&#8217;.</p>
<p>It is an open-source project, available on <a href="http://github.com/alecmce/RobotLegsPong/tree/master">GitHub</a> as an example of using RobotLegs together with these other technologies.</p>
<p style="text-align: center;">Source Code: <a href="http://github.com/alecmce/RobotLegsPong/tree/master">github/alecmce/RobotLegsPong</a></p>
<p>RobotLegsPong is not a very good <em>game</em>; it is playable only in the loosest sense. Bats require to be dragged in order to move (and there is no computer-logic to play against), so you could not really play against an opponent. The purpose of the exercise was to see what structure a game like Pong would take within the RobotLegs framework.</p>
<p>The purpose of this article is to describe the particulars of the technologies and why I chose them. In a follow-up article, I will look in more detail how RobotLegsPong is wired up.</p>
<h2>Why I Chose These Technologies</h2>
<h3>RobotLegs</h3>
<p>The RobotLegs framework is a lightweight, flexible application framework that allows coders to spend less time wiring up their application, and more time working on its functionality.</p>
<p>Frameworks are often criticised because they force developers to write code in a particular way, which might be inappropriate for a particular context. I have used Cairngorm, Pure MVC, as well as some proprietary frameworks, and have found that all of them do some things well, and do other things clumsily. So far I have not found this problem with RobotLegs, because most of the time it gets out of the way and lets you code; in fact, it does more than that: it reduces the amount of code you have to write.</p>
<h3>as3signals</h3>
<p>RobotLegs comes with an application event bus, but I have decided to circumvent that and use as3signals instead. as3signals allows you to define an object which acts as an event dispatcher within an application.</p>
<p>I like as3signals because describing an event as a Signal object allows my event model to be described through interfaces. as3signals is supposed to be fast too. Then again, interfaces are slow. The relative speeds of the approaches is interesting, but not a significant factor in my decision making process.</p>
<h3>Frame-Ticker</h3>
<p>The frame-ticker is a simple idea: rather than creating multiple enter-frame event listeners, each creating event objects, create one enter-frame listener and a main game loop iterating through those methods that need to be called per-iteration.</p>
<p>This implementation came out of a discussion on Twitter that I was involved in on the fringes; I wrote about it <a href="http://alecmce.com/as3/replacing-enter_frame">in a previous blog post</a>.</p>
<h3>ASUnit</h3>
<p>Unit testing enables developers to test portions of their code in isolation, so that they can be confident that every method works exactly as the developer intended. They also represent a secondary form of documentation-in-code; if you want to know how I meant a method to work, reading the unit test will tell you almost everything you need to know (including, if a good test is missing, what I <em>didn&#8217;t</em> consider).</p>
<p>That said, I have not unit tested every method; in this example I have only unit-tested the geometric logic for the bats. This is bad practice, however under time constraints I think that it is most important to unit test what is complex, mathematical or ambiguous, since this is where behaviour is most likely to fall down.</p>
<h2>[Inject]</h2>
<p>The &#8216;trick&#8217; to using RobotLegs is that you do not need to inject dependent objects into classes when you contruct them; this is done automatically. This code:</p>
<pre class="brush: as3;">
public class Dependee {}

public class MyExample
{
	public var dependee:Dependee;

	public function MyExample(dependee:Dependee)
	{
		this.dependee = dependee;
	}
}
</pre>
<p>becomes this code:</p>
<pre class="brush: as3;">
public class Dependee {}

public class MyExample
{
	[Inject]
	public var dependee:Dependee;
}
</pre>
<p>The metadata tag <code>[Inject]</code> has the effect of automatically injecting the dependee into the class when it is constructed. This isn&#8217;t much on the face of it, but it is enough. It feels to me as though a quarter of my code is actually just wiring up classes so that they each have access to the classes that they need to function, or passing objects around methods. The <code>[Inject]</code> tag lets me shift all of that wiring into the RobotLegs framework.</p>
<h2>Context</h2>
<p>There is a little more to the RobotLegs story however; how should RobotLegs react when it comes across an <code>[Inject]</code> tag? It could construct a new <code>Dependee</code> object, or it could be that I want only one <code>Dependee</code> object to be injected wherever the <code>[Inject]</code> tag is found. This is where the <code>Context</code> class becomes meaningful.</p>
<p>In the <a href="http://github.com/alecmce/RobotLegsPong/blob/master/src/app/PongContext.as">PongContext</a>, different classes are wired up in different ways. Their definitions are defined by adding <code>injector</code> mappings and the <code>mediatorMap</code> mappings in the <code>startup</code> method.</p>
<pre class="brush: as3;">
public class PongContext extends Context
{
	override public function startup():void
	{
		...
		injector.mapSingleton(DragMechanism);
		injector.mapSingletonOf(Geometry, GeometryModel);
		injector.mapClass(BatGeometry, BatGeometryModel);
		...
	}
}
</pre>
<h3>injector.mapSingleton</h3>
<pre class="brush: as3;">injector.mapSingleton(DragMechanism)</pre>
<p><code>mapSingleton</code> indicates that only one instance of the class entered should be constructed. In this case, just one <code>DragMechanism</code> will be created, and injected whenever this is found:</p>
<pre class="brush: as3;">
[Inject]
public var mechanism:DragMechanism;
</pre>
<h3>injector.mapSingletonOf</h3>
<pre class="brush: as3;">injector.mapSingletonOf(Geometry, GeometryModel);</pre>
<p><code>mapSingletonOf</code> extends the <code>mapSingleton</code> idea to interfaces and their implementing classes. In this case the <code>Geometry</code> interface is mapped to the <code>GeometryModel</code> class. The injection is called as follows:</p>
<pre class="brush: as3;">
[Inject]
public var model:Geometry;
</pre>
<p>No reference to the <code>GeometryModel</code> is needed in any class other than the <code>PongContext</code>. This allows a very pure use of interfaces across the application.</p>
<h3>injector.mapClass</h3>
<pre class="brush: as3;">injector.mapClass(BatGeometry, BatGeometryModel)</pre>
<p><code>injector.mapClass</code> works a little differently; whenever a <code>BatGeometry</code> interface is flagged to be injected, a new instance of <code>BatGeometryModel</code> is constructed and injected into the class, so the following code is used to create the injection:</p>
<p>Each <code>BatMediator</code> needs its own <code>BatGeometry</code> object. By using the <code>mapClass</code> method, multiple <code>BatGeometryModel</code> objects will be constructed, one for each time the following code is found:</p>
<pre class="brush: as3;">
[Inject]
public var model:BatGeometry;
</pre>
<h2>Mediators and Components</h2>
<pre class="brush: as3;">
public class PongContext extends Context
{
	override public function startup():void
	{
		...
		mediatorMap.mapView(Background, BackgroundMediator);

		addChild(new Background());
	}
}
</pre>
<p><code>mediatorMap</code> references a slightly different aspect of the application: your view objects. The <code>mediatorMap</code> allows users to define associations between display objects and <code>Mediator</code>s. These two parts comprise the <em>View</em> aspect of the standard MVC pattern.</p>
<p>The <code>DisplayObject</code> &#8211; in this case <code>Background</code> &#8211; is the asset that you want to be visible on the stage. In my pong example this is essentially just a Sprite, though it might just as well have been imported as a graphical asset in a SWC.</p>
<p>The <code>Mediator</code> is associated with the <code>DisplayObject</code> so that when an instance of the <code>DisplayObject</code> is created, the corresponding <code>Mediator</code> is also constructed. The <code>BackgroundMediator</code> looks something like this:</p>
<pre class="brush: as3;">
public class BackgroundMediator extends Mediator
{
	[Inject]
	public var view:Background;

	override public function onRegister():void
	{
		...
	}
}
</pre>
<p>The <code>DisplayObject</code> <code>Background</code> is injected into the <code>BackgroundMediator</code> when it is constructed. The <code>DisplayObject</code> can then be manipulated. It is an elegant solution that separates display object from UI logic.</p>
<pre class="brush: as3;">addChild(new Background());</pre>
<p>is all that is needed to wire the entire <code>DisplayObject</code>/<code>Mediator</code> combination.</p>
<h3>RobotLegs &#038; Tickers</h3>
<p>The RobotLegs structure is particularly useful for wiring up a <code>Ticker</code>-based application because one ticker can be mapped as a singleton, and injected to all those methods that need to iterate every frame:</p>
<pre class="brush: as3;">
public class PongContext extends Context
{
	override public function startup():void
	{
		...
		injector.mapSingletonOf(Ticker, EnterFrameTicker);
		...
	}
}
</pre>
<h3>RobotLegs with as3signals</h3>
<p>I really like the style of event dispatching that <code>as3signals</code> provides, but my implementation demands that if one class requires another class then it must flag it to be injected, and then the signal wired up in a method flagged as <code>[PostConstruct]</code> (see <a href="http://github.com/alecmce/RobotLegsPong/blob/master/src/app/model/GeometryModel.as">GeometryModel</a>). This doesn&#8217;t feel like the right solution.</p>
<p>Integrating <code>as3signals</code> with RobotLegs is beyond the scope of this article. It looks like Joel Hooks and Robert Penner are making inroads into this problem through <a href="http://groups.google.com/group/as3-signals/browse_thread/thread/fabc7995e9e55ec3#">as3signals&#8217; Google Group</a>. I look forward to seeing what they come up with.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/robotlegspong1/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>ASUnit &#8211; A Conventional Problem</title>
		<link>http://alecmce.com/as3/asunit-a-conventional-problem</link>
		<comments>http://alecmce.com/as3/asunit-a-conventional-problem#comments</comments>
		<pubDate>Thu, 29 Oct 2009 11:32:25 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=422</guid>
		<description><![CDATA[There are several conventions involved in unit-testing. If you use FDT, this structure will be familiar to you. If not, you should get the picture anyway: TestRunner does one thing: starts the unit-test framework by adding the AllTests TestSuite. That AllTests will then in-turn add all of the AllTests in the next level of packages [...]]]></description>
			<content:encoded><![CDATA[<p>There are several conventions involved in unit-testing. If you use <a href="http://www.fdt.powerflasher.com/">FDT</a>, this structure will be familiar to you. If not, you should get the picture anyway:</p>
<p style="text-align: center;"><img src="http://alecmce.com/wp-content/uploads/2009/10/filesystem11.png" alt="A standard structure for a unit-tested project in FDT" title="Unit-Tested Project Structure" width="296" height="374" class="size-full wp-image-423" /></p>
<p>TestRunner does one thing: starts the unit-test framework by adding the <code>AllTests TestSuite</code>. That <code>AllTests</code> will then in-turn add all of the <code>AllTests</code> in the next level of packages (in this case, just the one <code>AllTests</code> in the <code>alecmce</code> package). This happens recursively through the entire package tree. Any tests that lie in the same package as an <code>AllTests</code> are added by that <code>AllTests</code>, so <code>alecmce.topsecret.AllTests</code> is responsible for adding <code>alecmce.topsecret.ThisClassWillChangeYourLifeTest</code>.</p>
<p>This convention works really well. More and more people are adopting unit-testing while developing their tools/frameworks. Their tests are published alongside their tools/frameworks, so that you can be confident that they work as anticipated, and so that you can use the tests as a form of documentation for the known working functionality of the tools/frameworks.</p>
<p>Suppose you want to import a tool/framework into your project. For example (as it was the reason that this problem arose), let&#8217;s suppose I want to add <a href="http://github.com/robertpenner/as3-signals">as3signals</a> into my project. Since it has a suite of tests, in case I need to make changes to the library, I want to add those tests to the suite of tests that I run. I download the framework from github and add it to my lib folder, adding the <code>src</code> and <code>test</code> folders as source folders:</p>
<p style="text-align: center;"><img src="http://alecmce.com/wp-content/uploads/2009/10/filesystem2.png" alt="A file-system with as3signals added as a library" title="A file-system with as3signals added as a library" width="346" height="685" class="size-full wp-image-424" /></p>
<p>There&#8217;s a problem here. There are two classes in the default package called <code>AllTests</code>. First there&#8217;s mine, which is responsible for adding <code>alecmce.AllTests</code>, then there&#8217;s also as3signal&#8217;s which is responsible for adding <code>org.AllTests</code>.</p>
<p>There is no way to differentiate between them; they conflict:</p>
<pre class="brush: as3;">Error: Can not resolve a multiname reference unambiguously. AllTests</pre>
<p>The convention of creating a class called <code>AllTests</code> in each package is clean and simple in the one-library environment. If you import multiple projects then the convention breaks down. Of course, there are other ways of importing libraries into yours: you could package them up as swcs (or else, use the swc provided), or you could create separate projects in <a href="http://www.fdt.powerflasher.com/">FDT</a> and link the projects together (assuming you use <a href="http://www.fdt.powerflasher.com/">FDT</a> of course &#8211; though I&#8217;m sure other environments can work similarly).</p>
<p>For me, that diminishes the point of using unit-testing. I want to have all the code that goes into my project tested all the time. While I don&#8217;t expect to change signals, I want to be able to reassure myself that everything is still working as I anticipate it to <em>for all the code, every time I run my tests</em>.</p>
<h2>A change in convention?</h2>
<p>If instead of <code>AllTests</code> I called my tests <code>TopsecretAllTests</code> or <code>AllTests_topsecret</code> and the signals tests were called <code>SignalsAllTests</code> or <code>AllTests_signals</code> the class ambiguity would disappear. It is feasible however that two people could end up using the same project name under different packages. Then, maybe two people would end up with <code>AllTests_topsecret</code> classes and the ambiguity would persist.</p>
<p>The guaranteed solution is to append the full package name onto each <code>AllTests</code> class: <code>AlllTests_alecmce_topsecret</code> is a candidate. Then, two tests&#8217; packages would only conflict if the packages themselves conflict (in which case the tests are the least of their problems). However, this seems like over-kill.</p>
<p>Unfortunately, because the <code>AllTests</code> convention <em>is</em> the convention, this problem is thorny. Even if the <code>AllTests_topsecret</code> pattern is an acceptable work-around, it will not be adopted by people until the need arises, and then, probably, any number of different practises will emerge. The existing norms are well known, well documented and in common practise. It is, effectively, a problem without a solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/asunit-a-conventional-problem/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Detecting Class-Recursion in AS3</title>
		<link>http://alecmce.com/as3/detecting-class-recursion-in-as3</link>
		<comments>http://alecmce.com/as3/detecting-class-recursion-in-as3#comments</comments>
		<pubDate>Sun, 25 Oct 2009 21:40:21 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[asunit]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=404</guid>
		<description><![CDATA[This article has arisen because I found that every now and again while I was writing unit tests for my code, I would find myself coming across stack overflows caused by an infinite recursion of classes. The unit-testing framework didn&#8217;t provide a very helpful error message informing me what was going wrong. I decided if [...]]]></description>
			<content:encoded><![CDATA[<p>This article has arisen because I found that every now and again while I was writing unit tests for my code, I would find myself coming across stack overflows caused by an infinite recursion of classes. The unit-testing framework didn&#8217;t provide a very helpful error message informing me what was going wrong. I decided if I could amend the framework so that it gave me a message which I could resolve easily. It turns out to be harder than it first appeared.</p>
<h2>The Recursive Problem</h2>
<p>It is unlikely that you would ever write a class like this:</p>
<pre class="brush: as3;">
class Recursive
{
	public function Recursive()
	{
		new Recursive();
	}
}
</pre>
<p>However, there is a context where it&#8217;s not as unlikely as you&#8217;d think. One of the more annoying aspects of test-driven development is the creation of test suites and test classes to reflect each of the packages in your source folder. By convention each package contains an <code>AllTests</code> test suite which adds all the tests within that package. Below is an example:</p>
<pre class="brush: as3;">
package mypackage
{
	import asunit.framework.TestSuite;
	import mypackage.subpackage.AllTests;

	public class AllTests extends TestSuite
	{
		public function AllTests()
		{
			addTest(new mypackage.AllTests());
			addTest(new ExampleTestCase());
		}
	}
}
</pre>
<p>If you spotted the deliberate mistake, award yourself ten points. <code>mypackage.AllTests</code> was supposed to add <code>mypackage.subpackage.AllTests</code> as a test suite, but it inadvertently added itself. This will cause a stack overflow in ASUnit. It will tell you that:</p>
<pre class="brush: as3;">
Could not create and run test suite: Error: Error #1023: Stack overflow occurred.
</pre>
<p>It&#8217;s accurate, but not massively informative. We can do better than that.</p>
<h2>A Generic Solution</h2>
<p>I wanted to approach the problem generically before applying any solution to the ASUnit framework. How, then, can you detect that a constructor method calls another instance of the same method?</p>
<p>In AS2 there was an <code>arguments.caller</code> object, which would have allowed me to access the referring method. <code>describeType</code> could be used to inspect the caller and the current method, and check whether they&#8217;re the same&#8230; unfortunately, <code>arguments.caller</code> is not supported in AS3, as the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/arguments.html">AS3 Language Reference</a> explains.</p>
<p>However, it is still possible to discover information about the methods in the stack of currently-called elements: by creating (but not throwing) an error. As long as you are running Flash in the debug player, then you can inspect that stack trace created by the error, and determine the sequence of constructions.</p>
<p style="text-align:center;"><a href="http://github.com/alecmce/recursion-watcher/">Check out the github repository for this approach</a></p>
<p>The main class in this repository is the <a href="http://github.com/alecmce/recursion-watcher/blob/master/src/recursionwatcher/ResursionWatcher.as">RecursionWatcher.as</a> file. The workhorse method is the <code>stackIndicatesRecursion</code> method which takes a generated error and inspects the stack trace that it produces to determine whether class-recursion is taking place.</p>
<h2>A Solution for ASUnit?</h2>
<p>So far this I&#8217;ve created this solution generically in its own repository, and I haven&#8217;t tried to integrate it into ASUnit. Some issues need to be thought through:</p>
<ul>
<li>Should this sort of solution be integrated into the TestCase or TestSuite class?</li>
<li>What are the speed implications of adding this? What sort of speed reduction is the extra functionality worth?</li>
<li>Can the functionality be put into a class which decorates the TestCase, minimising the footprint of the core code changes?</li>
</ul>
<p>I will be approaching integrating this work into the latest versions of ASUnit in the next few weeks, but I would like to guage whether this is the most appropriate course of action to take, and whether it&#8217;s even worth putting this sort of test into the framework. All comments welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/detecting-class-recursion-in-as3/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Isometric Fun &#8211; Cuboids</title>
		<link>http://alecmce.com/as3/isometric-fun-cuboids</link>
		<comments>http://alecmce.com/as3/isometric-fun-cuboids#comments</comments>
		<pubDate>Thu, 15 Oct 2009 22:33:52 +0000</pubDate>
		<dc:creator>alec</dc:creator>
				<category><![CDATA[animation]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[asunit]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=379</guid>
		<description><![CDATA[Test Driven Development is a wonderful thing. When I am calm, not under the pressure of deadlines and working most effectively, I would argue that TDD is the optimal way of working. Unfortunately, UI testing does not sit easily within TDD. To really check that graphical code works, you need to see it. I was [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: center; margin-bottom: 10px;">

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="500" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2009/10/VisualizeCuboids1.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2009/10/VisualizeCuboids1.swf" width="500" height="400">
      <!--<![endif]-->
        <p>The Flash plugin is required to view this object.</p>
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

</div>
<p>Test Driven Development is a wonderful thing. When I am calm, not under the pressure of deadlines and working most effectively, I would argue that TDD is the optimal way of working. Unfortunately, UI testing does not sit easily within TDD. To really check that graphical code works, you need to see it.</p>
<p>I was working back through isometry logic that I did almost a year ago, revisiting and writing fresh libraries for a project that my company is working on. I found myself needing to visually test that rendering cuboids in isometric space works exactly as I expect it to. It&#8217;s one thing for ASUnit to &#8216;run green&#8217; in the test cases that I could pre-calculate, and quite another to see all these lovely cuboids drawn out. These tests are useful additions to the suite of work, and I thought it was fun enough to share.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/isometric-fun-cuboids/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
