Re: test for an array

2003-09-30 Thread Eric Lease Morgan

Thank you for the prompt replies.

On 9/30/03 5:18 PM, "Andy Lester" <[EMAIL PROTECTED]> wrote:

> 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" );

I can implement this, and "think of what you're expecting" makes a lot of
sense. Thank you.

-- 
Eric Morgan



Re: test for an array

2003-09-30 Thread Ed Summers
On Tue, Sep 30, 2003 at 04:56:30PM -0500, Eric Lease Morgan wrote:
>   is(ref($librarian->term_ids), 'ARRAY', 'set term_ids()');

Try Test::More's isa_ok(). It works on objects *and* references.

isa_ok( $librarian->term_ids, 'ARRAY', 'set term_ids()' );

Eric++ for taking the time to do tests! 

//Ed





Re: test for an array

2003-09-30 Thread Andy Lester
At 4:56 PM -0500 9/30/03, Eric Lease Morgan wrote:
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