Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > converting lists to array for testing purposes

Reply
Thread Tools

converting lists to array for testing purposes

 
 
John
Guest
Posts: n/a
 
      02-26-2004
Hi all,

I am trying to write a test and the result expected from the module is
a list of lists. I will use Test module to check if the result is the
same than the expected.

Anyone know how this can be done? I could compare value by value or
parse the Data:umper value into an String but I am sure this is
something trivial to do in another way. As trivial that I can find how
on the reference.


Thanks for helping me
J
 
Reply With Quote
 
 
 
 
fifo
Guest
Posts: n/a
 
      02-26-2004
At 2004-02-26 08:25 -0800, John wrote:
> I am trying to write a test and the result expected from the module is
> a list of lists. I will use Test module to check if the result is the
> same than the expected.
>


Do you mean something like this:

#!/usr/bin/perl
use strict;
use warnings;
use Test::Simple tests => 2;

sub test {
grep(ref eq 'ARRAY', @_) == @_
}

ok(test returns_list_of_arrayrefs());
ok(test returns_something_else());

sub returns_list_of_arrayrefs {
([1, 2, 3], [4, 5], [])
}

sub returns_something_else {
([1, 2, 3], 45, [])
}
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      02-26-2004
John <> wrote in comp.lang.perl.misc:
> Hi all,
>
> I am trying to write a test and the result expected from the module is
> a list of lists. I will use Test module to check if the result is the
> same than the expected.
>
> Anyone know how this can be done? I could compare value by value or
> parse the Data:umper value into an String but I am sure this is
> something trivial to do in another way. As trivial that I can find how
> on the reference.


Try Test::More (a standard module, like Test). It has methods that help
with this kind of thing. eq_array should be what you're looking for.

Anno
 
Reply With Quote
 
Tore Aursand
Guest
Posts: n/a
 
      02-26-2004
On Thu, 26 Feb 2004 08:25:05 -0800, John wrote:
> I am trying to write a test and the result expected from the module is a
> list of lists. I will use Test module to check if the result is the same
> than the expected.


Have you had a look at these modules?

Test::More
Test:ifferences

You can find them at CPAN:

<http://www.cpan.org/>


--
Tore Aursand <>
"First, God created idiots. That was just for practice. Then He created
school boards." -- Mark Twain
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to have a list of lists (or array of lists) bahoo Python 3 04-03-2007 07:37 PM
List of lists of lists of lists... =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?= Python 5 05-15-2006 11:47 AM
converting lists to strings to lists robin Python 10 04-12-2006 04:58 PM
PBR for load sharing purposes paranic Cisco 2 11-02-2005 02:37 PM
Validators at cross purposes? Ken McAndrew ASP .Net 2 01-06-2004 05:13 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57