in reply to How to write testable command line script?
See also:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to write testable command line script?
by thechartist (Monk) on Nov 25, 2018 at 21:31 UTC | |
Thanks to the numerous examples, along with some deep thought, I have some success to report! While it isn't the prettiest code, my reduce subroutine passes the automated tests. There are still some issues to work out, but the main problems I solved were:reduce.t reduce.pl
| [reply] [d/l] [select] |
by AnomalousMonk (Archbishop) on Nov 26, 2018 at 01:58 UTC | |
... the initial goal of getting the tests to run has been met. I'm looking at your $test_7: (0, 0, -60) -> (-1, 59, 0) (result: -1° 59' 0"). (There's a similar test 7 here with result (-1, 59, 2).) I would have thought the normalized or reduced result to be (0 -1 0) (0° -1' 0"). If the required result shown in the code is correct, it suggests a set of sign propagation rules I have yet to see. Can you expand on this? I notice that you haven't recast your core code into a module yet. Doing so is a good idea for many reasons, including testing. Note that Test::More::use_ok() is available for modules and Test::More::require_ok() for more humble files. The other point that occurred to me is also in terms of general design. Rather than always reduce()-ing deg/min/sec tuples to other d/m/s tuples, it might be less of a headache to normalize d/m/s tuples to, say, integer or decimal fraction arc-seconds (or maybe radians?) or whatever's most convenient, do all the trig in these standard units, then convert back to the ultimate d/m/s (or whatever) output form just once as a final step. Just a thought... Give a man a fish: <%-{-{-{-< | [reply] [d/l] [select] |
by thechartist (Monk) on Nov 26, 2018 at 02:15 UTC | |
Negative numbers are only permitted in the degree column. Any minutes or seconds need to be a positive integer from 0-59 inclusive. Although an angle has a combined decimal and base 60 format, I treat the base 60 components of an angle like the fractional components of a decimal are treated; negatives get propagated to the next highest term. You can find the procedure Albert Klaf's Trigonometry Refresher on page 12; the section is available on google books. As I was going through the tests, I noticed some errors in the tests that I have no idea how they made their way into the code. I suspect they were just typos or search/replace errors I had missed. Regarding extensions to decimals -- that is a planned future extension based upon the problems in the study guide I am going through. Instead of doing the problems manually, I write a program to calculate the solutions, and learn Perl testing in the process :) | [reply] |
by pryrt (Abbot) on Nov 26, 2018 at 15:02 UTC | |
by thechartist (Monk) on Nov 26, 2018 at 15:16 UTC | |
|