Tuesday, August 9, 2011

CQ Simulation: Implementing Results

Had to fight a bit with this.

I wrote some code to kick a user off a seat when the time ran out:

if (useTime == 0)

{

currentUser = null;

this.Free = true;

}

This kept giving me a FAIL on the tick method for Seat. Here's the test.


#test when seat occupied

$testSeat = new Seat(60)


$testSeat.Free = $false


for ($a = 0; $a -lt 59; $a++) {

$testSeat.tick()

}


if (!($testSeat.timeleft())) { "FAIL: Time left should still be above 0."}



$testSeat.tick()



if ($testSeat.timeleft()) { "FAIL: Tick method should have reduced time left to 0."}


I was sure something was wrong, but I took a closer look at my test – and it's no longer valid. Once tick is called when the user has no time left, the tick method now resets the time to the original amount.

I marked the test as no longer valid.


Next up, I added some code to interact with the results object. Here's some:


if (d.hasAbandoned(simTick))

{

computerQueue.Remove(d);

results.incrementAbandonded();

}


This method, in addition to removing an expired datauser object, now increments the results object.

The increment method is trivial:


public void incrementAbandonded()

{

usersAbandoned++;

}

And that will do it for tonight.

Next time, I'll do the rest of the results recording. That should give me the basic functionality of the program.

No comments:

Post a Comment