source: trunk/test/dna_test.cc @ 2343

Last change on this file since 2343 was 2343, checked in by Peter, 11 years ago

adding missing file. refs #377

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