search.cpan.org is shutting down
Taiki Kawakami > Test-LimitDecimalPlaces-0.01 > Test::LimitDecimalPlaces

Test-LimitDecimalPlaces-0.01.tar.gz

Dependencies

Annotate this POD

# CPAN RT

 Open 0
View/Report Bugs
Module Version: 0.01

# NAME

Test::LimitDecimalPlaces - Compare numerical values by limiting number of decimal places

# VERSION

This document describes Test::LimitDecimalPlaces version 0.01

# SYNOPSIS

```    use Test::LimitDecimalPlaces tests => 5; # Can specify the test plan.

# Equality test by default number of decimal places
limit_ok(1.2345678, 1.2345678, 'Test the same floating-point values.');

# Inequality test by default number of decimal places
limit_not_ok( 0.0000001, 0.0000002, 'Test different values' );

# Equality test by specified number of decimal places
limit_ok_by(0.00000001, 0.000000006, 8, 'Test similar value.') ."\n"; # number of decimal places is 8

# Inequality test by specified number of decimal places
limit_not_ok_by( 0.00000001, 0.00000002, 8, 'Test different values.' ); # number of decimal places is 8

# Compare arrays
my @x = ( 0, 1, 0.1, 0.0000001, 0.0000001 );
my @y = ( 0, 1, 0.1, 0.0000001, 0.00000006 );
limit_ok(\@x, \@y, 'Compare arrays.');

# Set a different default number of decimal places
use Test::LimitDecimalPlaces num_of_digits => 6, tests => 1;
limit_ok(1.234567, 1.234566, 'Test the similar floating-point values.');```

# DESCRIPTION

If compare floating point numbers normally, we cannot get the correct result on some environment. This module was made to solve this problem.

This module provides test functions that can compare numerical values by limiting number of decimal places. These functions are using splintf() internally to limit number of decimal places.

# USAGE

use Test::LimitDecimalPlaces;

Use with no args, then number of decimal places to limit defaults 7.

use Test::LimitDecimalPlaces num_of_digits => 6;

Use with argument of 'num_of_digits', then default number of decimal places to limit is set specified number.

This parameter must be a number greater than or equal to zero.

With test plan

This module can specify test plan. Like so:

`    use Test::LimitDecimalPlaces tests => 1;`

And this module can specify own options with test plan. Like so:

`    use Test::LimitDecimalPlaces num_of_digits => 6, tests => 1;`

Test::LimitDecimalPlaces-specific option must come first.

# FUNCTIONS

limit_ok

limit_ok(\$x, \$y, 'Description of test');

limit_ok(\@x, \@y, 'Description of test');

This function compares and check equality between given values by limiting default number of decimal places.

limit_ok_by

limit_ok_by(\$x, \$y, \$num_of_digits, 'Description of test');

limit_ok_by(\@x, \@y, \$num_of_digits, 'Description of test');

Action of this function is almost the same as limit_ok().

But this function uses specified number of decimal places (\$num_of_digits in case of the above instance).

limit_not_ok

limit_not_ok(\$x, \$y, 'Description of test');

limit_not_ok(\@x, \@y, 'Description of test');

This function compares and check inequality between given values by limiting default number of decimal places.

limit_not_ok_by

limit_not_ok_by(\$x, \$y, \$num_of_digits, 'Description of test');

limit_not_ok_by(\@x, \@y, \$num_of_digits, 'Description of test');

Action of this function is almost the same as limit_not_ok().

But this function uses specified number of decimal places (\$num_of_digits in case of the above instance).

# CONFIGURATION AND ENVIRONMENT

Test::LimitDecimalPlaces requires no configuration files or environment variables.

# DEPENDENCIES

Test::Exception (version 0.31 or later)

None reported.

# BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to `bug-test-limitdecimalplaces@rt.cpan.org`, or through the web interface at http://rt.cpan.org.

# AUTHOR

moznion `<moznion@gmail.com>`

Copyright (c) 2012, moznion `<moznion@gmail.com>`. All rights reserved.