-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhamming_spec.lua
63 lines (48 loc) · 1.64 KB
/
hamming_spec.lua
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
local compute = require('hamming').compute
describe('hamming', function ()
it('identical strands', function ()
assert.are.equal(0, compute('A', 'A'))
end)
it('long identical strands', function ()
assert.are.equal(0, compute('GGACTGA', 'GGACTGA'))
end)
it('complete distance in single nucleotide strands', function ()
assert.are.equal(1, compute('A', 'G'))
end)
it('complete distance in small strands', function ()
assert.are.equal(2, compute('AG', 'CT'))
end)
it('small distance in small strands', function ()
assert.are.equal(1, compute('AT', 'CT'))
end)
it('small distance', function ()
assert.are.equal(1, compute('GGACG', 'GGTCG'))
end)
it('small distance in long strands', function ()
assert.are.equal(2, compute('ACCAGGG', 'ACTATGG'))
end)
it('non unique character in first strand', function ()
assert.are.equal(1, compute('AGA', 'AGG'))
end)
it('non unique character in second strand', function ()
assert.are.equal(1, compute('AGG', 'AGA'))
end)
it('same nucleotides in different positions', function ()
assert.are.equal(2, compute('TAG', 'GAT'))
end)
it('large distance', function ()
assert.are.equal(4, compute('GATACA', 'GCATAA'))
end)
it('large distance in off-by-one strand', function ()
assert.are.equal(9, compute('GGACGGATTCTG', 'AGGACGGATTCT'))
end)
it('empty strands', function ()
assert.are.equal(0, compute('', ''))
end)
it('disallow first strand longer', function ()
assert.are.equal(-1, compute('AATG', 'AAA'))
end)
it('disallow second strand longer', function ()
assert.are.equal(-1, compute('ATA', 'AGTG'))
end)
end)