Sha256: 6271c08395244f95d180a006b55eaaa3c7ef246567106456ba54559f6f8d578c

Contents?: true

Size: 1.62 KB

Versions: 303

Compression:

Stored size: 1.62 KB

Contents

#!/usr/bin/env perl
use strict;
use warnings;
use open ':std', ':encoding(utf8)';
use utf8;

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

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

my @cases = (
    # input                                       expected output                  title
    ['word',                                      {word =>  1},                    'one word'],
    ['one of each',                               {one => 1, of => 1, each => 1},  'one of each'],
    ['one fish two fish red fish blue fish',
            {one => 1, fish => 4, two => 1, red => 1, blue => 1},
                 'multiple occurences'],
    ['car : carpet as java : javascript!!&@$%^&',
            {car => 1, carpet => 1, as => 1, java => 1, javascript => 1},
                'ignore punctuation'],
    ['testing, 1, 2 testing',                     {testing => 2, 1 => 1, 2 => 1}, 'include numbers'],
    ['go Go GO',                                  {go => 3},                       'normalize case'],
);


plan tests => 3 + @cases;

ok -e "${dir}${module}.pm", "missing $module.pm"
    or BAIL_OUT("You need to create a module called $module.pm with a function called word_count() that gets one parameter: the text in which to count the words.");

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

can_ok($module, 'word_count') or BAIL_OUT("Missing package Phrase; or missing sub word_count()");

my $sub = $module . '::word_count';

foreach my $c (@cases) {
    no strict 'refs';
    is_deeply $sub->($c->[0]), $c->[1], $c->[2];
}


Version data entries

303 entries across 303 versions & 1 rubygems

Version Path
trackler-2.2.1.105 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.104 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.103 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.102 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.101 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.100 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.99 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.98 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.97 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.96 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.95 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.94 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.93 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.92 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.91 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.90 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.89 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.88 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.87 tracks/perl5/exercises/word-count/word_count.t
trackler-2.2.1.86 tracks/perl5/exercises/word-count/word_count.t