Tuesday, August 23, 2011

CQ Simulation: More Tests 2

More method tests today.

I wanted to make sure that these tests are testing the methods themselves, without mixing up the different things to be tested. This means some of these are quite boring:


# Test the timeLeft method


$testSeat = new Seat(60)

if (!($testSeat.timeLeft())) {"FAIL: Time Left should be true."}


Well, maybe there's more later, but for now, next: DataUser constructor:


# queue up time, patience time, desired time.

$testDataUser = new DataUser(1, 2, 3)


And now for 0 values:


$testDataUser = new DataUser(0, 0, 0)

This one caused an exception. Just one problem – well, look at the code:


if (queueUpTime [LESSTHAN] 0) { throw new Exception(); }

if (patienceTime [LESSTHAN] 0) { throw new Exception(); }

if (desiredTime [LESSTHAN] 0) { throw new Exception(); }

Zero is not less than zero. Here – let's try something:


// if (queueUpTime [LESSTHAN] 0) { throw new Exception(); }

// if (patienceTime [LESSTHAN] 0) { throw new Exception(); }

// if (desiredTime [LESSTHAN] 0) { throw new Exception(); }

Same error:

New-Object : Exception calling ".ctor" with "3" argument(s): "Exception of type 'System.Exception' was thrown."

I suspected as much. It seems there is another place in the code that is throwing this exception.

Oh, I was looking at the wrong place in the code. Here's the code for verifying the constructor:

if (X_queueUpTime [LESSTHAN] 0) { throw new Exception(); }

if (X_patienceTime [LESSTHAN] 1) { throw new Exception(); }

if (X_desiredTime [LESSTHAN] 1) { throw new Exception(); }

So, let's make this into an expected fail and we're done.

try {

$testDataUser = new DataUser(0, 0, 1)

"FAIL: Accepting input outside acceptable range."

} catch {}


try {

$testDataUser = new DataUser(0, 1, 0)

"FAIL: Accepting input outside acceptable range."

} catch {}

More next time.


No comments:

Post a Comment