Skip to content

Commit

Permalink
* Fixed CPAN RT bug #85332 Changes is 0 bytes (this file)
Browse files Browse the repository at this point in the history
  * Fixed CPAN RT bug #87221 Division by Zero

  * t/15_zeroes.t: Added tests for divisions by zero

  * t/16_decimals.t: Added tests for unsupported non-integer arguments
  • Loading branch information
Theo van Hoesel authored and Th.J.v.Hoesel committed Jul 25, 2013
1 parent 57a57c9 commit ba69da8
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 3 deletions.
136 changes: 136 additions & 0 deletions Changes
@@ -0,0 +1,136 @@
2013-07-25 Theo van Hoesel <Th.J.v.Hoesel@gmail.com>

* Fixed CPAN RT bug #85332 Changes is 0 bytes (this file)

* Fixed CPAN RT bug #87221 Division by Zero

* t/15_zeroes.t: Added tests for divisions by zero

* t/16_decimals.t: Added tests for unsupported non-integer arguments

2013-05-14 Dave Cross <dave@dave.org.uk>

* Version 2: Now With Added Moose

2011-11-26 Dave Cross <dave@dave.org.uk>

* lib/Number/Fraction.pm: Fix typo in docs.

* lib/Number/Fraction.pm: Bump version number.

* MANIFEST, t/14_abs.t: Added more tests for 'abs'. Added META.json to
MANIFEST.

2011-11-24 Dave Cross <dave@dave.org.uk>

* lib/Number/Fraction.pm: Implemented the 'abs' function. Tests now pass.

* t/14_abs.t: Added test for the 'abs' function.

2010-03-21 Dave Cross <dave@angel.mag-sol.com>

* lib/Number/Fraction.pm: Added documentation for the exponentiation support.

* lib/Number/Fraction.pm, t/13_exp.t: Added simple support for
exponentiation.

2010-03-15 Dave Cross <dave@angel.mag-sol.com>

* t/13_exp.t: Added tests for exponentiation. And they all pass without any
code changes!

2010-02-09 Dave Cross <dave@dacross.(none)>

* lib/Number/Fraction.pm: Fixed a couple of typos in the Pod. Thanks to
Kornel Umann for spotting them.

2009-06-15 Dave Cross <dave@dave.org.uk>

* Build.PL, lib/Number/Fraction.pm, t/12_invalid.t: Fixed CPAN RT bug #46961
(and added tests). Move VERSION setting into Number/Fraction.pm.

2009-02-21 Dave Cross <dave@dave.org.uk>

* : Removed execute bits on tests.

2008-03-09 Dave Cross <dave@dave.org.uk>

* Build.PL: Fiddled with dependencies. Incremented version number.

2008-03-08 Dave Cross <dave@dave.org.uk>

* MANIFEST: Added Build.PL and META.yml

* lib/Number/Fraction.pm: Changed email address and copyright date

* Build.PL, Makefile.PL: Moved from Makefile.PL to Build.PL.

* lib/Number/Fraction.pm: Use svn revision number. Remove old cvs logs.

* MANIFEST: Make non-executable

* t/01_load.t, t/02_create.t, t/03_create.t, t/04_add.t, t/05_subtract.t,
t/06_multiply.t, t/07_divide.t, t/08_compare.t, t/09_neg.t: Switch to using
Test::More throughout. Remove old Test.pm black magic comments.

* : Make non-executable

2006-03-02 Dave Cross <dave@dave.org.uk>

* t/05_subtract.t: fixed one test that failed after applying previous fixes.

* lib/Number/Fraction.pm, t/02_create.t: A couple of patches supplied by
David Westbrook.

2005-10-22 Dave Cross <dave@dave.org.uk>

* lib/Number/Fraction.pm: Added new tests.

* MANIFEST: Added pod coverage tests.

* t/11_pod_coverage.t: Added Pod coverage tests.

2004-10-23 Dave Cross <dave@dave.org.uk>

* lib/Number/Fraction.pm: Improved test coverage (to 100% - Go Me!)

2004-05-23 Dave Cross <dave@dave.org.uk>

* Makefile.PL, lib/Number/Fraction.pm, t/10_pod.t: Changed pod tests. Updated
my email address in Makefile.PL

* Makefile.PL: Changed references to Fraction.pm

* MANIFEST: Added t/10_pod.t

* MANIFEST: Moved Fraction.pm to lib/Number

* Changes: Removed Changes (now autogenerated)

2004-05-22 Dave Cross <dave@dave.org.uk>

* lib/Number/Fraction.pm, t/02_create.t, t/03_create.t, t/04_add.t,
t/05_subtract.t, t/06_multiply.t, t/07_divide.t, t/10_pod.t: Added more
tests. Fixed a couple of bugs that they uncovered.

2004-04-28 Dave Cross <dave@dave.org.uk>

