in reply to Re^2: How to write testable command line script?
in thread How to write testable command line script?

... 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:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^4: How to write testable command line script?
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 :)

      That does not seem right to me. From how I understand it, -60 seconds or -1 minute is NOT the same as -1degree 59minutes. That's like saying, in time math, that subtracting 60 seconds is the same as subtracting 1 hour 59 minutes: really, in h:m:s, -60s = -0:01:00; or, in a similar procedure in decimal math, that's like saying that subtracting 10/100ths from 0 would convert -10/100 to -1/10, and then to carry the negative sign, add 10/10 and subtract 1 unit, which would be -1.90 -- when it should really be -10/100 reduces to -1/10, and then the negative sign carries out to the unit of 0, so -0.10.

      Think of it this way, in the final DMS or HMS notations, the DMS/HMS operators are a higher precedence than the unary minus operator -- so -0° 1' 0" is equivalent to -(0° 1' 0") = -(0 + 1/60 + 0/3600) = -(0 + 0/60 + 60/3600) = -60/3600 = -60 seconds

      Checking a few online calculators/converters, they seem to agree with me. (I haven't yet found something more authoritative than a calculator... but it matches my reasoning above): If I go to this online DMS converter, and change -0.0167 (which is slightly more negative than -1/60 of a degree, or -1minute), it reads -0° 1' 0.12". And on another online tool, if you start with 0° 0' 0", and subtract 0° 1' 0", you get -0° 1' 0". Can you show a reference where -60seconds is displayed as -1° 59' 0"?

        This is not a degree to decimal converter. This takes angles in deg,min,sec format (all integers) and adds or subtracts them.

        The degree min sec format is a polynomial of the form (10^x)a + (1/60)a + (1/3600)a, if we were going to express this as decimal, where a and x are integers. This is no different from any decimal, which is in powers of 10: (10^2)a + 10b + c + (10^-1)d + (10^-2)e ...; we always simplify decimal numbers by borrowing from the next highest term if subtraction is negative, and carrying excess if addition results in a number greater than equal to the base we are working in.

        The book I cited in my previous post (Trigonometry Refresher by Albert Klaf) describes the procedure on page 12. I would post the link, but I don't believe links make it through correctly. Google books has that page available.

        As for online calculators -- I have found issues with them that are not consistent with what I understand to be the algebraic properties of angle addition and subtraction. Any calculator that does not reduce 60 min to 1 degree by carrying over to the next higher term, is not correct. I will consider your argument and see if I can come up with a proof of my method, or counter-example to yours, later, if the above does not persuade you.