# davorg/number-fraction

A little bit of tidying up.

1 parent 9b498dc commit 7d6696e02ca2ea90904b5465ec8bde89c0ccc8a6 committed
Showing with 10 additions and 7 deletions.
1. +5 −3 lib/Number/Fraction.pm
2. +1 −1 t/15_zeroes.t
3. +4 −3 t/16_decimals.t
8 lib/Number/Fraction.pm
 @@ -221,7 +221,8 @@ around BUILDARGS => sub { my \$class = shift; if (@_ >= 2) { - die "numinator and denominator both need to be integers" unless \$_[0] =~ /^-?[0-9]+\z/ and \$_[1] =~ /^-?[0-9]+\z/; + die "numerator 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) { @@ -232,7 +233,8 @@ around BUILDARGS => sub { die "Can't make a \$class from a ", ref \$_[0]; } } else { - die "numinator and denominator both need to be integers" unless \$_[0] =~ m|^(-?[0-9]+)(?:/(-?[0-9]+))?\z|; + die "numerator 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) }); } @@ -250,7 +252,7 @@ normalised format. sub BUILD { my \$self = shift; - die "Denominator can\'t be equal to \'zero\'" if \$self->{den} == 0; + die "Denominator can't be equal to zero" if \$self->{den} == 0; \$self->_normalise; }
2 t/15_zeroes.t
 @@ -8,7 +8,7 @@ \$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"); +cmp_ok(\$zero, '==', 0, "created a 'zero' fraction"); my \$qrtr = Number::Fraction->new('1/4'); cmp_ok(\$qrtr, '==', 0.25, "Created 1/4");
7 t/16_decimals.t
 @@ -7,7 +7,8 @@ \$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"); +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"); @@ -19,8 +20,8 @@ \$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"); +ok(\$@, "Numerator can't be a decimal"); \$fract = eval {Number::Fraction->new(3 , 4.5) }; -ok(\$@, "Denominator can\'t be a decimal"); +ok(\$@, "Denominator can't be a decimal");