Geometry-Formula

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

{
   "abstract" : "methods to calculate common geometry formulas.",
   "author" : [
      "Casey Vega <cvega@cpan.org>"
   ],
   "dynamic_config" : 0,
   "generated_by" : "Dist::Zilla version 4.200004, CPAN::Meta::Converter version 2.110930",
   "license" : [
      "perl_5"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: 'methods to calculate common geometry formulas.'
author:
  - 'Casey Vega <cvega@cpan.org>'
build_requires: {}
configure_requires:
  ExtUtils::MakeMaker: 6.31
dynamic_config: 0
generated_by: 'Dist::Zilla version 4.200004, CPAN::Meta::Converter version 2.110930'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html

Makefile.PL  view on Meta::CPAN

use strict;
use warnings;



use ExtUtils::MakeMaker 6.31;



my %WriteMakefileArgs = (
  'ABSTRACT' => 'methods to calculate common geometry formulas.',
  'AUTHOR' => 'Casey Vega <cvega@cpan.org>',
  'BUILD_REQUIRES' => {},
  'CONFIGURE_REQUIRES' => {
    'ExtUtils::MakeMaker' => '6.31'
  },
  'DISTNAME' => 'Geometry-Formula',
  'EXE_FILES' => [],
  'LICENSE' => 'perl',
  'NAME' => 'Geometry::Formula',
  'PREREQ_PM' => {},

README  view on Meta::CPAN



This archive contains the distribution Geometry-Formula,
version 0.02:

  methods to calculate common geometry formulas.

This software is copyright (c) 2011 by Casey Vega.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.


lib/Geometry/Formula.pm  view on Meta::CPAN

    $x = $PI *
      ( $self->_squared( $param{'outer_radius'} ) - $self->_squared( $param{'inner_radius'} ) );

    return $x;
}

sub circle {
    my ( $self, %param, $x ) = @_;
    _param_check( 'circle', %param );

    if ( $param{'formula'} eq 'area' ) {
        $x = $PI * $self->_squared( $param{'radius'} );
    }
    elsif ( $param{'formula'} eq 'circumference' ) {
        $x = ( 2 * $PI ) * $param{'radius'};
    }
    else {
        $x = $param{'radius'} * 2;
    }

    return $x;
}

sub cone {

lib/Geometry/Formula.pm  view on Meta::CPAN


    $x = ( 1 / 3 ) * ( $param{'base'} * $param{'height'} );

    return $x;
}

sub cube {
    my ( $self, %param, $x ) = @_;
    _param_check( 'cube', %param );

    if ( $param{'formula'} eq 'surface_area' ) {
        $x = 6 * ( $param{'a'} * 2 );
    }
    else {
        $x = $self->_cubed( $param{'a'} );
    }

    return $x;
}

sub ellipse {
    my ( $self, %param, $x ) = @_;
    _param_check( 'ellipse', %param );

    if ( $param{'formula'} eq 'area' ) {
        $x = $PI * ( $param{'a'} * $param{'b'} );
    }
    else {
        $x = 2 * $PI *
          sqrt( ( $self->_squared( $param{'a'} ) + $self->_squared( $param{'b'} ) ) / 2 );
    }

    return $x;
}

lib/Geometry/Formula.pm  view on Meta::CPAN


    $x = $self->_squared( $param{'side'} ) * ( sqrt(3) / 4 );

    return $x;
}

sub frustum_of_right_circular_cone {
    my ( $self, %param, $x ) = @_;
    _param_check( 'frustum_of_right_circular_cone', %param );

    if ( $param{'formula'} eq 'lateral_surface_area' ) {
        $x =
          $PI *
          ( $param{'large_radius'} + $param{'small_radius'} ) *
          sqrt( $self->_squared( $param{'large_radius'} - $param{'small_radius'} ) +
              $self->_squared( $param{'slant_height'} ) );
    }
    elsif ( $param{'formula'} eq 'total_surface_area' ) {
        my $slant_height =
          sqrt( $self->_squared( $param{'large_radius'} - $param{'small_radius'} ) +
              $self->_squared( $param{'height'} ) );

        $x =
          $PI *
          ( $param{'small_radius'} *
              ( $param{'small_radius'} + $slant_height )
              + $param{'large_radius'} *
              ( $param{'large_radius'} + $slant_height ) );

lib/Geometry/Formula.pm  view on Meta::CPAN

        ) / 3;
    }

    return $x;
}

sub parallelogram {
    my ( $self, %param, $x ) = @_;
    _param_check( 'parallelogram', %param );

    if ( $param{'formula'} eq 'area' ) {
        $x = $param{'base'} * $param{'height'};
    }
    else {
        $x = ( 2 * $param{'a'} ) + ( 2 * $param{'b'} );
    }

    return $x;
}

sub rectangle {
    my ( $self, %param, $x ) = @_;
    _param_check( 'rectangle', %param );

    if ( $param{'formula'} eq 'area' ) {
        $x = $param{'length'} * $param{'width'};
    }
    else {
        $x = ( 2 * $param{'length'} ) + ( 2 * $param{'width'} );
    }

    return $x;
}

sub rectangular_solid {
    my ( $self, %param, $x ) = @_;
    _param_check( 'rectangular_solid', %param );

    if ( $param{'formula'} eq 'volume' ) {
        $x = $param{'length'} * $param{'width'} * $param{'height'};
    }
    else {
        $x =
          2 *
          ( ( $param{'length'} * $param{'width'} ) +
              ( $param{'width'} * $param{'height'} ) +
              ( $param{'length'} * $param{'height'} ) );
    }

lib/Geometry/Formula.pm  view on Meta::CPAN


    $x = ( $param{'a'} * $param{'b'} ) / 2;

    return $x;
}

sub right_circular_cone {
    my ( $self, %param, $x ) = @_;
    _param_check( 'right_circular_cone', %param );

    if ( $param{'formula'} eq 'lateral_surface_area' ) {
        $x =
          $PI *
          $param{'radius'} *
          ( sqrt( $self->_squared( $param{'radius'} ) + $self->_squared( $param{'height'} ) ) );
    }
    else {
        $x = ( 1 / 3 ) * $PI * $self->_squared( $param{'radius'} ) * $param{'height'};
    }

    return $x;
}

sub right_circular_cylinder {
    my ( $self, %param, $x ) = @_;
    _param_check( 'right_circular_cylinder', %param );

    if ( $param{'formula'} eq 'lateral_surface_area' ) {
        $x = 2 * $PI * $param{'radius'} * $param{'height'};
    }
    elsif ( $param{'formula'} eq 'total_surface_area' ) {
        $x =
          2 * $PI * $param{'radius'} * ( $param{'radius'} + $param{'height'} );
    }
    else {
        $x = $PI * ( $self->_squared( $param{'radius'} ) * $param{'height'} );
    }

    return $x;
}

