Sha256: fc0c4c250a729a02d3cb6571570df005c2d8428b26ec3c5c1af6a2852e192c7f

Contents?: true

Size: 1.24 KB

Versions: 303

Compression:

Stored size: 1.24 KB

Contents

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

use Test::More;
use JSON qw(from_json);
use FindBin;
my $dir;
BEGIN { $dir = $FindBin::Bin . '/' };
use lib $dir;

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

my $cases_file = "${dir}cases.json";
my $cases;
if (open my $fh, '<', $cases_file) {
    local $/ = undef;
    $cases = from_json scalar <$fh>;
} else {
    die "Could not open '$cases_file' $!";
}

#plan tests => 3 + @$cases;
#diag explain $cases;

ok -e "${dir}${module}.pm", "missing $module.pm"
    or BAIL_OUT("You need to create a class called $module.pm with a constructor called new.");

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

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

foreach my $c (@$cases) {
   diag "Start $c->{name}";
   my $q = $module->new;
   foreach my $s (@{ $c->{set} }) {
      foreach my $command (qw(push unshift)) {
         if (exists $s->{$command}) {
            $q->$command($s->{$command})
         }
      }
      foreach my $assert (qw(pop shift)) {
         if (exists $s->{$assert}) {
             is $q->$assert, $s->{$assert}, "$c->{name} $assert";
         }
      }
   }
}


done_testing();

Version data entries

303 entries across 303 versions & 1 rubygems

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