summary refs log tree commit diff stats
path: root/raku/nucleotide-count/nucleotide-count.rakutest
blob: 51e405a5913260df6849f825176e8fa88d963982 (plain) (blame)
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
#!/usr/bin/env raku
use Test;
use JSON::Fast;
use lib $?FILE.IO.dirname;
use NucleotideCount;
plan 5;

my @test-cases = from-json($=pod.pop.contents).List;
for @test-cases -> %case {
  given %case<expected> {
    when .<error>.so {
      throws-like
        { nucleotide-count %case<input><strand> },
        Exception,
        message => /
          $( %case<expected><error> )
          || 'Constraint type check failed in binding to parameter'
        /,
        %case<description>;
    }

    default {
      cmp-ok nucleotide-count(%case<input><strand>),
        '~~', %case<expected>.Bag, %case<description>;
    }
  }
}

=head2 Test Cases
=begin code
[
  {
    "description": "count all nucleotides in a strand: empty strand",
    "expected": {
      "A": 0,
      "C": 0,
      "G": 0,
      "T": 0
    },
    "input": {
      "strand": ""
    },
    "property": "nucleotideCounts"
  },
  {
    "description": "count all nucleotides in a strand: can count one nucleotide in single-character input",
    "expected": {
      "A": 0,
      "C": 0,
      "G": 1,
      "T": 0
    },
    "input": {
      "strand": "G"
    },
    "property": "nucleotideCounts"
  },
  {
    "description": "count all nucleotides in a strand: strand with repeated nucleotide",
    "expected": {
      "A": 0,
      "C": 0,
      "G": 7,
      "T": 0
    },
    "input": {
      "strand": "GGGGGGG"
    },
    "property": "nucleotideCounts"
  },
  {
    "description": "count all nucleotides in a strand: strand with multiple nucleotides",
    "expected": {
      "A": 20,
      "C": 12,
      "G": 17,
      "T": 21
    },
    "input": {
      "strand": "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"
    },
    "property": "nucleotideCounts"
  },
  {
    "description": "count all nucleotides in a strand: strand with invalid nucleotides",
    "expected": {
      "error": "Invalid nucleotide in strand"
    },
    "input": {
      "strand": "AGXXACT"
    },
    "property": "nucleotideCounts"
  }
]
=end code