lib/Geometry/Formula.pm  view on Meta::CPAN


    $x = ( $param{'theta'} / 360 ) * $PI * $self->_squared( $param{'radius'} );

    return $x;
}

sub sphere {
    my ( $self, %param, $x ) = @_;
    _param_check( 'sphere', %param );

    if ( $param{'formula'} eq 'surface_area' ) {
        $x = 4 * $PI * $self->_squared( $param{'radius'} );
    }
    else {
        $x = ( 4 / 3 ) * $PI * $self->_cubed( $param{'radius'} );
    }

    return $x;
}

sub square {
    my ( $self, %param, $x ) = @_;
    _param_check( 'square', %param );

    if ( $param{'formula'} eq 'area' ) {
        $x = $self->_squared( $param{'side'} );
    }
    else {
        $x = $param{'side'} * 4;
    }

    return $x;
}

sub torus {
    my ( $self, %param, $x ) = @_;
    _param_check( 'torus', %param );

    if ( $param{'formula'} eq 'surface_area' ) {
        $x = 4 * $self->_squared($PI) * $param{'a'} * $param{'b'};
    }
    else {
        $x = 2 * $self->_squared($PI) * $self->_squared( $param{'a'} ) * $param{'b'};
    }

    return $x;
}

sub trapezoid {
    my ( $self, %param, $x ) = @_;
    _param_check( 'trapezoid', %param );

    if ( $param{'formula'} eq 'area' ) {
        $x = ( ( $param{'a'} + $param{'b'} ) / 2 ) * $param{'height'};
    }
    else {
        $x = $param{'a'} + $param{'b'} + $param{'c'} + $param{'d'};
    }

    return $x;
}

sub triangle {
    my ( $self, %param, $x ) = @_;
    _param_check( 'triangle', %param );

    if ( $param{'formula'} eq 'area' ) {
        $x = .5 * $param{'base'} * $param{'height'};
    }
    else {
        $x = $param{'a'} + $param{'b'} + $param{'c'};
    }

    return $x;
}

sub _squared {

lib/Geometry/Formula.pm  view on Meta::CPAN

            area      => [ 'a', 'b', 'height' ],
            perimeter => [ 'a', 'b', 'c', 'd' ]
        },
        triangle => {
            area      => [ 'base', 'height' ],
            perimeter => [ 'a',    'b', 'c' ]
        },
    );

    # validate that parameter values are defined and numeric
    foreach ( @{ $valid_params{$method}{ $param{'formula'} } } ) {
        croak "required parameter '$_' not defined"
          if !$param{$_};

        croak "parameter '$_' requires a numeric value"
          if $param{$_} !~ m/^\d+$/;
    }

    # validate parameter is a valid constructor/component of formula
    foreach my $param ( keys %param ) {
        next if $param eq 'formula';

        my @constructors = @{ $valid_params{$method}{ $param{'formula'} } };

        if ( !@constructors ) {
            croak "invalid formula name: $param{'formula'} specified";
        }

        if ( grep { $_ eq $param } @constructors ) {
            next;
        }
        else {
            croak "invalid parameter '$param' specified for $method";
        }
    }

lib/Geometry/Formula.pm  view on Meta::CPAN

}

1;

__END__

=pod

=head1 NAME

Geometry::Formula - methods to calculate common geometry formulas.

=head1 VERSION

    Version 0.01

=head1 SYNOPSIS

    use Geometry::Formula

    my $x = Geometry::Formula->new;

=head1 DESCRIPTION

This package provides users with the ability to calculate simple geometric
problems using the most common geometry formulas. This module was primarily
written for education and practical purposes.  

=head1 CONSTRUCTOR

=over

=item C<< new() >>

Returns a reference to a new formula object. No arguments currently needed
or required.

=back

=head1 SUBROUTINES/METHODS

The following methods are used to calculate our geometry formulas. Keep in
mind each formula has a unique set of constructors/parameters that are used
and must be provided accordingly. All attempts have been made to prevent a
user from providing invalid data to the method.

Methods are named after the 2d and 3d shapes one would expect to find while
using geometric formulas such as square or cube. Please see the individual
method items for the specific parameters one must use. In the example below
you can see how we make usage of Geometry::Formula:

    use Geometry::Formula;

    my $x   = Geometry::Formula->new;
    my $sqr = $x->square{ formula => 'area', side => 5 };

    print $sqr;
    ---
    25

=over

=item C<< annulus() >>

The annulus method provides an area formula. 

required: inner_radius, outer_radius

    $x->annulus{
        formula      => 'area',
        inner_radius => int,
        outer_radius => int
    };

Note: the inner_radius cannot be larger then the outer_radius.

=item C<< circle() >>

The circle method provides an area, circumference, and diameter formula.

required: radius

    $x->circle(
        formula => 'area',
        radius  => int
    );

    $x->circle(
        formula => 'circumference',
        radius  => int
    );

    $x->circle(
        formula => 'diameter',
        radius  => int
    );

=item C<< cone() >>

The cone method provides a volume formula.

required: base, height

    $x->cone(
        formula => 'volume',
        base    => int,
        height  => int
    );

=item C<< cube() >>

The cube method provides a surface area and volume formula.

required: a

    $x->cube(
        formula => 'surface_area',
        a       => int
    );

    $x->cube(
        formula => 'volume',
        a       => int
    );

=item C<< ellipse() >>

The ellipse method provides an area and perimeter formula.

required: a, b

    $x->ellipse(
        formula => 'area',
        a       => int,
        b       => int
    );

    $x->ellipse(
        formula => 'perimeter',
        a       => int,
        b       => int
    );

Note: a and b represent radii

=item C<< ellipsoid() >>

The ellipsoid method provides a volume formula.

required: a, b, c

    x->ellipsoid(
        formula => 'volume',
        a       => int,
        b       => int,
        c       => int,
    );

Note: a, b, and c represent radii

=item C<< equilateral_triangle() >>

The equalateral_triangle method provides an area formula.

required: side

    x->equilateral_triangle(
        formula => 'area',
        side    => int,
    );

=item C<< frustum_of_right_circular_cone() >>

The frustum_of_right_circular_cone method provides a lateral_surface_area,
total_surface_area, and volume formula.

required: slant_height, large_radius, small_radius

    x->frustum_of_right_circular_cone(
        formula      => 'lateral_surface_area',
        slant_height => int,
        large_radius => int,
        small_radius => int
    );

required: height, large_radius, small_radius

    x->frustum_of_right_circular_cone(
        formula      => 'total_surface_area',
        height       => int,
        large_radius => int,
        small_radius => int

    );

    x->frustum_of_right_circular_cone(
        formula      => 'volume',
        height       => int,
        large_radius => int,
        small_radius => int
    );

