use strict;
use warnings;
use Test::More;
my @good = qw( 12 1 +1 1234 );
my @bad = qw( 1a -3 0.1 .1 0 +0 -0 );
plan 'tests' => scalar @good + scalar @bad;
ok( is_int( $_ ), "[$_] is int" ) for @good;
ok( ! is_int( $_ ), "[$_] is not int" ) for @bad;
sub is_int {
return ( $_[0] eq int( $_[0] ) && $_[0] > 0 );
}
__END__
1..11
ok 1 - [12] is int
ok 2 - [1] is int
not ok 3 - [+1] is int
# Failed test '[+1] is int'
# in perlmonks.pl at line 14.
ok 4 - [1234] is int
Argument "1a" isn't numeric in int at perlmonks.pl line 18.
ok 5 - [1a] is not int
ok 6 - [-3] is not int
ok 7 - [0.1] is not int
ok 8 - [.1] is not int
ok 9 - [0] is not int
ok 10 - [+0] is not int
ok 11 - [-0] is not int
# Looks like you failed 1 test of 11.
Oops. I should have named that is_positive_int, etc.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|