* MANIFEST, lib/Number/Fraction.pm: Added negative tests to MANIFEST

2004-04-27 Dave Cross <dave@dave.org.uk>

* lib/Number/Fraction.pm: Added support for negative numbers.

* t/09_neg.t: Added tests for negative numbers

2003-02-19 Dave Cross <dave@dave.org.uk>

* t/08_compare.t: Corrected invalid string tests. '1/2' lt '1/4' (when
considered as strings)

* lib/Number/Fraction.pm: Correct '+0' to '0+'. Added "fallback" - which
allowed me to remove cmp and ncmp.

* Changes, MANIFEST, Makefile.PL, README, lib/Number/Fraction.pm,
t/01_load.t, t/02_create.t, t/03_create.t, t/04_add.t, t/05_subtract.t,
t/06_multiply.t, t/07_divide.t, t/08_compare.t: Initial revision
10 changes: 7 additions & 3 deletions lib/Number/Fraction.pm
Expand Up @@ -126,7 +126,7 @@ use warnings;
use Carp;
use Moose;

our $VERSION = '2.00';
our $VERSION = '2.01';

use overload
q("") => 'to_string',
Expand Down Expand Up @@ -221,7 +221,7 @@ around BUILDARGS => sub {
my $class = shift;

if (@_ >= 2) {
die unless $_[0] =~ /^-?[0-9]+\z/ and $_[1] =~ /^-?[0-9]+\z/;
die "numinator and denominator both need to be integers" unless $_[0] =~ /^-?[0-9]+\z/ and $_[1] =~ /^-?[0-9]+\z/;

return $class->$orig({ num => $_[0], den => $_[1] });
} elsif (@_ == 1) {
Expand All @@ -232,7 +232,7 @@ around BUILDARGS => sub {
die "Can't make a $class from a ", ref $_[0];
}
} else {
die unless $_[0] =~ m|^(-?[0-9]+)(?:/(-?[0-9]+))?\z|;
die "numinator and denominator both need to be integers" unless $_[0] =~ m|^(-?[0-9]+)(?:/(-?[0-9]+))?\z|;

return $class->$orig({ num => $1, den => ( defined $2 ? $2 : 1) });
}
Expand All @@ -250,6 +250,7 @@ normalised format.

sub BUILD {
my $self = shift;
die "Denominator can\'t be equal to \'zero\'" if $self->{den} == 0;
$self->_normalise;
}

Expand Down Expand Up @@ -403,6 +404,7 @@ sub div {

if (ref $r) {
if (UNIVERSAL::isa($r, ref $l)) {
die "FATAL ERROR: Division by zero" if $r->{num} == 0;
return (ref $l)->new($l->{num} * $r->{den},
$l->{den} * $r->{num});
} else {
Expand Down Expand Up @@ -477,6 +479,8 @@ sub _hcf {
return $x;
}

__PACKAGE__->meta->make_immutable;

1;
__END__
Expand Down
17 changes: 17 additions & 0 deletions t/15_zeroes.t
@@ -0,0 +1,17 @@
use Test::More 'no_plan';
use Number::Fraction;

my $f = eval { Number::Fraction->new('1/0') };
ok($@, "Denominator of zero should not allowed in string" );

$f = eval { Number::Fraction->new(1 , 0 ) };
ok($@, "Denominator of zero should not allowed in two ints" );

my $zero = Number::Fraction->new (0);
cmp_ok($zero, '==', 0, "created a \'zero\' fraction");

my $qrtr = Number::Fraction->new('1/4');
cmp_ok($qrtr, '==', 0.25, "Created 1/4");

my $divz = eval { $qrtr / $zero };
ok($@, "Division by zero should cause FATAL ERROR");
26 changes: 26 additions & 0 deletions t/16_decimals.t
@@ -0,0 +1,26 @@
use Test::More 'no_plan';
use Number::Fraction ':constants';

my $fract = undef;

$fract = eval { Number::Fraction->new(3.0 , 4) };
cmp_ok($fract, 'eq' , '3/4', "fraction from round decimal numinator as number");

$fract = eval {Number::Fraction->new(3 , 4.0) };
cmp_ok($fract, 'eq' , '3/4', "fraction from round decimal denominator as number");

$fract = eval {Number::Fraction->new('3', '4' ) };
ok($@, "fraction from two healty strings not supported, use numbers instead");

$fract = eval {Number::Fraction->new('3.0', '4' ) };
ok($@, "fraction from round decimal numinator as string not supported");

$fract = eval {Number::Fraction->new('3' , '4.0') };
ok($@, "fraction from round decimal denominator as string not supported");

$fract = eval {Number::Fraction->new(3.5, 4 ) };
ok($@, "Numinator can\'t be a decimal");

$fract = eval {Number::Fraction->new(3 , 4.5) };
ok($@, "Denominator can\'t be a decimal");

0 comments on commit ba69da8

Please sign in to comment.