=item C<< parallelogram() >>

The parallelogram method provides an area and perimeter formula.

required: base, height

    x->parallelgram(
        formula => 'area',
        base    => int,
        height  => int
    );

required: a, b

    x->parallelgram(
        formula => 'perimeter',
        a       => int,
        b       => int
    );

Note: a and b are sides

=item C<< rectangle() >>

The rectangle method provides an area and perimeter formula.

required: length, width

    x->rectangle(
        formula => 'area',
        length  => int,
        width   => int
    );

    x->rectangle(
        formula => 'perimeter',
        length  => int,
        width   => int
    );

=item C<< rectangular_solid() >>

The rectangular_solid method provides an and perimeter formula.

required: length, width, height

    x->rectangular_solid(
        formula => 'surface_area',
        length  => int,
        width   => int,
        height  => int
    );

    x->rectangular_solid(
        formula => 'volume',
        length  => int,
        width   => int,
        height  => int
    );

=item C<< rhombus() >>

The rhombus method provides an area formula.

required: a, b

    x->rhombus(
        formula => 'area',
        a       => int,
        b       => int
    );

Note: a and b represent diagonal lines (sides)

=item C<< right_circular_cone() >>

The right_circular_cone method provides a lateral surface area formula.

required: height, radius

    $x->right_circular_cone(
        formula => 'lateral_surface_area', 
        height  => int,
        radius  => int
    );

=item C<< right_circular_cylinder() >>

The right_circular_cylinder method provides a side surface area,
total surface area, and volume formula. 

required: height, radius

    $x->right_circular_cylinder(
        formula => 'lateral_surface_area', 
        height  => int,
        radius  => int
    );

    $x->right_circular_cylinder(
        formula => 'total_surface_area', 
        height  => int,
        radius  => int
    );

    $x->right_circular_cylinder(
        formula => 'volume', 
        height  => int,
        radius  => int
    );

=item C<< sector_of_circle() >>

The sector_of_circle method provides an area formula.

required: theta

    $x->sector_of_circle(
        formula => 'area', 
        theta   => int
    );

Note: theta value should not be greater then 360 (degrees).

=item C<< sphere() >>

The sphere method provides a surface area and volume formula.

required: radius

    $x->sphere(
        formula => 'surface_area', 
        radius  => int
    );

    $x->sphere(
        formula => 'volume', 
        radius  => int
    );

=item C<< square() >>

The square method provides an area and perimeter formula.

required: side

    $x->square(
        formula => 'area', 
        side    => int
    );

    $x->square(
        formula => 'perimeter', 
        side    => int
    );

=item C<< torus() >>

The torus method provides a surface area and volume formula.

    $x->torus(
        formula => 'surface_area', 
        a       => int,
        b       => int
    );

    $x->torus(
        formula => 'volume', 
        a  => int,
        b  => int
    );

Note: a and b represent radii

=item C<< trapezoid() >>

The trapezoid method provides an area and perimeter formula.

required: a, b, and height

    $x->trapezoid(
        formula => 'area', 
        a       => int,
        b       => int,
        height  => int
    );

required a, b, c, and d

    $x->trapezoid(
        formula => 'perimeter', 
        a       => int,
        b       => int,
        c       => int,
        d       => int
    );

=item C<< triangle() >>

The triangle method provides an area and perimeter formula.

    $x->triangle(
        formula => 'area', 
        base    => int,
        height  => int
    );

    $x->triangle(
        formula => 'perimeter', 
        a  => int,
        b  => int,
        c  => int
    );

=back 

=head1 HELPER SUBROUTINES/METHODS

While documented typically you will not call these methods directly. These

lib/Geometry/Formula.pm  view on Meta::CPAN

=item C<< $self->_squared( int ) >>

numeric values passed to this function get $self->_squared and returned. 

=item C<<$self->_cubed( int ) >>

numeric values passed to this fucntion get$self->_cubed and returned

=item C<< _param_check( $name_of_method, %param ) >> 

this method validates the parameters being passed into our formula methods
are properly constructed. 

=back

=head1 DIAGNOSTICS 

N/A at the current point in time

=head1 CONFIGURATION AND ENVIRONMENT

t/annulus.t  view on Meta::CPAN

use Test::More tests => 6;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception needed" if $@;
}

my $test = Geometry::Formula->new;

my $annulus =
  $test->annulus( formula => 'area', inner_radius => 5, outer_radius => 10 );
like( $annulus, qr/235.619445/, 'calculation test' );

throws_ok {
    $test->annulus( formula => 'test', outer_radius => 10, inner_radius => 5 );
}
qr/invalid formula name: test specified/, 'valid formula name test';

throws_ok { $test->annulus( formula => 'area', outer_radius => 10 ) }
qr/required parameter 'inner_radius' not defined/,
  'required parameter exception for inner_radius';

throws_ok { $test->annulus( formula => 'area', inner_radius => 10 ) }
qr/required parameter 'outer_radius' not defined/,
  'required parameter exception for outer_radius';

throws_ok {
    $test->annulus(
        formula      => 'area',
        outer_radius => '10',
        inner_radius => '5a'
    );
}
qr/parameter 'inner_radius' requires a numeric value/,
  'formula parameter inner_radius is numeric';

throws_ok {
    $test->annulus(
        formula      => 'area',
        outer_radius => '345a',
        inner_radius => 5
    );
}
qr/parameter 'outer_radius' requires a numeric value/,
  'formula parameter outer_radius is numeric';

t/circle.t  view on Meta::CPAN

use Geometry::Formula;
use Test::More tests => 10;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception needed" if $@;
}

my $test = Geometry::Formula->new;

my $area = $test->circle( formula => 'area', radius => 5 );
like( $area, qr/78.539815/, 'calculation test' );

my $circumference = $test->circle( formula => 'circumference', radius => 5 );
like( $circumference, qr/31.415926/, 'calculation test' );

my $diameter = $test->circle( formula => 'diameter', radius => 5 );
like( $diameter, qr/10/, 'calculation test' );

throws_ok { $test->circle( formula => 'foo', radius => 10 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->circle( formula => 'area', fail => 10 ) }
qr/required parameter 'radius' not defined/,
  'required parameter exception for radius';

throws_ok { $test->circle( formula => 'circumference', fail => 10 ) }
qr/required parameter 'radius' not defined/,
  'required parameter exception for radius';

throws_ok { $test->circle( formula => 'diameter', fail => 10 ) }
qr/required parameter 'radius' not defined/,
  'required parameter exception for radius';

throws_ok { $test->circle( formula => 'area', radius => '5a' ); }
qr/parameter 'radius' requires a numeric value/,
  'formula parameter radius is numeric';

throws_ok { $test->circle( formula => 'circumference', radius => '5a' ); }
qr/parameter 'radius' requires a numeric value/,
  'formula parameter radius is numeric';

throws_ok { $test->circle( formula => 'diameter', radius => '5a' ); }
qr/parameter 'radius' requires a numeric value/,
  'formula parameter radius is numeric';

t/cone.t  view on Meta::CPAN

use Geometry::Formula;
use Test::More tests => 6;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception needed" if $@;
}

my $test = Geometry::Formula->new;

my $volume = $test->cone( formula => 'volume', base => 5, height => 5 );
like( $volume, qr/8.333333/, 'calculation test' );

throws_ok { $test->cone( formula => 'foo', radius => 10 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->cone( formula => 'volume', base => 10 ) }
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok { $test->cone( formula => 'volume', height => 10 ) }
qr/required parameter 'base' not defined/,
  'required parameter exception for base';

throws_ok { $test->cone( formula => 'volume', base => '5a', height => '5' ); }
qr/parameter 'base' requires a numeric value/,
  'formula parameter base is numeric';

throws_ok { $test->cone( formula => 'volume', base => '5', height => '5a' ); }
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

t/cube.t  view on Meta::CPAN

use Geometry::Formula;
use Test::More tests => 7;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception needed" if $@;
}

my $test = Geometry::Formula->new;

my $surface_area = $test->cube( formula => 'surface_area', a => 5 );
like( $surface_area, qr/60/, 'calculation test' );

my $volume = $test->cube( formula => 'volume', a => 5 );
like( $volume, qr/125/, 'calculation test' );

throws_ok { $test->cube( formula => 'foo', a => 10 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->cube( formula => 'volume', b => 10 ) }
qr/required parameter 'a' not defined/, 'required parameter exception for a';

throws_ok { $test->cube( formula => 'surface_area', b => 10 ) }
qr/required parameter 'a' not defined/, 'required parameter exception for a';

throws_ok { $test->cube( formula => 'surface_area', a => '5a', ); }
qr/parameter 'a' requires a numeric value/, 'formula parameter a is numeric';

throws_ok { $test->cube( formula => 'volume', a => '5a', ); }
qr/parameter 'a' requires a numeric value/, 'formula parameter height is numeric';

t/ellipse.t  view on Meta::CPAN

use Geometry::Formula;
use Test::More tests => 11;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception needed" if $@;
}

my $test = Geometry::Formula->new;

my $area = $test->ellipse( formula => 'area', a => 5, b => 10 );
like( $area, qr/157.07963/, 'calculation test' );

my $perimeter = $test->ellipse( formula => 'perimeter', a => 5, b => 10 );
like( $perimeter, qr/49.672940/, 'calculation test' );

throws_ok { $test->ellipse( formula => 'foo', a => 10 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->ellipse( formula => 'area', d => 10, b => 10 ) }
qr/required parameter 'a' not defined/, 'required parameter exception';

throws_ok { $test->ellipse( formula => 'area', a => 10, c => 10 ) }
qr/required parameter 'b' not defined/, 'required parameter exception';

throws_ok { $test->ellipse( formula => 'perimeter', d => 10, b => 10 ) }
qr/required parameter 'a' not defined/, 'required parameter exception';

throws_ok { $test->ellipse( formula => 'perimeter', a => 10, c => 10 ) }
qr/required parameter 'b' not defined/, 'required parameter exception';

throws_ok { $test->ellipse( formula => 'area', a => '5a', b => '5' ); }
qr/parameter 'a' requires a numeric value/, 'formula parameter a is numeric';

throws_ok { $test->ellipse( formula => 'area', b => '5a', a => '5' ); }
qr/parameter 'b' requires a numeric value/, 'formula parameter b is numeric';

throws_ok { $test->ellipse( formula => 'perimeter', a => '5a', b => '5' ); }
qr/parameter 'a' requires a numeric value/, 'formula parameter a is numeric';

throws_ok { $test->ellipse( formula => 'perimeter', b => '5a', a => '5' ); }
qr/parameter 'b' requires a numeric value/, 'formula parameter b is numeric';

t/ellipsoid.t  view on Meta::CPAN

use Geometry::Formula;
use Test::More tests => 8;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception needed" if $@;
}

my $test = Geometry::Formula->new;

my $volume = $test->ellipsoid( formula => 'volume', a => 5, b => 10, c => 15 );
like( $volume, qr/3141.5926/, 'calculation test' );

throws_ok { $test->ellipsoid( formula => 'foo', a => 1, b => 2, c => 3 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->ellipsoid( formula => 'volume', b => 2, c => 3 ) }
qr/required parameter 'a' not defined/,
  'required parameter exception for a';

throws_ok { $test->ellipsoid( formula => 'volume', a => 1, c => 3 ) }
qr/required parameter 'b' not defined/,
  'required parameter exception for b';

throws_ok { $test->ellipsoid( formula => 'volume', a => 1, b => 2 ) }
qr/required parameter 'c' not defined/,
  'required parameter exception for c';

throws_ok { $test->ellipsoid( formula => 'volume', a => '1a', b => 2, c => 3 ); }
qr/parameter 'a' requires a numeric value/,
  'formula parameter a is numeric';

throws_ok { $test->ellipsoid( formula => 'volume', a => 1, b => '2a', c => 3 ); }
qr/parameter 'b' requires a numeric value/,
  'formula parameter b is numeric';

throws_ok { $test->ellipsoid( formula => 'volume', a => 1, b => 2, c => '3a' ); }
qr/parameter 'c' requires a numeric value/,
  'formula parameter c is numeric';

t/equilateral_triangle.t  view on Meta::CPAN

use Geometry::Formula;
use Test::More tests => 4;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception needed" if $@;
}

my $test = Geometry::Formula->new;

my $area = $test->equilateral_triangle( formula => 'area', side => 5 );
like( $area, qr/10.82531/, 'calculation test' );

throws_ok { $test->equilateral_triangle( formula => 'foo', side => 5 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->equilateral_triangle( formula => 'area' ) }
qr/required parameter 'side' not defined/,
  'required parameter exception for side';

throws_ok { $test->equilateral_triangle( formula => 'area', side => '1a' ); }
qr/parameter 'side' requires a numeric value/,
  'formula parameter side is numeric';

t/frustum_of_right_circular_cone.t  view on Meta::CPAN

use Test::More tests => 22;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception needed" if $@;
}

my $test = Geometry::Formula->new;

my $lateral_surface_area = $test->frustum_of_right_circular_cone(
    formula      => 'lateral_surface_area',
    slant_height => 5,
    small_radius => 10,
    large_radius => 15
);
like( $lateral_surface_area, qr/555.36035/, 'calculation test' );

my $total_surface_area = $test->frustum_of_right_circular_cone(
    formula      => 'total_surface_area',
    height       => 5,
    small_radius => 10,
    large_radius => 15
);
like( $total_surface_area, qr/1576.37795279637/, 'calculation test' );

my $volume = $test->frustum_of_right_circular_cone(
    formula      => 'volume',
    height       => 5,
    small_radius => 10,
    large_radius => 15

);
like( $volume, qr/2487.09414166667/, 'calculation test' );

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'foo',
        height       => 5,
        small_radius => 10,
        large_radius => 15
    );
}
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'lateral_surface_area',
        small_radius => 5,
        large_radius => 10
    );
}
qr/required parameter 'slant_height' not defined/,
  'required parameter exception for slant_height';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'lateral_surface_area',
        slant_height => 5,
        large_radius => 10
    );
}
qr/required parameter 'small_radius' not defined/,
  'required parameter exception for small_radius';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'lateral_surface_area',
        slant_height => 5,
        small_radius => 10
    );
}
qr/required parameter 'large_radius' not defined/,
  'required parameter exception for large_radius';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'total_surface_area',
        small_radius => 5,
        large_radius => 10
    );
}
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'total_surface_area',
        height       => 5,
        large_radius => 10
    );
}
qr/required parameter 'small_radius' not defined/,
  'required parameter exception for small_radius';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'total_surface_area',
        height       => 5,
        small_radius => 10
    );
}
qr/required parameter 'large_radius' not defined/,
  'required parameter exception for large_radius';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'volume',
        small_radius => 5,
        large_radius => 10
    );
}
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'volume',
        height       => 5,
        large_radius => 10
    );
}
qr/required parameter 'small_radius' not defined/,
  'required parameter exception for small_radius';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'volume',
        height       => 5,
        small_radius => 10
    );
}
qr/required parameter 'large_radius' not defined/,
  'required parameter exception for large_radius';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'lateral_surface_area',
        slant_height => '5a',
        small_radius => 10,
        large_radius => 15
    );
}
qr/parameter 'slant_height' requires a numeric value/,
  'formula parameter slant_height is numeric';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'lateral_surface_area',
        slant_height => 5,
        small_radius => '10a',
        large_radius => 15
    );
}
qr/parameter 'small_radius' requires a numeric value/,
  'formula parameter small_radius is numeric';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'lateral_surface_area',
        slant_height => 5,
        small_radius => 10,
        large_radius => '15a'
    );
}
qr/parameter 'large_radius' requires a numeric value/,
  'formula parameter large_radius is numeric';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'total_surface_area',
        height       => '5a',
        small_radius => 10,
        large_radius => 15
    );
}
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'total_surface_area',
        height       => 5,
        small_radius => '10a',
        large_radius => 15
    );
}
qr/parameter 'small_radius' requires a numeric value/,
  'formula parameter small_radius is numeric';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'total_surface_area',
        height       => 5,
        small_radius => 10,
        large_radius => '15a'
    );
}
qr/parameter 'large_radius' requires a numeric value/,
  'formula parameter large_radius is numeric';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'volume',
        height       => '5a',
        small_radius => 10,
        large_radius => 15
    );
}
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'volume',
        height       => 5,
        small_radius => '10a',
        large_radius => 15
    );
}
qr/parameter 'small_radius' requires a numeric value/,
  'formula parameter small_radius is numeric';

throws_ok {
    $test->frustum_of_right_circular_cone(
        formula      => 'volume',
        height       => 5,
        small_radius => 10,
        large_radius => '15a'
    );
}
qr/parameter 'large_radius' requires a numeric value/,
  'formula parameter large_radius is numeric';

t/parallelogram.t  view on Meta::CPAN

use Geometry::Formula;
use Test::More tests => 11;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception needed" if $@;
}

my $test = Geometry::Formula->new;

my $area = $test->parallelogram( formula => 'area', base => 5, height => 10 );
like( $area, qr/50/, 'calculation test' );

my $perimeter = $test->parallelogram( formula => 'perimeter', a => 5, b => 10 );
like( $perimeter, qr/30/, 'calculation test' );

throws_ok { $test->parallelogram( formula => 'foo', base => 5, height => 10 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->parallelogram( formula => 'area', base => 10 ) }
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok { $test->parallelogram( formula => 'area', height => 10 ) }
qr/required parameter 'base' not defined/,
  'required parameter exception for base';

throws_ok { $test->parallelogram( formula => 'perimeter', a => 10 ) }
qr/required parameter 'b' not defined/,
  'required parameter exception for b';

throws_ok { $test->parallelogram( formula => 'perimeter', b => 10 ) }
qr/required parameter 'a' not defined/,
  'required parameter exception for a';

throws_ok {
    $test->parallelogram( formula => 'area', base => '5a', height => '5' );
}
qr/parameter 'base' requires a numeric value/,
  'formula parameter base is numeric';

throws_ok {
    $test->parallelogram( formula => 'area', base => '5', height => '5a' );
}
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

throws_ok {
    $test->parallelogram( formula => 'perimeter', a => '5a', b => '5' );
}
qr/parameter 'a' requires a numeric value/, 'formula parameter a is numeric';

throws_ok {
    $test->parallelogram( formula => 'perimeter', a => '5', b => '5a' );
}
qr/parameter 'b' requires a numeric value/, 'formula parameter b is numeric';

t/rectangle.t  view on Meta::CPAN

use Geometry::Formula;
use Test::More tests => 11;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception need" if $@;
};

my $test = Geometry::Formula->new;

my $area = $test->rectangle( formula => 'area', length => 5, width => 10 );
like( $area, qr/50/, 'calculation test' );

my $perimeter =
  $test->rectangle( formula => 'perimeter', length => 5, width => 10 );
like( $perimeter, qr/30/, 'calculation test' );

throws_ok { $test->rectangle( formula => 'foo', length => 5, width => 10 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->rectangle( formula => 'area', length => 10 ) }
qr/required parameter 'width' not defined/,
  'required parameter exception for width';

throws_ok { $test->rectangle( formula => 'area', width => 10 ) }
qr/required parameter 'length' not defined/,
  'required parameter exception for length';

throws_ok { $test->rectangle( formula => 'perimeter', width => 10 ) }
qr/required parameter 'length' not defined/,
  'required parameter exception for b';

throws_ok { $test->rectangle( formula => 'perimeter', width => 10 ) }
qr/required parameter 'length' not defined/,
  'required parameter exception for a';

throws_ok {
    $test->rectangle( formula => 'area', length => '5a', width => '5' );
}
qr/parameter 'length' requires a numeric value/,
  'formula parameter length is numeric';

throws_ok {
    $test->rectangle( formula => 'area', length => '5', width => '5a' );
}
qr/parameter 'width' requires a numeric value/,
  'formula parameter width is numeric';

throws_ok {
    $test->rectangle( formula => 'perimeter', length => '5a', width => '5' );
}
qr/parameter 'length' requires a numeric value/, 'formula parameter a is numeric';

throws_ok {
    $test->rectangle( formula => 'perimeter', length => '5', width => '5a' );
}
qr/parameter 'width' requires a numeric value/, 'formula parameter b is numeric';

t/rectangular_solid.t  view on Meta::CPAN

use Test::More tests => 15;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception need" if $@;
};

my $test = Geometry::Formula->new;

my $volume = $test->rectangular_solid(
    formula => 'volume',
    length  => 5,
    width   => 10,
    height  => 15
);
like( $volume, qr/750/, 'calculation test' );

my $surface_area = $test->rectangular_solid(
    formula => 'surface_area',
    length  => 5,
    width   => 10,
    height  => 15
);
like( $surface_area, qr/550/, 'calculation test' );

throws_ok {
    $test->rectangular_solid(
        formula => 'foo',
        length  => 5,
        width   => 10,
        height  => 15
    );
}
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->rectangular_solid( formula => 'volume', length => 5, width => 10 ) }
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok { $test->rectangular_solid( formula => 'volume', width => 10, height => 15 ) }
qr/required parameter 'length' not defined/,
  'required parameter exception for length';

throws_ok { $test->rectangular_solid( formula => 'volume', length => 5, height => 15 ) }
qr/required parameter 'width' not defined/,
  'required parameter exception for width';

throws_ok { $test->rectangular_solid( formula => 'surface_area', length => 5, width => 10 ) }
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok { $test->rectangular_solid( formula => 'surface_area', width => 10, height => 15 ) }
qr/required parameter 'length' not defined/,
  'required parameter exception for length';

throws_ok { $test->rectangular_solid( formula => 'surface_area', length => 5, height => 15 ) }
qr/required parameter 'width' not defined/,
  'required parameter exception for width';


throws_ok {
    $test->rectangular_solid(
        formula => 'volume',
        length  => '5a',
        width   => '5',
        height  => '5'
    );
}
qr/parameter 'length' requires a numeric value/,
  'formula parameter length is numeric';

throws_ok {
    $test->rectangular_solid(
        formula => 'volume',
        length  => '5',
        width   => '5a',
        height  => '5'
    );
}
qr/parameter 'width' requires a numeric value/,
  'formula parameter width is numeric';

throws_ok {
    $test->rectangular_solid(
        formula => 'volume',
        length  => '5',
        width   => '5',
        height  => '5a'
    );
}
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

throws_ok {
    $test->rectangular_solid(
        formula => 'surface_area',
        length  => '5a',
        width   => '5',
        height  => '5'
    );
}
qr/parameter 'length' requires a numeric value/,
  'formula parameter length is numeric';

throws_ok {
    $test->rectangular_solid(
        formula => 'surface_area',
        length  => '5',
        width   => '5a',
        height  => '5'
    );
}
qr/parameter 'width' requires a numeric value/,
  'formula parameter width is numeric';

throws_ok {
    $test->rectangular_solid(
        formula => 'surface_area',
        length  => '5',
        width   => '5',
        height  => '5a'
    );
}
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

t/rhombus.t  view on Meta::CPAN

use Geometry::Formula;
use Test::More tests => 6;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception need" if $@;
};

my $test = Geometry::Formula->new;

my $area = $test->rhombus( formula => 'area', a => 5, b => 10 );
like( $area, qr/25/, 'calculation test' );

throws_ok { $test->rhombus( formula => 'foo', a => 5, b => 10 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->rhombus( formula => 'area', b => 10 ) }
qr/required parameter 'a' not defined/,
  'required parameter exception for a';

throws_ok { $test->rhombus( formula => 'area', a => 5 ) }
qr/required parameter 'b' not defined/,
  'required parameter exception for b';

throws_ok { $test->rhombus( formula => 'area', a => '1a', b => 10 ); }
qr/parameter 'a' requires a numeric value/,
  'formula parameter a is numeric';

throws_ok { $test->rhombus( formula => 'area', a => '5', b => '1a' ); }
qr/parameter 'b' requires a numeric value/,
  'formula parameter b is numeric';

t/right_circular_cone.t  view on Meta::CPAN

use Test::More tests => 11;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception need" if $@;
};

my $test = Geometry::Formula->new;

my $lateral_surface_area = $test->right_circular_cone(
    formula => 'lateral_surface_area',
    radius  => 5,
    height  => 10
);
like( $lateral_surface_area, qr/175.620365280258/, 'calculation test' );

my $volume = $test->right_circular_cone(
    formula => 'volume',
    radius  => 5,
    height  => 10
);
like( $volume, qr/261.799383333333/, 'calculation test' );

throws_ok {
    $test->right_circular_cone(
        formula => 'foo',
        radius  => 10,
        height  => 15
    );
}
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok {
    $test->right_circular_cone( formula => 'volume', radius => 10 );
}
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok {
    $test->right_circular_cone( formula => 'volume', height => 15 );
}
qr/required parameter 'radius' not defined/,
  'required parameter exception for radius';

throws_ok {
    $test->right_circular_cone(
        formula => 'lateral_surface_area',
        radius  => 10
    );
}
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok {
    $test->right_circular_cone(
        formula => 'lateral_surface_area',
        height  => 15
    );
}
qr/required parameter 'radius' not defined/,
  'required parameter exception for radius';

throws_ok {
    $test->right_circular_cone(
        formula => 'volume',
        radius  => '5a',
        height  => '5'
    );
}
qr/parameter 'radius' requires a numeric value/,
  'formula parameter radius is numeric';

throws_ok {
    $test->right_circular_cone(
        formula => 'volume',
        radius  => '5',
        height  => '5a'
    );
}
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

throws_ok {
    $test->right_circular_cone(
        formula => 'lateral_surface_area',
        radius  => '5a',
        height  => '5'
    );
}
qr/parameter 'radius' requires a numeric value/,
  'formula parameter radius is numeric';

throws_ok {
    $test->right_circular_cone(
        formula => 'lateral_surface_area',
        radius  => '5',
        height  => '5a'
    );
}
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

t/right_circular_cylinder.t  view on Meta::CPAN

use Test::More tests => 16;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception need" if $@;
};

my $test = Geometry::Formula->new;

my $lateral_surface_area = $test->right_circular_cylinder(
    formula => 'lateral_surface_area',
    radius  => 5,
    height  => 10
);
like( $lateral_surface_area, qr/314.15926/, 'calculation test' );

