testing and its important was Re: [Tutor] re: Leap year problem

Sean 'Shaleh' Perry shalehperry@attbi.com
Tue Jan 14 21:07:01 2003


On Tuesday 14 January 2003 16:29, Michael Janssen wrote:
>
> no: to quote myself: "note: truth-table entry 3. can't occour". Without
> that testing the specific case could mean you test the sufficient
> condition and leave out the necessary. I leave it to your homework to
> understand this ;-) It's late.
>

this is important to remember as you continue programming.  Testing your =
code=20
can be as difficult as writing it.  Defining the problem in a pedantic wa=
y=20
(and using truth tables sometimes) is a good start.

For instance, let's say I asked you to write a function to tell me if a n=
umber=20
was even.  Sounds easy enough.  Then think "how would i prove to myself t=
hat=20
it worked?".  4 is even, 3 is odd, what about 1? 0?

Same thing for this leap year check.  You need to think "what years hit e=
ach=20
condition?".

For instance:

A.D. 100 was not a leap year but it looks like it might be.  Same with 17=
00=20
A.D.  1600 was a leap year though as was 2000.

As you can see testing is just as important as writing.

During a recent job interview I was asked to write code for an algorithm =
(in=20
this case a sort).  As I scribbled on the white board the interviewer cha=
tted=20
with me about the mechanics of the problem as well as about how I intende=
d to=20
prove it worked.  He was just as interested in my ability to write good c=
ode=20
as he was in my ability to test other people's.