2343 |
17 Oct 10 |
peter |
// $Id$ |
2343 |
17 Oct 10 |
peter |
2 |
|
2343 |
17 Oct 10 |
peter |
3 |
/* |
2787 |
23 Jul 12 |
peter |
Copyright (C) 2010, 2012 Peter Johansson |
2343 |
17 Oct 10 |
peter |
5 |
|
2343 |
17 Oct 10 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
2343 |
17 Oct 10 |
peter |
7 |
|
2343 |
17 Oct 10 |
peter |
The yat library is free software; you can redistribute it and/or |
2343 |
17 Oct 10 |
peter |
modify it under the terms of the GNU General Public License as |
2343 |
17 Oct 10 |
peter |
published by the Free Software Foundation; either version 3 of the |
2343 |
17 Oct 10 |
peter |
License, or (at your option) any later version. |
2343 |
17 Oct 10 |
peter |
12 |
|
2343 |
17 Oct 10 |
peter |
The yat library is distributed in the hope that it will be useful, |
2343 |
17 Oct 10 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2343 |
17 Oct 10 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2343 |
17 Oct 10 |
peter |
General Public License for more details. |
2343 |
17 Oct 10 |
peter |
17 |
|
2343 |
17 Oct 10 |
peter |
You should have received a copy of the GNU General Public License |
2343 |
17 Oct 10 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
2343 |
17 Oct 10 |
peter |
20 |
*/ |
2343 |
17 Oct 10 |
peter |
21 |
|
2881 |
18 Nov 12 |
peter |
22 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
23 |
|
2343 |
17 Oct 10 |
peter |
24 |
#include "Suite.h" |
2343 |
17 Oct 10 |
peter |
25 |
|
2343 |
17 Oct 10 |
peter |
26 |
#include "yat/omic/DNA.h" |
2343 |
17 Oct 10 |
peter |
27 |
using namespace theplu::yat; |
2343 |
17 Oct 10 |
peter |
28 |
using omic::DNA; |
2343 |
17 Oct 10 |
peter |
29 |
|
2343 |
17 Oct 10 |
peter |
30 |
void default_constructor(test::Suite&); |
2343 |
17 Oct 10 |
peter |
31 |
void copy_constructor(test::Suite&); |
2343 |
17 Oct 10 |
peter |
32 |
void char_constructor(test::Suite&); |
2343 |
17 Oct 10 |
peter |
33 |
void complement(test::Suite&); |
2343 |
17 Oct 10 |
peter |
34 |
void get(test::Suite&); |
2343 |
17 Oct 10 |
peter |
35 |
void test_operator(test::Suite&); |
2343 |
17 Oct 10 |
peter |
36 |
void expand(test::Suite&); |
2343 |
17 Oct 10 |
peter |
37 |
|
2343 |
17 Oct 10 |
peter |
38 |
int main(int argc, char* argv[]) |
2343 |
17 Oct 10 |
peter |
39 |
{ |
2343 |
17 Oct 10 |
peter |
40 |
test::Suite suite(argc, argv); |
2343 |
17 Oct 10 |
peter |
41 |
|
2343 |
17 Oct 10 |
peter |
42 |
default_constructor(suite); |
2343 |
17 Oct 10 |
peter |
43 |
copy_constructor(suite); |
2343 |
17 Oct 10 |
peter |
44 |
char_constructor(suite); |
2343 |
17 Oct 10 |
peter |
45 |
complement(suite); |
2343 |
17 Oct 10 |
peter |
46 |
get(suite); |
2343 |
17 Oct 10 |
peter |
47 |
test_operator(suite); |
2343 |
17 Oct 10 |
peter |
48 |
expand(suite); |
2343 |
17 Oct 10 |
peter |
49 |
|
2343 |
17 Oct 10 |
peter |
50 |
return suite.return_value(); |
2343 |
17 Oct 10 |
peter |
51 |
} |
2343 |
17 Oct 10 |
peter |
52 |
|
2343 |
17 Oct 10 |
peter |
53 |
void default_constructor(test::Suite& suite) |
2343 |
17 Oct 10 |
peter |
54 |
{ |
2343 |
17 Oct 10 |
peter |
55 |
DNA a1; |
2343 |
17 Oct 10 |
peter |
56 |
DNA a2(' '); |
2343 |
17 Oct 10 |
peter |
57 |
if (!suite.add(a1==a2)) |
2343 |
17 Oct 10 |
peter |
58 |
suite.out() << "default constructor failed.\n"; |
2343 |
17 Oct 10 |
peter |
59 |
} |
2343 |
17 Oct 10 |
peter |
60 |
|
2343 |
17 Oct 10 |
peter |
61 |
void copy_constructor(test::Suite& suite) |
2343 |
17 Oct 10 |
peter |
62 |
{ |
2343 |
17 Oct 10 |
peter |
63 |
DNA a1; |
2343 |
17 Oct 10 |
peter |
64 |
DNA a2(a1); |
2343 |
17 Oct 10 |
peter |
65 |
if (!suite.add(a1==a2)) |
2343 |
17 Oct 10 |
peter |
66 |
suite.out() << "copy constructor failed.\n"; |
2343 |
17 Oct 10 |
peter |
67 |
|
2343 |
17 Oct 10 |
peter |
68 |
} |
2343 |
17 Oct 10 |
peter |
69 |
|
2343 |
17 Oct 10 |
peter |
70 |
void char_constructor(test::Suite& suite) |
2343 |
17 Oct 10 |
peter |
71 |
{ |
2343 |
17 Oct 10 |
peter |
72 |
std::string str("ACGTMRWSYKBDHVN "); |
2343 |
17 Oct 10 |
peter |
73 |
for (size_t i=0; i<str.size(); ++i) { |
2343 |
17 Oct 10 |
peter |
74 |
DNA a(str[i]); |
2343 |
17 Oct 10 |
peter |
75 |
a = a; |
2343 |
17 Oct 10 |
peter |
76 |
} |
2343 |
17 Oct 10 |
peter |
77 |
|
2343 |
17 Oct 10 |
peter |
78 |
suite.out() << "check invalid constructor argument..."; |
2343 |
17 Oct 10 |
peter |
79 |
try { |
2343 |
17 Oct 10 |
peter |
80 |
DNA a('X'); |
2343 |
17 Oct 10 |
peter |
81 |
suite.out() << "failed\n"; |
2343 |
17 Oct 10 |
peter |
82 |
suite.add(false); |
2343 |
17 Oct 10 |
peter |
83 |
} |
2343 |
17 Oct 10 |
peter |
84 |
catch (std::invalid_argument& e) { |
2343 |
17 Oct 10 |
peter |
85 |
suite.out() << "ok\n"; |
2343 |
17 Oct 10 |
peter |
86 |
suite.out() << "expected exception with what(): " << e.what() << "\n"; |
2343 |
17 Oct 10 |
peter |
87 |
} |
2343 |
17 Oct 10 |
peter |
88 |
} |
2343 |
17 Oct 10 |
peter |
89 |
|
2343 |
17 Oct 10 |
peter |
90 |
void complement(test::Suite& suite) |
2343 |
17 Oct 10 |
peter |
91 |
{ |
2742 |
08 Jun 12 |
peter |
92 |
suite.add(DNA(' ').complement()==DNA(' ')); |
2742 |
08 Jun 12 |
peter |
93 |
|
2343 |
17 Oct 10 |
peter |
94 |
suite.add(DNA('A').complement()==DNA('T')); |
2742 |
08 Jun 12 |
peter |
95 |
suite.add(DNA('C').complement()==DNA('G')); |
2343 |
17 Oct 10 |
peter |
96 |
suite.add(DNA('G').complement()==DNA('C')); |
2742 |
08 Jun 12 |
peter |
97 |
suite.add(DNA('T').complement()==DNA('A')); |
2742 |
08 Jun 12 |
peter |
98 |
|
2742 |
08 Jun 12 |
peter |
99 |
suite.add(DNA('M').complement()==DNA('K')); |
2742 |
08 Jun 12 |
peter |
100 |
suite.add(DNA('K').complement()==DNA('M')); |
2343 |
17 Oct 10 |
peter |
101 |
suite.add(DNA('R').complement()==DNA('Y')); |
2742 |
08 Jun 12 |
peter |
102 |
suite.add(DNA('Y').complement()==DNA('R')); |
2742 |
08 Jun 12 |
peter |
103 |
suite.add(DNA('S').complement()==DNA('S')); |
2742 |
08 Jun 12 |
peter |
104 |
suite.add(DNA('W').complement()==DNA('W')); |
2742 |
08 Jun 12 |
peter |
105 |
|
2742 |
08 Jun 12 |
peter |
106 |
suite.add(DNA('V').complement()==DNA('B')); |
2742 |
08 Jun 12 |
peter |
107 |
suite.add(DNA('H').complement()==DNA('D')); |
2742 |
08 Jun 12 |
peter |
108 |
suite.add(DNA('D').complement()==DNA('H')); |
2742 |
08 Jun 12 |
peter |
109 |
suite.add(DNA('B').complement()==DNA('V')); |
2742 |
08 Jun 12 |
peter |
110 |
|
2742 |
08 Jun 12 |
peter |
111 |
suite.add(DNA('N').complement()==DNA('N')); |
2343 |
17 Oct 10 |
peter |
112 |
} |
2343 |
17 Oct 10 |
peter |
113 |
|
2343 |
17 Oct 10 |
peter |
114 |
void get(test::Suite& suite) |
2343 |
17 Oct 10 |
peter |
115 |
{ |
2343 |
17 Oct 10 |
peter |
116 |
char c; |
2343 |
17 Oct 10 |
peter |
117 |
c = DNA('A').get(); |
2343 |
17 Oct 10 |
peter |
118 |
suite.add(c=='A'); |
2343 |
17 Oct 10 |
peter |
119 |
} |
2343 |
17 Oct 10 |
peter |
120 |
|
2343 |
17 Oct 10 |
peter |
121 |
void test_operator(test::Suite& suite) |
2343 |
17 Oct 10 |
peter |
122 |
{ |
2343 |
17 Oct 10 |
peter |
123 |
DNA dna('N'); |
2343 |
17 Oct 10 |
peter |
124 |
dna &= DNA('R'); |
2343 |
17 Oct 10 |
peter |
125 |
suite.add(dna==DNA('R')); |
2343 |
17 Oct 10 |
peter |
126 |
dna &= DNA('M'); |
2343 |
17 Oct 10 |
peter |
127 |
suite.add(dna==DNA('A')); |
2343 |
17 Oct 10 |
peter |
128 |
|
2343 |
17 Oct 10 |
peter |
129 |
dna = DNA('R') & DNA('M'); |
2343 |
17 Oct 10 |
peter |
130 |
suite.add(dna==DNA('A')); |
2343 |
17 Oct 10 |
peter |
131 |
|
2343 |
17 Oct 10 |
peter |
132 |
dna = DNA('A'); |
2343 |
17 Oct 10 |
peter |
133 |
dna |= DNA('C'); |
2343 |
17 Oct 10 |
peter |
134 |
suite.add(dna==DNA('M')); |
2343 |
17 Oct 10 |
peter |
135 |
|
2343 |
17 Oct 10 |
peter |
136 |
dna = DNA('A') | DNA('C'); |
2343 |
17 Oct 10 |
peter |
137 |
suite.add(dna==DNA('M')); |
2343 |
17 Oct 10 |
peter |
138 |
|
2343 |
17 Oct 10 |
peter |
139 |
dna ^= DNA('A'); |
2343 |
17 Oct 10 |
peter |
140 |
suite.add(dna==DNA('C')); |
2343 |
17 Oct 10 |
peter |
141 |
|
2343 |
17 Oct 10 |
peter |
142 |
dna = DNA('A') ^ DNA('M'); |
2343 |
17 Oct 10 |
peter |
143 |
suite.add(dna==DNA('C')); |
2343 |
17 Oct 10 |
peter |
144 |
|
2343 |
17 Oct 10 |
peter |
145 |
suite.out() << "testing output operator: " << DNA('N') << "\n"; |
2343 |
17 Oct 10 |
peter |
146 |
} |
2343 |
17 Oct 10 |
peter |
147 |
|
2343 |
17 Oct 10 |
peter |
148 |
void expand(test::Suite& suite) |
2343 |
17 Oct 10 |
peter |
149 |
{ |
2343 |
17 Oct 10 |
peter |
150 |
DNA dna('M'); |
2343 |
17 Oct 10 |
peter |
151 |
std::string str = expand(dna); |
2343 |
17 Oct 10 |
peter |
152 |
suite.add(str=="AC" || str=="CA"); |
2343 |
17 Oct 10 |
peter |
153 |
} |