I can't really test display until I've got something to display. I'll start with the tick method.
I'll start by testing for a second hand. Here's basic PS code for that:
$testHandTick = new Hand(60, 1)
for ($a = 0; $a -lt 700; $a++)
{
if (!($testHandTick.tick())) { "FAIL: Tick method should return True."}
}
Wait, wait, wait – I need to simplify a little. Here are some test cases that should matter:
no ticks
1 tick
10 ticks
59 ticks
60 ticks
700 ticks
90000 ticks (more than one day)
I need to implement something like these for each version of the Hand class.
This looks like it needs a function. How about this:
function testSecondHand ($in) {
$testHandTick=new Hand(60, 1)
for ($a = 0; $a -lt $in; $a++)
{
if (!($testHandTick.tick())) { "FAIL: Tick method should return True."}
}
$testHandTick.Display
}
Here's some ad hoc testing:
PowerShell: testSecondHand 6060
PowerShell: testSecondHand 12059
PowerShell: testSecondHand 18058
Um, what?
Oops – that's a problem with the code:
state++;
if (state > maxState)
{
state = 0;
}
return true;
It goes from 0 to 60 to 0 again.
So, how are clocks marked? There isn't a 0 position on watch dials.
state++;
if (state > maxState)
{
state = 1;
}
return true;
PowerShell: testSecondHand 60
60
PowerShell: testSecondHand 120
60
PowerShell: testSecondHand 180
60
OK, then I roughed out testMinuteHand. Here's an ad hoc result:
PowerShell: testMinuteHand 2
0
That's not right. If a second hand should be displaying 60 or 1, so should a minute hand.
Let's go back to the code.
OK, maybe I should have planned more in advance. Give me a minute here.
OK, back into the code. Think I have it right, but before I test, let's get some test cases written into the script.
Here are the tests for second, minute, and hour:
testSecondHand 0 60
testSecondHand 1 1
testSecondHand 10 10
testSecondHand 59 59
testSecondHand 60 60
testSecondHand 61 1
testSecondHand 120 60
testSecondHand 240 60
testMinuteHand 0 60
testMinuteHand 1 60
testMinuteHand 10 60
testMinuteHand 59 60
testMinuteHand 60 1
testMinuteHand 61 1
testMinuteHand 120 2
testMinuteHand 240 4
testMinuteHand 3599 59
testMinuteHand 3600 60
testMinuteHand 3601 60
testHourHand 0 12
testHourHand 1 12
testHourHand 10 12
testHourHand 59 12
testHourHand 60 12
testHourHand 61 12
testHourHand 120 12
testHourHand 240 12
testHourHand 3599 12
testHourHand 3600 1
testHourHand 3601 1
testHourHand 7200 2
testHourHand 43199 11
testHourHand 43200 12
testHourHand 43201 12
I revised the functions to take an expected value. All these tests match the expected values.
I need to wrap up for the day.
The Day hand is still acting in a way I don't understand. That will be my project for tomorrow.
No comments:
Post a Comment