Edmund von der Burg > Test-Numeric-0.3 > Test::Numeric

Test-Numeric-0.3.tar.gz

Dependencies

Annotate this POD

# CPAN RT

 New 2 Open 0
View/Report Bugs
Module Version: 0.3

# NAME

Test::Numeric - Testing utilities for numbers.

# SYNOPSIS

``` use Test::Numeric tests => 8;

# The following functions are all exported by Test::Numeric```
``` is_number   '12.34e56',  "valid number";
is_number   '-12.34E56', "valid number";
isnt_number 'test',      "not a number";

is_even 2, "an even number";
is_odd  3, "an odd number";

is_integer   '123',    'an integer';
isnt_integer '123.45', 'not an integer';

is_formatted   '1-.2', '123.45';
isnt_formatted '1-.2', '123.4';```

# DESCRIPTION

This is a simple testing module that lets you do several tests on numbers. You can check that it is a number, check that it is an integer, check if they are odd or even and finally check if they are of a certain form.

is_number
` is_number \$number, \$name;`

`is_number` tests whether `\$number` is a number. The number can be positive or negative, it can have a formatted point and an exponent. These are all valid numbers: 1, 23, 0.34, .34, -12.34e56

isnt_number

The opposite of `is_number`.

is_integer
` is_integer \$number, \$name;`

`is_integer` tests if `\$number` is an integer, ie a whole number. Fails if the number is not a number r not a number at all.

isnt_integer

The opposite of `is_integer`. Note that `isnt_integer` will fail if the number is not a number. So 'abc' may not be an integer but `isnt_integer` will still fail.

is_even
` is_even \$number, \$name;`

`is_even` tests if the number given is even. Fails for non-integers. Zero is even.

is_odd

As `is_even`, but for odd numbers.

is_formatted
`  is_formatted \$format, \$number, \$name;`

`is_formatted` allows you to test that the number complies with a certain format. `\$format` tells the function what to check for and is of the form `pre.suf` where `pre` and `suf` are the number of digits before and after the decimal point. They are either just a number ( eg. '3.2' for something like 123.12 ) or a range ( eg. '3.1-2' ) for either 123.1 or 123.12 ).

The range can be open-ended, for example '0-.2' will match any number of digits before the decimal place, and exactly two after.

If the format is incorrect then the test will fail and a warning printed.

This test is intended for things such as id numbers where the number must be something like `000123`.

isnt_formatted

The same as is_formatted but negated.

is_money
` is_money \$number, \$name;`

This is a conveniance function to test if the value looks like money, ie has a format of `0-.2` - which is tw decimal points. Internally it just calls is_formatted with the correct format.

isnt_money

The opposite of `is_money`.

# TODO

• Create appropriate test names if none is given.
• Add tests to see if a number looks like hex, octal, binary etc.

# AUTHOR

Bug reports, patches, suggestions etc are all welcomed.