Sha256: 6bcc6007d1f902e91613b9bd5b6215fd482da0e8484bee078897b934e2c20d1a

Contents?: true

Size: 1.33 KB

Versions: 303

Compression:

Stored size: 1.33 KB

Contents

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

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

my @cases = (
    {
        input    => "1",
        expected => 1,
    },
    {
        input    => "10",
        expected => 2,
    },
    {
        input    => "11",
        expected => 3,
    },
    {
        input    => "100",
        expected => 4,
    },
    {
        input    => "1001",
        expected => 9,
    },
    {
        input    => "11010",
        expected => 26,
    },
    {
        input    => "10001101000",
        expected => 1128,
    },
    {
        input    => "carrot23",
        expected => 0,
    },
);

my $module = $ENV{EXERCISM} ? 'Example' : 'Binary';

plan tests => 4 + @cases;

ok -e "${dir}${module}.pm", "Missing $module.pm",
        or BAIL_OUT "You need to create a file called $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, "to_decimal" or BAIL_OUT "Missing package $module; or missing sub to_decimal()";

foreach my $c ( @cases ) {
    my $binary = $module->new($c->{input});
    is $binary->to_decimal, $c->{expected}, "Binary($c->{input}) to_decimal $c->{expected}";
}

Version data entries

303 entries across 303 versions & 1 rubygems

Version Path
trackler-2.2.1.65 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.64 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.63 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.62 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.61 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.60 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.59 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.58 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.57 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.56 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.55 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.54 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.53 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.52 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.51 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.50 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.49 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.48 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.47 tracks/perl5/exercises/binary/binary.t
trackler-2.2.1.46 tracks/perl5/exercises/binary/binary.t