I wrote a command line script to aid my review of trigonometry, and improve my understanding of Perl and its testing tools.
My initial script accepts 2 sequences 3 integers (representing the degrees, minutes, and seconds of an angle. Positive and negative values are accepted), separated by any one of the basic arithmetic operations (+,-,*). It returns the correct arithmetic result in reduced form (ie. min or sec must be a positive integer from 0-59, with borrow/carry done appropriately).
prompt> trg_calc 179 0 59 + 0 59 1
Reduced Answer: 180 0 0
My manual testing indicates it works as I intend. When I run perl -w and perl -c on the script, no problems occur.
My goal was to write this with automated testing in mind. This is where I have problems.
I am going by the example in the Perl Testing: A Developer's Notebook for testing scripts (vs. modules). FWIW, I have not read it in depth; I have skipped around trying to pick out what appears immediately useful.
Here is my test file:
use Test::More 'no_plan';
my $test_path = "C:/Users/Greyhat/PDL_Old/trig/src";
# Degree Addition Tests
ok( main() eq 'Operation is undef.', '2
+. Tests invocation with empty arg list');
ok( main( '90 35 29 + 90 24 29' ) eq '180, 59, 58', '3
+. no carry needed' );
ok( main( '179 0 59 + 0 0 1' ) eq '179 1 0', '4
+. test if single carry works correctly' );
ok( main( '179 0 59 + 0 59 1' ) eq '180 0 0', '5
+. tests if multiple carry works correctly' );
ok( main( '-179 0 59 + 0 59 1' ) eq '-178 0 0 ', '6
+. test mainition with negatives' );
ok( main( '0 0 1 + 0 0 59' ) eq '0 1 0', '7
+. test if single reduce works correctly' );
ok( main( '90 180 270 + 0 180 90' ) eq '96 6 0', '8
+. tests if multiple reduce calls work correctly' );
With that, I get a host of uninstantiated variable errors, even for things that are declared in the source file, so it appears that my arguments are not making it all the way to the needed subroutine.
My assumption is that calling the main function like this simulates the actions of someone invoking this from the command line. When I do use the script from the command line, it works as I expect, so there must be a gap in my understanding of the testing tools.
The tests for reading the file in and the one for invoking with empty arguments, pass. But all of the other ones fail.
Some of my concerns about the tests above:
1. The expression is in quotes, when I would simply prefer to pass an array of numbers. I've tried that, but I still get syntax errors when I run the test file under perl -c trig_calc.t.
2. How should I use return values in the *.pl file so the test tools have something to check? I am not exactly clear how the return values are used.
3. How should I test for array equality in this particular case? I don't think numeric equality is correct here.
Thanks for the assistance.