1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#!/usr/bin/env raku
use Test;
use JSON::Fast;
use lib $?FILE.IO.dirname;
use Hamming;
plan 9;
my @test-cases = from-json($=pod.pop.contents).List;
for @test-cases -> %case {
given %case<expected> {
when .<error>.so {
throws-like
{ hamming-distance |%case<input><strand1 strand2> },
Exception,
message => /
'left and right strands must be of equal length'
|| 'Constraint type check failed in binding to parameter'
/,
%case<description>;
}
default {
is hamming-distance(|%case<input><strand1 strand2>),
|%case<expected description>;
}
}
}
=head2 Test Cases
=begin code
[
{
"description": "empty strands",
"expected": 0,
"input": {
"strand1": "",
"strand2": ""
},
"property": "distance"
},
{
"description": "single letter identical strands",
"expected": 0,
"input": {
"strand1": "A",
"strand2": "A"
},
"property": "distance"
},
{
"description": "single letter different strands",
"expected": 1,
"input": {
"strand1": "G",
"strand2": "T"
},
"property": "distance"
},
{
"description": "long identical strands",
"expected": 0,
"input": {
"strand1": "GGACTGAAATCTG",
"strand2": "GGACTGAAATCTG"
},
"property": "distance"
},
{
"description": "long different strands",
"expected": 9,
"input": {
"strand1": "GGACGGATTCTG",
"strand2": "AGGACGGATTCT"
},
"property": "distance"
},
{
"description": "disallow first strand longer",
"expected": {
"error": "left and right strands must be of equal length"
},
"input": {
"strand1": "AATG",
"strand2": "AAA"
},
"property": "distance"
},
{
"description": "disallow second strand longer",
"expected": {
"error": "left and right strands must be of equal length"
},
"input": {
"strand1": "ATA",
"strand2": "AGTG"
},
"property": "distance"
},
{
"description": "disallow left empty strand",
"expected": {
"error": "left strand must not be empty"
},
"input": {
"strand1": "",
"strand2": "G"
},
"property": "distance"
},
{
"description": "disallow right empty strand",
"expected": {
"error": "right strand must not be empty"
},
"input": {
"strand1": "G",
"strand2": ""
},
"property": "distance"
}
]
=end code
|