Sha256: 82263bb5028f9e6fef789314c15ea61cf174e832669c6487cbb8f3e47adba57b

Contents?: true

Size: 1.41 KB

Versions: 73

Compression:

Stored size: 1.41 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 = (
    {
        hex     => '1',
        decimal => 1,
    },
    {
        hex     => 'c',
        decimal => 12,
    },
    {
        hex     => '10',
        decimal => 16,
    },
    {
        hex     => 'af',
        decimal => 175,
    },
    {
        hex     => '100',
        decimal => 256,
    },
    {
        hex     => '19ace',
        decimal => 105166,
    },
    {
        hex     => 'carrot',
        decimal => 0,
    },
    {
        hex     => '000000',
        decimal => 0,
    },
    {
        hex     => 'ffffff',
        decimal => 16777215,
    },
    {
        hex     => 'ffff00',
        decimal => 16776960,
    },
);

my $module = 'Hexadecimal';

plan tests => 4 + @cases;

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, "to_decimal" or BAIL_OUT "Missing package $module; or missing sub to_decimal()";

foreach my $c (@cases) {
    my $hex = $module->new($c->{hex});
    is $hex->to_decimal, $c->{decimal}, "convert $c->{hex} to $c->{decimal}";
}

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.179 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.178 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.177 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.176 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.175 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.174 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.173 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.172 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.171 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.170 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.169 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.167 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.166 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.165 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.164 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.163 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.162 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.161 tracks/perl5/exercises/hexadecimal/hexadecimal.t
trackler-2.2.1.160 tracks/perl5/exercises/hexadecimal/hexadecimal.t