Sha256: 8c27ea7f30c61c6675b6a8b6096de1d87ebd25450a827e65cecdd3b1525139d1

Contents?: true

Size: 1.27 KB

Versions: 73

Compression:

Stored size: 1.27 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 $module = 'Hamming';

plan tests => 12;

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

sub dies_like(&$$) {
    my( $code, $expected, $message ) = @_;
    eval { $code->() };
    like $@ => $expected, $message;
}

my $sub = \&{"$module" . "::compute"}; 
is $sub->('A', 'A'), 0, "identical strands";
is $sub->('A', 'G'), 1, "different strands";
is $sub->('AG', 'CT'), 2, "completely different strands";
is $sub->('AT', 'CT'), 1, "one hamming distance";
is $sub->('GGACG', 'GGTCG'), 1, "one hamming distance, longer strands";
is $sub->('GATACA', 'GCATAA'), 4, "4 hamming distance";
is $sub->('GGACGGATTCTG', 'AGGACGGATTCT'), 9, "9 hamming distance";

dies_like { $sub->('AAAG', 'AAA') } 
    qr/DNA strands must be of equal length/, 
    "extra length on 1st strand";

dies_like { $sub->('AAA', 'AAAG') } 
    qr/DNA strands must be of equal length/, 
    "extra length on 2nd strand";

Version data entries

73 entries across 73 versions & 1 rubygems

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