How do I test for an array?
I have written a module that gets and sets characteristics of an object, and I am using another module called Test::More to test my module. Two of my methods return arrays. One is a simple array of integers. The other is an array of objects.
Using methods/functions from Test::More, how can I test to see whether or not the returned values are arrays? I currently have this:
# set the librarian's term ids; how do I test for this? $librarian->term_ids(3, 614, 601); is(ref($librarian->term_ids), 'ARRAY', 'set term_ids()');
But since the returned value is NOT a reference this always fails.
How can I check to see whether or not $librarian->terms points to an array? Is there some Perl function that tells me what sort of data type a variable defines?
$library->terms doesn't "point to" anything, and $librarian->terms is not a variable, either.
Rather than thinking of it in terms of what the function should return, think of it as what you're expecting. For example, you might:
my @vars = $librarian->term_ids( ... ); is( scalar @vars, 3, "Got back three items" ); is( $vars[0], "Smith", "Checking name" ); is( $vars[1], "HR128", "Checking homeroom" ); ok( !$vars[2], "Checking that Smith is NOT the principal" );
Howzat?
xoa -- Andy Lester => [EMAIL PROTECTED] => www.petdance.com => AIM:petdance