Friday, July 8, 2011

CQ Simulation: Testing

Well, this is why tests should only have one aspect of the program that they test.

Here's the code around what happens during a tick:

if (thisTick < queueUpTime) return;


if (sitting) { patienceTime--; }


else { desiredTime--; }

And I got it backwards: Patience time should be decremented when you are waiting in line, not after you are sitting at a computer.

But the first version of the test didn't find that -- not minor -- problem.

I'll fix it and clean up the tests:


# Test sitting field.


$testSitting = new DataUser (100, 100, 100)


if ($testSitting.testSitting()) { "FAIL: sitting variable should be false." }


$testSitting.sitDown()


if (!($testSitting.testSitting())) { "FAIL: sitting variable should be true." }



# Test patience field


$testTick = new DataUser (7, 1, 100)



$testTick.tick(9)


try {


$testTick.tick(9)


"FAIL: Tick should decrement patience field."


}



catch {}



# Test desired time field:


$testTick = new DataUser (7, 100, 1)


$testTick.sitDown()


$testTick.tick(9)



try {


$testTick.tick(9)


"FAIL: Tick should decrement desired time field."


}



catch {}

And now it is testing what it is supposed to be testing and doing what it is supposed to be doing.

No comments:

Post a Comment