Why not just pass each module a callback function to call when it's done?
Then TestSequence can do all the work.
For example:
class TestModule
{
public function runTest(callback:Function)
{
// Do some testing...
// When done...
callback();
}
}
class TestSequence
{
private var _nTests:Number; // This holds how many tests are currently
running
public function TestSequence()
{
}
public function runTests()
{
_nTests=0;
// Queue up a bunch of tests
var tests:Array=[];
tests.push(new SomeClassDerivedFromTestModule());
tests.push(new SomeOtherClassDerivedFromTestModule());
// Store the callback to avoid recreating delegates all the time
var theCallback:Function=Delegate.create(this,onTestComplete);
for (var i:Number=0;i<tests.length;i++)
{
_nTests++; // Increment the number of tests currently running
tests[i].runTest(theCallback);
}
}
private function onTestComplete()
{
_nTests--;
if (_nTests==0)
{
trace("All tests done...");
}
}
}
On 11/24/05, erixtekila <[EMAIL PROTECTED]> wrote:
>
>
> Le 24 nov. 05, à 19:39, Scott Hyndman a écrit :
>
> > You could have modules aware of their peers (like a graph or linked
> > list structure) and eliminate TestSequence entirely...but it would be
> > kind of odd.
> >
> > Otherwise you could have modules dispatch a notification when
> > complete, and have TestSequence observing the modules. This would make
> > the most sense...and I wouldn't consider it an explicit callback,
> > since the modules will have no knowledge of the sequence's existence.
>
> Yes, that's what I was thinking of.
> But I still have to call the callback.
>
> Here is what I was thinking of :
>
> - TestSequence is composed with an FIFO Array, linked list, whatever…
> - TestModule is a base class with only one method : endTest (b:Boolean)
> - Each Test have to subclass it in order to call endTest when the
> implementing test is achieved.
> The endTest method is not derived by the subclass (it should declared
> as final, but…)
> - ITestElement is an interface that each Test have to implement in
> order to force 1 method : startTest()
>
> Sequentially, TestSequence call each entry of its stack.
> Each TestElement do its stuff and, when finishing or failing, calls
> endTest on the superclass.
> endTest only do one stuff : calls the callback of TestSequence.
> When receiving this message, TestSequence only has to go one stpe
> further.
> And so on…
>
> My goal is to abstract as much as possible the test implementation.
> I'd like to be able to batch as much test as I want.
>
> But, as I am lazy (!), I'd like not to call endTest at all.
> Because I am not sure that I will remember that need in months.
> So, it would be pretty better for me to find an automatic way of being
> called.
>
> Follow me ?
> Any idea ?
>
>
> Thanks by advance.
> -----------
>
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders