Acme-Math-PerfectChristmasTree

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


SYNOPSIS
        use Acme::Math::PerfectChristmasTree qw/calc_perfect_christmas_tree/;

        my $tree_height  = 140; #<= centimeter
        my %perfect_tree = calc_perfect_christmas_tree($tree_height);

        # Content of %perfect_tree
        #
        # 'star_or_fairy_height' => 14,
        # 'tinsel_length'        => 714.712328691678,
        # 'number_of_baubles'    => 29,
        # 'lights_length'        => 439.822971502571

DESCRIPTION
    This module calculates perfect Christmas tree. Sorry, "perfect Christmas
    tree" is not a data tree. So it has nothing to do with data structure.

    This module is using an equation which was devised by mathematics club
    of The University Of Sheffield. For more details, refer to the following
    web site.

    <http://www.shef.ac.uk/news/nr/debenhams-christmas-tree-formula-1.227810

README  view on Meta::CPAN

METHODS
    calc_perfect_christmas_tree
        Calculates perfect Christmas tree.

        This function needs an argument which specify height of tree (please
        input as centimeter).

        This function returns a hash. Keys of hash are...

            'star_or_fairy_height'
            'tinsel_length'
            'number_of_baubles'
            'lights_length'

        (Values of hash related to length or height are expressed as
        centimeter).

CONFIGURATION AND ENVIRONMENT
    Acme::Math::PerfectChristmasTree requires no configuration files or
    environment variables.

DEPENDENCIES
    Test::Exception (Version 0.31 or later)

INCOMPATIBILITIES

README.pod  view on Meta::CPAN

=head1 SYNOPSIS

    use Acme::Math::PerfectChristmasTree qw/calc_perfect_christmas_tree/;

    my $tree_height  = 140; #<= centimeter
    my %perfect_tree = calc_perfect_christmas_tree($tree_height);

    # Content of %perfect_tree
    #
    # 'star_or_fairy_height' => 14,
    # 'tinsel_length'        => 714.712328691678,
    # 'number_of_baubles'    => 29,
    # 'lights_length'        => 439.822971502571

=head1 DESCRIPTION

This module calculates perfect Christmas tree. Sorry, "perfect Christmas tree" is not a data tree.
So it has nothing to do with data structure.

This module is using an equation which was devised by mathematics club of The University Of Sheffield.
For more details, refer to the following web site.

L<http://www.shef.ac.uk/news/nr/debenhams-christmas-tree-formula-1.227810>

README.pod  view on Meta::CPAN


=item calc_perfect_christmas_tree

Calculates perfect Christmas tree.

This function needs an argument which specify height of tree (please input as centimeter).

This function returns a hash. Keys of hash are...

    'star_or_fairy_height'
    'tinsel_length'
    'number_of_baubles'
    'lights_length'

(Values of hash related to length or height are expressed as centimeter).

=back

=head1 CONFIGURATION AND ENVIRONMENT

Acme::Math::PerfectChristmasTree requires no configuration files or environment variables.

=head1 DEPENDENCIES

Test::Exception (Version 0.31 or later)

lib/Acme/Math/PerfectChristmasTree.pm  view on Meta::CPAN

sub calc_perfect_christmas_tree {
    my $tree_height = shift;

    if ($tree_height <= 0) {
        croak 'Tree height must be a number greater than zero.';
    }

    my $pi = pi();
    return (
        'number_of_baubles' => _round(sqrt(17) / 20 * $tree_height),
        'tinsel_length' => 13 * $pi / 8 * $tree_height,
        'lights_length' => $pi * $tree_height,
        'star_or_fairy_height' => $tree_height / 10,
    );
}

sub _round {
    my $value = shift;

    return int($value + 0.5);
}

lib/Acme/Math/PerfectChristmasTree.pm  view on Meta::CPAN

=head1 SYNOPSIS

    use Acme::Math::PerfectChristmasTree qw/calc_perfect_christmas_tree/;

    my $tree_height  = 140; #<= centimeter
    my %perfect_tree = calc_perfect_christmas_tree($tree_height);

    # Content of %perfect_tree
    #
    # 'star_or_fairy_height' => 14,
    # 'tinsel_length'        => 714.712328691678,
    # 'number_of_baubles'    => 29,
    # 'lights_length'        => 439.822971502571


=head1 DESCRIPTION

This module calculates perfect Christmas tree. Sorry, "perfect Christmas tree" is not a data tree.
So it has nothing to do with data structure.

This module is using an equation which was devised by mathematics club of The University Of Sheffield.
For more details, refer to the following web site.

lib/Acme/Math/PerfectChristmasTree.pm  view on Meta::CPAN


=item calc_perfect_christmas_tree

Calculates perfect Christmas tree.

This function needs an argument which specify height of tree (please input as centimeter).

This function returns a hash. Keys of hash are...

    'star_or_fairy_height'
    'tinsel_length'
    'number_of_baubles'
    'lights_length'

(Values of hash related to length or height are expressed as centimeter).

=back


=head1 CONFIGURATION AND ENVIRONMENT

Acme::Math::PerfectChristmasTree requires no configuration files or environment variables.


=head1 DEPENDENCIES

t/01.calc_perfect_christmas_tree.t  view on Meta::CPAN

    use Test::More tests => 4;
}

my %got;
my %expected;

subtest 'perfect christmas tree that is 140cm' => sub {
    %got = calc_perfect_christmas_tree(140);
    ok( $got{'number_of_baubles'} == 29 );
    ok( $got{'star_or_fairy_height'} == 14 );
    ok( sprintf( '%5.7f', $got{'tinsel_length'} ) == 714.7123287 );
    ok( sprintf( '%5.7f', $got{'lights_length'} ) == 439.8229715 );
};

subtest 'perfect christmas tree that is 234.56cm' => sub {
    %got = calc_perfect_christmas_tree(234.56);
    ok( $got{'number_of_baubles'} == 48 );
    ok( sprintf( '%5.7f', $got{'star_or_fairy_height'} ) == 23.4560000 );
    ok( sprintf( '%5.7f', $got{'tinsel_length'} ) == 1197.4494558 );
    ok( sprintf( '%5.7f', $got{'lights_length'} ) == 736.8919728 );
};

throws_ok { calc_perfect_christmas_tree(0) }
    qr/Tree height must be a number greater than zero./,
    'Give zero to function.';

throws_ok { calc_perfect_christmas_tree(-1) }
    qr/Tree height must be a number greater than zero./,
    'Give nagative number to function';



( run in 0.286 second using v1.01-cache-2.11-cpan-65fba6d93b7 )