HP Forums
Po-man's code coverage for HP 48, 50g, etc. - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: Po-man's code coverage for HP 48, 50g, etc. (/thread-1264.html)



Po-man's code coverage for HP 48, 50g, etc. - HP67 - 05-07-2014 05:38 PM

I had a relatively complicated CASE statement at the end of some calculations and I didn't have test cases that I knew would drive each case condition. I realized if I just started testing I didn't have a good way to see if each case was exercised.

Instead of the usual display statement I decided to use the user flags since the 48 has 64 and the 50g has 128, plenty for my purposes.

First I wrote a small RPL program to clear all the user flags with a FOR NEXT loop. I realize you can whip up two flag words with one of them cleared and just STOF or even save and restore the flags in a variable, but this little piece of code is just as simple to use since the calculator displays the VARS and you just hit a soft menu button. Chef's choice.

Then I added code to set the flag as part of each case THEN clause. 1 SF for the first condition, 2 SF for the second, etc.

Next I wrote a small program to run through the user flags and display the number of each flag that was set.

Finally I tested my program with a bunch of data and after each test I ran my display program. When all the flags were set I knew I had covered all the code in the CASE statement.

I like using flags for testing and code coverage because unlike display statements they don't affect the stack and can be left in "production" code. The 48 even displays the first 5 in the annunciator area which is really great. I thought the 50g did that too but in my testing I didn't see any change in the display.

I know there are some real heavy-duty RPL and assembly developers on the forums but I haven't seen debugging articles or info. So I hope somebody finds this useful.


RE: Po-man's code coverage for HP 48, 50g, etc. - Marcus von Cube - 05-13-2014 11:07 PM

The trick seems to be suitable for the WP 34S, two. Checking the flags is easy with the STATUS functionality. Clearing all flags is just a matter of executing a single command (CFALL).


RE: Po-man's code coverage for HP 48, 50g, etc. - HP67 - 05-14-2014 06:01 AM

Thanks, Marcus! Excellent news.