my $total_surface_area = $test->right_circular_cylinder(
    formula => 'total_surface_area',
    radius  => 5,
    height  => 10
);
like( $total_surface_area, qr/471.23889/, 'calculation test' );

my $volume = $test->right_circular_cylinder(
    formula => 'volume',
    radius  => 5,
    height  => 10
);
like( $volume, qr/785.39815/, 'calculation test' );

throws_ok {
    $test->right_circular_cylinder(
        formula => 'foo',
        radius  => 10,
        height  => 15
    );
}
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok {
    $test->right_circular_cylinder(
        formula => 'lateral_surface_area',
        radius  => 10
    );
}
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok {
    $test->right_circular_cylinder(
        formula => 'lateral_surface_area',
        height  => 15
    );
}
qr/required parameter 'radius' not defined/,
  'required parameter exception for radius';

throws_ok {
    $test->right_circular_cylinder(
        formula => 'total_surface_area',
        radius  => 10
    );
}
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok {
    $test->right_circular_cylinder(
        formula => 'total_surface_area',
        height  => 15
    );
}
qr/required parameter 'radius' not defined/,
  'required parameter exception for radius';

throws_ok {
    $test->right_circular_cylinder( formula => 'volume', radius => 10 );
}
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok {
    $test->right_circular_cylinder( formula => 'volume', height => 15 );
}
qr/required parameter 'radius' not defined/,
  'required parameter exception for radius';

throws_ok {
    $test->right_circular_cylinder(
        formula => 'lateral_surface_area',
        radius  => '5a',
        height  => '5'
    );
}
qr/parameter 'radius' requires a numeric value/,
  'formula parameter radius is numeric';

throws_ok {
    $test->right_circular_cylinder(
        formula => 'lateral_surface_area',
        radius  => '5',
        height  => '5a'
    );
}
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

throws_ok {
    $test->right_circular_cylinder(
        formula => 'total_surface_area',
        radius  => '5a',
        height  => '5'
    );
}
qr/parameter 'radius' requires a numeric value/,
  'formula parameter radius is numeric';

throws_ok {
    $test->right_circular_cylinder(
        formula => 'total_surface_area',
        radius  => '5',
        height  => '5a'
    );
}
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

throws_ok {
    $test->right_circular_cylinder(
        formula => 'volume',
        radius  => '5a',
        height  => '5'
    );
}
qr/parameter 'radius' requires a numeric value/,
  'formula parameter radius is numeric';

throws_ok {
    $test->right_circular_cylinder(
        formula => 'volume',
        radius  => '5',
        height  => '5a'
    );
}
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

t/sector_of_circle.t  view on Meta::CPAN

use Geometry::Formula;
use Test::More tests => 6;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception need" if $@;
};

my $test = Geometry::Formula->new;

my $area = $test->sector_of_circle( formula => 'area', theta => 5, radius => 10 );
like( $area, qr/4.36332305555556/, 'calculation test' );

throws_ok { $test->sector_of_circle( formula => 'foo', theta => 5, radius => 10 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->sector_of_circle( formula => 'area', radius => 10 ) }
qr/required parameter 'theta' not defined/,
  'required parameter exception for theta';

throws_ok { $test->sector_of_circle( formula => 'area', theta => 5 ) }
qr/required parameter 'radius' not defined/,
  'required parameter exception for radius';

throws_ok { $test->sector_of_circle( formula => 'area', theta => '1a', radius => 10 ); }
qr/parameter 'theta' requires a numeric value/,
  'formula parameter theta is numeric';

throws_ok { $test->sector_of_circle( formula => 'area', theta => '5', radius => '1a' ); }
qr/parameter 'radius' requires a numeric value/,
  'formula parameter radius is numeric';

t/sphere.t  view on Meta::CPAN

use Test::More tests => 7;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception need" if $@;
};

my $test = Geometry::Formula->new;

my $surface_area = $test->sphere(
    formula => 'surface_area',
    radius  => 5
);
like( $surface_area, qr/314.15926/, 'calculation test' );

my $volume = $test->sphere(
    formula => 'volume',
    radius  => 5
);
like( $volume, qr/523.598766666667/, 'calculation test' );

throws_ok { $test->sphere( formula => 'foo', radius => 15 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->sphere( formula => 'volume' ) }
qr/required parameter 'radius' not defined/,
  'required parameter exception for radius';

throws_ok { $test->sphere( formula => 'surface_area' ) }
qr/required parameter 'radius' not defined/,
  'required parameter exception for radius';

throws_ok { $test->sphere( formula => 'volume', radius => '5a' ); }
qr/parameter 'radius' requires a numeric value/,
  'formula parameter radius is numeric';

throws_ok { $test->sphere( formula => 'surface_area', radius => '5a' ); }
qr/parameter 'radius' requires a numeric value/,
  'formula parameter radius is numeric';

t/square.t  view on Meta::CPAN

use Test::More tests => 7;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception need" if $@;
};

my $test = Geometry::Formula->new;

my $area = $test->square(
    formula => 'area',
    side  => 5 
);
like( $area, qr/25/, 'calculation test' );

my $perimeter = $test->square(
    formula => 'perimeter',
    side  => 5
);
like( $perimeter, qr/20/, 'calculation test' );

throws_ok { $test->square( formula => 'foo', side => 15 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->square( formula => 'area' ) }
qr/required parameter 'side' not defined/,
  'required parameter exception for side';

throws_ok { $test->square( formula => 'perimeter' ) }
qr/required parameter 'side' not defined/,
  'required parameter exception for side';

throws_ok { $test->square( formula => 'area', side => '5a' ); }
qr/parameter 'side' requires a numeric value/,
  'formula parameter side is numeric';

throws_ok { $test->square( formula => 'perimeter', side => '5a' ); }
qr/parameter 'side' requires a numeric value/,
  'formula parameter side is numeric';

t/torus.t  view on Meta::CPAN

use Test::More tests => 11;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception need" if $@;
};

my $test = Geometry::Formula->new;

my $surface_area = $test->torus(
    formula => 'surface_area',
    a       => 5,
    b       => 10
);
like( $surface_area, qr/1973.92081287495/, 'calculation test' );

my $volume = $test->torus(
    formula => 'volume',
    a       => 5,
    b       => 10
);
like( $volume, qr/4934.80203218738/, 'calculation test' );

