Post Reply 
A perfect example!?
08-30-2015, 09:24 AM
Post: #1
A perfect example!?
The HP User Guide has an example so perfect I must share it with you.

There is an example procedure to check whether a number is a perfect number, and a test procedure showing the perfect numbers up to 100. The first of which is 6.
OK, all looking good.
To familiarise myself with my new calculator, I typed this in.
I was curious as to whether -6 was also a perfect number and also wanted to check that the Is Perfect routine didn't contain any nasties, like looping forever on an unexpected negative.
It didn't loop forever. But now it showed 1 as the first number.
Checking Wikipedia, 1 isn't a perfect number.
So why did Isperfect originally not show 1, and then did?

Inspecting the test harness, that is described as showing all perfect numbers up to 100, we see that it actually begins testing at 2, rather than the more obvious 1 or 0, which is why it never checked whether Isperfect was working correctly for 0 or 1.

Some more suspicious than I might wonder whether someone knew there was a bug in Isperfect and adjusted the test harness to avoid revealing the bug. Or whether other HP tests pass similarly.

But as it is, this example is a perfect example for debugging, and teaching that it's best to put the recognition test in one place, not - in effect - putting some "is it" tests in a separate routine.

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
A perfect example!? - StephenG1CMZ - 08-30-2015 09:24 AM
RE: A perfect example!? - Paul Dale - 08-30-2015, 09:47 AM
RE: A perfect example!? - debrouxl - 08-30-2015, 07:00 PM

User(s) browsing this thread: 1 Guest(s)