Sha256: fb29b329072a2a2daf30a68974ec924ff7119eb86d60b1a72255d39ec5c57d6f

Contents?: true

Size: 1.85 KB

Versions: 303

Compression:

Stored size: 1.85 KB

Contents

#!/usr/bin/env perl
use strict;
use warnings;

use Test::More tests => 14;
use FindBin;
my $dir;
BEGIN { $dir = $FindBin::Bin . '/' };
use lib $dir;

my $module = $ENV{EXERCISM} ? 'Example' : 'Triplet';
ok -e "${dir}${module}.pm", "Missing $module.pm" or BAIL_OUT "You need to create file: $module.pm";

eval "use $module";
ok !$@, "Cannot load $module" or BAIL_OUT "Cannot load $module. Does it compile? Does it end with 1;?";

can_ok $module, "new",            or BAIL_OUT "Missing package $module; or missing sub new()";
can_ok $module, "is_pythagorean", or BAIL_OUT "Missing package $module; or missing sub is_pythagorean()";
can_ok $module, "sum",            or BAIL_OUT "Missing package $module; or missing sub sum()";
can_ok $module, "product",        or BAIL_OUT "Missing package $module; or missing sub product()";
can_ok $module, "products",       or BAIL_OUT "Missing package $module; or missing sub products()";

my $triplet;

$triplet = $module->new(3, 4, 5);
is $triplet->sum, 12, "test sum";
ok $triplet->is_pythagorean, "test if pythagorean";
is $triplet->product, 60, "test product";

$triplet = $module->new(5, 6, 7);
ok !$triplet->is_pythagorean, "test not a pythagorean";

$triplet = $module->new({max_factor => 10});
is_deeply( [sort @{$triplet->products}], [sort (60, 480)],
    "products of pythagorean_triplets where each number is <= 10" ) or diag explain $triplet->products;

$triplet = $module->new({min_factor => 11, max_factor => 20});
is_deeply( $triplet->products, [3840],
    "products of triplets where factor in 11-20" ) or diag explain $triplet->products;

$triplet = $module->new({sum => 180, max_factor => 100});
#$triplet = $module->new({sum => 180, min_factor => 20, max_factor => 80});
is_deeply( [sort @{$triplet->products}], [118080, 168480, 202500],
    "products of triplets where sum=180 and max_factor is 100" ) or diag explain $triplet->products;

Version data entries

303 entries across 303 versions & 1 rubygems

Version Path
trackler-2.2.1.85 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.84 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.83 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.82 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.81 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.80 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.79 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.78 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.77 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.76 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.75 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.74 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.73 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.72 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.71 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.70 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.69 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.68 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.67 tracks/perl5/exercises/pythagorean-triplet/triplet.t
trackler-2.2.1.66 tracks/perl5/exercises/pythagorean-triplet/triplet.t