-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuNucleotideCountTests.pas
188 lines (164 loc) · 4.04 KB
/
uNucleotideCountTests.pas
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
unit uNucleotideCountTests;
interface
uses
DUnitX.TestFramework, System.Generics.Collections;
const
CanonicalVersion = '1.3.0.2';
type
[TestFixture('count all nucleotides in a strand')]
NucleoTideCountTest = class(TObject)
public
[Test]
procedure Validate_CompareDictionaries;
[Test]
// [Ignore('Comment the "[Ignore]" statement to run the test')]
procedure empty_strand;
[Test]
// [Ignore]
procedure can_count_one_nucleotide_in_single_character_input;
[Test]
// [Ignore]
procedure strand_with_repeated_nucleotide;
[Test]
// [Ignore]
procedure strand_with_multiple_nucleotides;
[Test]
// [Ignore]
procedure strand_with_invalid_nucleotides;
end;
implementation
uses
SysUtils,
uNucleotideCount;
procedure CompareDictionaries(Expected, Actual: TDictionary<Char, Integer>);
var
expectedItem: TPair<char, integer>;
begin
Assert.AreEqual(Expected.Count, Actual.Count); //Actual should have 4 nucleotides as expected
for expectedItem in Expected do
begin //Every Actual item should match an expected item.
Assert.IsTrue(Actual.ContainsKey(expectedItem.Key));
Assert.AreEqual(expectedItem.Value, Actual[expectedItem.Key]);
end;
end;
procedure NucleoTideCountTest.Validate_CompareDictionaries;
var
expected, actual: TDictionary<char, integer>;
begin
expected := TDictionary<char, integer>.Create;
try
expected.Add('r',5);
expected.Add('a',10);
expected.Add('n',15);
expected.Add('d',20);
expected.Add('o',25);
expected.Add('m',30);
actual := TDictionary<char, integer>.create(expected);
try
CompareDictionaries(expected, actual);
finally
actual.Free;
end;
finally
expected.Free;
end;
end;
procedure NucleoTideCountTest.empty_strand;
var
dna: TDNA;
expected: TDictionary<char, integer>;
begin
expected := TDictionary<char, integer>.Create;
dna := TDNA.Create('');
try
expected.Add('A',0);
expected.Add('T',0);
expected.Add('C',0);
expected.Add('G',0);
CompareDictionaries(expected, dna.NucleotideCounts);
finally
dna.Free;
expected.Free;
end;
end;
procedure NucleoTideCountTest.strand_with_repeated_nucleotide;
var
dna: TDNA;
expected: TDictionary<char, integer>;
inStr: string;
begin
expected := TDictionary<char, integer>.Create();
inStr := 'GGGGGGG';
dna := TDNA.Create(inStr);
try
expected.Add('A',0);
expected.Add('T',0);
expected.Add('C',0);
expected.Add('G',7);
CompareDictionaries(expected, dna.NucleotideCounts);
finally
dna.Free;
expected.Free;
end;
end;
procedure NucleoTideCountTest.strand_with_invalid_nucleotides;
var
MyProc: TTestLocalMethod;
dna: TDNA;
begin
MyProc := procedure
var
inStr: string;
begin
inStr := 'AGXXACT';
dna := TDNA.Create(inStr);
end;
try
Assert.WillRaiseWithMessage(MyProc,EInvalidNucleotideException,'Invalid nucleotide in strand');
finally
dna.Free;
end;
end;
procedure NucleoTideCountTest.can_count_one_nucleotide_in_single_character_input;
var
dna: TDNA;
expected: TDictionary<char, integer>;
inStr: string;
begin
expected := TDictionary<char, integer>.Create;
inStr := 'G';
dna := TDNA.Create(inStr);
try
expected.Add('A',0);
expected.Add('T',0);
expected.Add('C',0);
expected.Add('G',1);
CompareDictionaries(expected, dna.NucleotideCounts);
finally
dna.Free;
expected.Free;
end;
end;
procedure NucleoTideCountTest.strand_with_multiple_nucleotides;
var
dna: TDNA;
expected: TDictionary<char, integer>;
inStr: string;
begin
expected := TDictionary<char, integer>.Create;
inStr := 'AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC';
dna := TDNA.Create(inStr);
try
expected.Add('A',20);
expected.Add('T',21);
expected.Add('C',12);
expected.Add('G',17);
CompareDictionaries(expected, dna.NucleotideCounts);
finally
dna.Free;
expected.Free;
end;
end;
initialization
TDUnitX.RegisterTestFixture(NucleoTideCountTest);
end.