× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




On 31/03/2008, at 4:44 PM, Joe D wrote:

Ok - just looked at my actual code, and I think this was a typo - my code
is:
Quarter=%div(Month:3) + 1;

That gives the correct answer for months 1 - 11. Still missed the obvious
bug, but not as bad as I thought.

Nope. That's just as bad.

DSPLY 1=1
DSPLY 2=1
DSPLY 3=2
DSPLY 4=2
DSPLY 5=2
DSPLY 6=3
DSPLY 7=3
DSPLY 8=3
DSPLY 9=4
DSPLY 10=4
DSPLY 11=4
DSPLY 12=5

Should be:
quarter = %div(month-1:3) + 1;

presuming you want calendar quarters and not fiscal quarters--but even that's easy to do.

This illustrates another classic trap: My code works correctly! Or how can it be broken? It's just one line of code!

You have to test properly preferably with repeatable, documented test cases. Another one for Scott's list.

Interestingly, the standard strategy of testing boundary conditions plus at least one middle value would not catch the first set of errors.

%div(month:4)+1 gives:

DSPLY 1=1
DSPLY 6=2
DSPLY 12=4

All of which are correct but the algorithm is wrong.

%div(month:3)+1 gives:

DSPLY 1=1
DSPLY 6=3
DSPLY 12=5

For which two are wrong, but:

DSPLY 1=1
DSPLY 4=2
DSPLY 7=3
DSPLY 11=4

Looks OK too but still the algorithm is wrong and months 3, 6, 9, and 12 are wrong.

Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.