throws_ok { $test->torus( formula => 'foo', a => 5, b => 10 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->torus( formula => 'surface_area', b => 10 ) }
qr/required parameter 'a' not defined/,
  'required parameter exception for a';

throws_ok { $test->torus( formula => 'surface_area', a => 5 ) }
qr/required parameter 'b' not defined/,
  'required parameter exception for b';

throws_ok { $test->torus( formula => 'volume', b => 10 ) }
qr/required parameter 'a' not defined/,
  'required parameter exception for a';

throws_ok { $test->torus( formula => 'volume', a => 5 ) }
qr/required parameter 'b' not defined/,
  'required parameter exception for b';

throws_ok { $test->torus( formula => 'surface_area', a => '5a', b => 10 ); }
qr/parameter 'a' requires a numeric value/,
  'formula parameter a is numeric';

throws_ok { $test->torus( formula => 'surface_area', a => '5', b => '10a' ); }
qr/parameter 'b' requires a numeric value/,
  'formula parameter b is numeric';

throws_ok { $test->torus( formula => 'volume', a => '5a', b => 10 ); }
qr/parameter 'a' requires a numeric value/,
  'formula parameter a is numeric';

throws_ok { $test->torus( formula => 'volume', a => '5', b => '10a' ); }
qr/parameter 'b' requires a numeric value/,
  'formula parameter b is numeric';

t/trapezoid.t  view on Meta::CPAN

use Test::More tests => 17;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception need" if $@; 
};

my $test = Geometry::Formula->new;

my $area = $test->trapezoid(
    formula => 'area',
    a       => 5,
    b       => 10,
    height  => 15
);
like( $area, qr/112.5/, 'calculation test' );

my $perimeter = $test->trapezoid(
    formula => 'perimeter',
    a       => 5,
    b       => 10,
    c       => 15,
    d       => 20
);
like( $perimeter, qr/50/, 'calculation test' );

throws_ok { $test->trapezoid( formula => 'foo', a => 5, b => 10, height => 15 ); }
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->trapezoid( formula => 'area', a => 5, b => 10 ) }
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok { $test->trapezoid( formula => 'area', a => 5, height => 15 ) }
qr/required parameter 'b' not defined/,
  'required parameter exception for b';

throws_ok { $test->trapezoid( formula => 'area', b => 10, height => 15 ) }
qr/required parameter 'a' not defined/,
  'required parameter exception for a';

throws_ok { $test->trapezoid( formula => 'perimeter', b => 10, c => 15, d => 20 ) }
qr/required parameter 'a' not defined/,
  'required parameter exception for a';

throws_ok { $test->trapezoid( formula => 'perimeter', a => 5 , c => 15, d => 20) }
qr/required parameter 'b' not defined/,
  'required parameter exception for b';

throws_ok { $test->trapezoid( formula => 'perimeter', a => 5, b => 10, d => 20 ) }
qr/required parameter 'c' not defined/,
  'required parameter exception for c';

throws_ok { $test->trapezoid( formula => 'perimeter', a => 5, b => 10, c => 15 ) }
qr/required parameter 'd' not defined/,
  'required parameter exception for d';

throws_ok { $test->trapezoid( formula => 'area', a => '5a', b => 10, height => 15 ); }
qr/parameter 'a' requires a numeric value/,
  'formula parameter a is numeric';

throws_ok { $test->trapezoid( formula => 'area', a => '5', b => '10a', height => 15 ); }
qr/parameter 'b' requires a numeric value/,
  'formula parameter b is numeric';

throws_ok { $test->trapezoid( formula => 'area', a => '5', b => '10', height => '15a' ); }
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

throws_ok { $test->trapezoid( formula => 'perimeter', a => '5a', b => 10, c => 15, d => 20 ); }
qr/parameter 'a' requires a numeric value/,
  'formula parameter a is numeric';

throws_ok { $test->trapezoid( formula => 'perimeter', a => '5', b => '10a', c => 15, d => 20 ); }
qr/parameter 'b' requires a numeric value/,
  'formula parameter b is numeric';

throws_ok { $test->trapezoid( formula => 'perimeter', a => '5', b => 10, c => '15a', d => 20 ); }
qr/parameter 'c' requires a numeric value/,
  'formula parameter c is numeric';

throws_ok { $test->trapezoid( formula => 'perimeter', a => '5', b => '10', c => 15, d => '20a' ); }
qr/parameter 'd' requires a numeric value/,
  'formula parameter d is numeric';

t/triangle.t  view on Meta::CPAN

use Test::More tests => 13;

BEGIN {
    eval "use Test::Exception";
    plan skip_all => "Test::Exception need" if $@;
};

my $test = Geometry::Formula->new;

my $area = $test->triangle(
    formula => 'area',
    base    => 5,
    height  => 10,
);
like( $area, qr/25/, 'calculation test' );

my $perimeter = $test->triangle(
    formula => 'perimeter',
    a       => 5,
    b       => 10,
    c       => 15,
);
like( $perimeter, qr/30/, 'calculation test' );

throws_ok {
    $test->triangle( formula => 'foo', a => 5, b => 10, height => 15 );
}
qr/invalid formula name: foo specified/, 'valid formula name test';

throws_ok { $test->triangle( formula => 'area', base => 5 ) }
qr/required parameter 'height' not defined/,
  'required parameter exception for height';

throws_ok { $test->triangle( formula => 'area', height => 10 ) }
qr/required parameter 'base' not defined/,
  'required parameter exception for base';

throws_ok {
    $test->triangle( formula => 'perimeter', b => 10, c => 15 );
}
qr/required parameter 'a' not defined/, 'required parameter exception for a';

throws_ok {
    $test->triangle( formula => 'perimeter', a => 5, c => 15 );
}
qr/required parameter 'b' not defined/, 'required parameter exception for b';

throws_ok {
    $test->triangle( formula => 'perimeter', a => 5, b => 10 );
}
qr/required parameter 'c' not defined/, 'required parameter exception for c';

throws_ok { $test->triangle( formula => 'area', base => '5a', height => 10 ); }
qr/parameter 'base' requires a numeric value/,
  'formula parameter base is numeric';

throws_ok {
    $test->triangle( formula => 'area', base => '5', height => '10a' );
}
qr/parameter 'height' requires a numeric value/,
  'formula parameter height is numeric';

throws_ok {
    $test->triangle(
        formula => 'perimeter',
        a       => '5a',
        b       => 10,
        c       => 15,
    );
}
qr/parameter 'a' requires a numeric value/, 'formula parameter a is numeric';

throws_ok {
    $test->triangle(
        formula => 'perimeter',
        a       => '5',
        b       => '10a',
        c       => 15,
    );
}
qr/parameter 'b' requires a numeric value/, 'formula parameter b is numeric';

throws_ok {
    $test->triangle(
        formula => 'perimeter',
        a       => '5',
        b       => 10,
        c       => '15a',
    );
}
qr/parameter 'c' requires a numeric value/, 'formula parameter c is numeric';



( run in 0.595 second using v1.01-cache-2.11-cpan-26ccb49234f )