1
exercism fetch lua nucleotide-count

nucleotide-count_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
local DNA = require('nucleotide-count')

describe('nucleotide-count', function()
  it('has no nucleotides', function()
    local expected =  { A = 0, T = 0, C = 0, G = 0 }
    dna = DNA:new('')
    local result = dna.nucleotideCounts
    assert.are.same(expected, result)
  end)

  it('has no adenosine', function()
    local dna = DNA:new('')
    local expected = 0
    result = dna:count('A')
    assert.are.same(expected, result)
 end)

  it('repetitive cytosine gets counts', function()
    local dna = DNA:new('CCCCC')
    local expected = 5
    result = dna:count('C')
    assert.are.same(expected, result)
  end)

  it('repetitive sequence has only guanosine', function()
    local dna = DNA:new('GGGGGGGG')
    expected = { A = 0, T = 0, C = 0, G = 8 }
    result = dna.nucleotideCounts
    assert.are.same(expected, result)
  end)

  it('counts only thymine', function()
    local dna = DNA:new('GGGGTAACCCGG')
    expected = 1
    result = dna:count('T')
    assert.are.same(expected, result)
  end)

  it('counts a nucleotide only once', function()
    local dna = DNA:new('GGTTGG')
    expected = 2
    result = dna:count('T')
    assert.are.same(expected, result)
  end)

  it('validates nucleotides', function()
    local dna = DNA:new('GGTTGG')
     assert.has.errors(function() dna:count('X') end)
     assert.has_error(function() dna:count('X') end, 'Invalid Nucleotide')
  end)

  it('counts all nucleotides', function()
    local dna = DNA:new('AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC')
    expected = { A = 20, T = 21, G = 17, C = 12 }
    result = dna.nucleotideCounts
    assert.are.same(expected, result)
  end)
end)