Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: 'either or' value unit test case in Test::Simple or Test::More

by ferreira (Chaplain)
on Jan 05, 2007 at 16:43 UTC ( [id://593157]=note: print w/replies, xml ) Need Help??


in reply to Re: 'either or' value unit test case in Test::Simple or Test::More
in thread 'either or' value unit test case in Test::Simple or Test::More

What about an overkill abstract solution?

# is_one_of($val, \@list); sub is_one_of { my $val = shift; my $list = shift; my $test_name = "$val is not one of @$list"; for (@$list) { pass($test_name), return if $val eq $_; } diag "never saw [$val] in [@$list]"; fail($test_name); }

And then palette may say:

is_one_of($var, [ qw(a b) ]);

Update: fixed after grinder's commentreturn and diag added.

Replies are listed 'Best First'.
Re^3: 'either or' value unit test case in Test::Simple or Test::More
by grinder (Bishop) on Jan 05, 2007 at 16:49 UTC

    If $list winds up with duplicate values that match $val, your plan is in big trouble. I would change that to

    for (@$list) { if ($val eq $_) { pass($test_name); return; } } diag "never saw [$val] in [@$list]"; fail($test_name);

    • another intruder with the mooring in the heart of the Perl

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://593157]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-16 18:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found