converting lists to array for testing purposes

Discussion in 'Perl Misc' started by John, Feb 26, 2004.

  1. John

    John Guest

    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::Dumper 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
     
    John, Feb 26, 2004
    #1
    1. Advertising

  2. John

    fifo Guest

    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, [])
    }
     
    fifo, Feb 26, 2004
    #2
    1. Advertising

  3. John

    Anno Siegel Guest

    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::Dumper 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
     
    Anno Siegel, Feb 26, 2004
    #3
  4. John

    Tore Aursand Guest

    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::Differences

    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
     
    Tore Aursand, Feb 26, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken McAndrew

    Validators at cross purposes?

    Ken McAndrew, Jan 5, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    401
    Ken McAndrew
    Jan 6, 2004
  2. Edwin Knoppert
    Replies:
    3
    Views:
    381
    Edwin Knoppert
    Jan 27, 2006
  3. robin
    Replies:
    10
    Views:
    551
    Dave Hansen
    Apr 12, 2006
  4. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    425
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  5. bahoo
    Replies:
    3
    Views:
    316
    Bruno Desthuilliers
    Apr 3, 2007
Loading...

Share This Page