1 | /* |
---|
2 | Copyright (c) 2012-2013 Arne Boeckman |
---|
3 | Copyright (c) 2012-2013 Elmar Pruesse |
---|
4 | |
---|
5 | This file is part of SINA. |
---|
6 | |
---|
7 | SINA is free software: you can redistribute it and/or modify |
---|
8 | it under the terms of the GNU General Public License as published by |
---|
9 | the Free Software Foundation, either version 3 of the License, or |
---|
10 | (at your option) any later version. |
---|
11 | |
---|
12 | This program is distributed in the hope that it will be useful, |
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | GNU General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU General Public License |
---|
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | */ |
---|
20 | |
---|
21 | |
---|
22 | #ifndef _aligned_base_TEST_HPP_ |
---|
23 | #define _aligned_base_TEST_HPP_ |
---|
24 | |
---|
25 | #define BOOST_TEST_MODULE aligned_base_module |
---|
26 | #include <boost/test/unit_test.hpp> |
---|
27 | |
---|
28 | #include "../aligned_base.h" |
---|
29 | using namespace sina; |
---|
30 | #define EQUAL BOOST_CHECK_EQUAL |
---|
31 | #define TRUE(x) BOOST_CHECK_EQUAL(x,true) |
---|
32 | #define FALSE(x) BOOST_CHECK_EQUAL(x,false) |
---|
33 | #define CASE BOOST_AUTO_TEST_CASE |
---|
34 | #define FCASE BOOST_FIXTURE_TEST_CASE |
---|
35 | |
---|
36 | BOOST_AUTO_TEST_SUITE(aligned_base_test); |
---|
37 | |
---|
38 | unsigned char A('A'); |
---|
39 | unsigned char G('G'); |
---|
40 | unsigned char C('C'); |
---|
41 | unsigned char U('U'); |
---|
42 | unsigned char T('T'); |
---|
43 | CASE(ctor_test){ |
---|
44 | |
---|
45 | base_iupac baseA(A); |
---|
46 | base_iupac baseT(U); |
---|
47 | |
---|
48 | TRUE(baseA.has_A()); |
---|
49 | FALSE(baseA.has_C()); |
---|
50 | FALSE(baseA.has_G()); |
---|
51 | FALSE(baseA.has_TU()); |
---|
52 | |
---|
53 | FALSE(baseT.has_A()); |
---|
54 | FALSE(baseT.has_C()); |
---|
55 | FALSE(baseT.has_G()); |
---|
56 | TRUE(baseT.has_TU()); |
---|
57 | |
---|
58 | EQUAL((char)baseA,A); |
---|
59 | EQUAL((char)baseT,U); |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | } |
---|
64 | |
---|
65 | CASE(ctor_illegal_param_test){ |
---|
66 | //what happens if we use an illegal char |
---|
67 | |
---|
68 | unsigned char illegal('!'); |
---|
69 | BOOST_CHECK_THROW(base_iupac baseIllegal(illegal),sina::aligned_base::bad_character_exception); |
---|
70 | |
---|
71 | |
---|
72 | } |
---|
73 | |
---|
74 | CASE(ctor_empty_param_test){ |
---|
75 | base_iupac b; |
---|
76 | FALSE(b.has_A()); |
---|
77 | FALSE(b.has_C()); |
---|
78 | FALSE(b.has_G()); |
---|
79 | FALSE(b.has_TU()); |
---|
80 | } |
---|
81 | |
---|
82 | CASE(complement_test){ |
---|
83 | base_iupac baseA(A); |
---|
84 | |
---|
85 | baseA.complement(); |
---|
86 | EQUAL((char)baseA,U); |
---|
87 | |
---|
88 | base_iupac baseC(C); |
---|
89 | |
---|
90 | baseC.complement(); |
---|
91 | EQUAL((char)baseC,G); |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | CASE(setLower_test){ |
---|
96 | base_iupac baseA(A); |
---|
97 | base_iupac baseC(C); |
---|
98 | |
---|
99 | baseA.setLowerCase(); |
---|
100 | baseC.setLowerCase(); |
---|
101 | |
---|
102 | EQUAL((char)baseA,'a'); |
---|
103 | EQUAL((char)baseC,'c'); |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | CASE(setUpper_test){ |
---|
108 | base_iupac baset('t'); |
---|
109 | base_iupac baseg('g'); |
---|
110 | |
---|
111 | baset.setUpperCase(); |
---|
112 | baseg.setUpperCase(); |
---|
113 | |
---|
114 | EQUAL((char)baset,'U'); |
---|
115 | EQUAL((char)baseg,'G'); |
---|
116 | } |
---|
117 | |
---|
118 | CASE(isLower_test){ |
---|
119 | base_iupac baset('t'); |
---|
120 | base_iupac baseG('G'); |
---|
121 | |
---|
122 | TRUE(baset.isLowerCase()); |
---|
123 | FALSE(baseG.isLowerCase()); |
---|
124 | } |
---|
125 | |
---|
126 | CASE(comp_test){ |
---|
127 | base_iupac baseT('T'); |
---|
128 | base_iupac baseU('U'); |
---|
129 | base_iupac baseu('u'); |
---|
130 | base_iupac baset('t'); |
---|
131 | base_iupac baseG('G'); |
---|
132 | base_iupac baseC('C'); |
---|
133 | |
---|
134 | TRUE(baseT.comp(baseU)); |
---|
135 | TRUE(baseT.comp(baseu)); |
---|
136 | TRUE(baseu.comp(baseT)); |
---|
137 | TRUE(baseT.comp(baseT)); |
---|
138 | TRUE(baset.comp(baseT)); |
---|
139 | TRUE(baseG.comp(baseG)); |
---|
140 | TRUE(baseC.comp(baseC)); |
---|
141 | FALSE(baseT.comp(baseC)); |
---|
142 | FALSE(baseG.comp(baseC)); |
---|
143 | FALSE(baset.comp(baseC)); |
---|
144 | |
---|
145 | } |
---|
146 | |
---|
147 | CASE(comp_pessimistic_test){ |
---|
148 | base_iupac base('R'); |
---|
149 | base_iupac base2('T'); |
---|
150 | |
---|
151 | //R should not be equal to R because R is ambiguous |
---|
152 | FALSE(base.comp_pessimistic(base)); |
---|
153 | base = 'A'; |
---|
154 | TRUE(base.comp_pessimistic(base)); |
---|
155 | base = 'G'; |
---|
156 | TRUE(base.comp_pessimistic(base)); |
---|
157 | FALSE(base.comp_pessimistic(base2)); |
---|
158 | |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | CASE(pair_test){ |
---|
163 | base_iupac baseT(T); |
---|
164 | base_iupac baseA(A); |
---|
165 | EQUAL(baseT.pair(baseA),1.0f); |
---|
166 | |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | |
---|
171 | CASE(is_ambig_test){ |
---|
172 | base_iupac baseT('T'); |
---|
173 | FALSE(baseT.is_ambig()); |
---|
174 | |
---|
175 | base_iupac baseM('m'); |
---|
176 | TRUE(baseM.is_ambig()); |
---|
177 | |
---|
178 | base_iupac baseV('V'); |
---|
179 | TRUE(baseV.is_ambig()); |
---|
180 | |
---|
181 | base_iupac baseG('G'); |
---|
182 | FALSE(baseG.is_ambig()); |
---|
183 | } |
---|
184 | |
---|
185 | CASE(ambig_order_test){ |
---|
186 | base_iupac baseT('T'); |
---|
187 | EQUAL(baseT.ambig_order(),1); |
---|
188 | |
---|
189 | base_iupac baseM('M'); |
---|
190 | EQUAL(baseM.ambig_order(),2); |
---|
191 | |
---|
192 | base_iupac baseD('D'); |
---|
193 | EQUAL(baseD.ambig_order(),3); |
---|
194 | } |
---|
195 | |
---|
196 | CASE(cast_to_char_test){ |
---|
197 | |
---|
198 | |
---|
199 | //iterate over small letter alphabet |
---|
200 | for(char i = 97; i <=122; i++ ) |
---|
201 | { |
---|
202 | try |
---|
203 | { |
---|
204 | //skip t, it is identical to u :) |
---|
205 | if('t' == i) |
---|
206 | { |
---|
207 | i++; |
---|
208 | } |
---|
209 | base_iupac base(i);//it may either throw an exception |
---|
210 | EQUAL((char)base, i);//or it should convert correctly |
---|
211 | } |
---|
212 | catch(sina::aligned_base::bad_character_exception) |
---|
213 | { |
---|
214 | EQUAL(true,true); |
---|
215 | } |
---|
216 | |
---|
217 | } |
---|
218 | |
---|
219 | |
---|
220 | } |
---|
221 | |
---|
222 | |
---|
223 | BOOST_AUTO_TEST_SUITE_END(); // XXX_test |
---|
224 | |
---|
225 | #endif /* _XXX_TEST_HPP_ */ |
---|
226 | |
---|
227 | /* |
---|
228 | Local Variables: |
---|
229 | mode:c++ |
---|
230 | c-file-style:"stroustrup" |
---|
231 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
---|
232 | indent-tabs-mode:nil |
---|
233 | fill-column:99 |
---|
234 | End: |
---|
235 | */ |
---|
236 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
---|