libStatGen Software  1
TrimSequence_test.cpp
1 /*
2  * Copyright (C) 2010 Regents of the University of Michigan
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include <string>
18 #include <TrimSequence.h>
19 
20 #include <gtest/gtest.h>
21 
22 TEST(TrimSequenceTest, trimSequenceTest)
23 {
24  std::string test;
25  std::string::iterator result;
26 
27  test = "445566";
28  result = trimSequence(test, '5', true);
29  EXPECT_EQ(result - test.begin() , 2);
30 
31  test = "445554555";
32  result = trimSequence(test, '5', true);
33  EXPECT_EQ(result - test.begin(), 6);
34 
35  test = "4455545556";
36  result = trimSequence(test, '5', true);
37  EXPECT_EQ(result - test.begin(), 6);
38 
39  test = "44555455566";
40  result = trimSequence(test, '5', true);
41  EXPECT_EQ(result - test.begin(), 6);
42 
43  test = "665544";
44  result = trimSequence(test, '5', false);
45  EXPECT_EQ(test.end() - result , 2);
46 
47  test = "555455544";
48  result = trimSequence(test, '5', false);
49  EXPECT_EQ(test.end() - result, 6);
50 
51  test = "6555455544";
52  result = trimSequence(test, '5', false);
53  EXPECT_EQ(test.end() - result, 6);
54 
55  // Paul's test cases in TrimSequence.cpp
56  //
57  // from the left:
58  //
59  test = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
60  result = trimSequence(test, 'A', true);
61  EXPECT_TRUE(result == test.begin());
62 
63  test = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
64  result = trimSequence(test, '~', true);
65  EXPECT_TRUE(result == test.end());
66 
67  test = "AAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
68  result = trimSequence(test, 'B', true);
69  EXPECT_TRUE(result == (test.begin() + 5));
70 
71  test = "AAAAAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
72  result = trimSequence(test, 'B', true);
73  EXPECT_TRUE(result == (test.begin() + 8));
74 
75  test = "AAAAAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
76  result = trimSequence(test, 'F', true);
77  EXPECT_TRUE(result == (test.begin() + 12));
78 
79  test = "AAAAAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
80  result = trimSequence(test, '@', true);
81  EXPECT_TRUE(result == (test.begin() + 0));
82 
83  test = "AAAAAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
84  result = trimSequence(test, '@', true);
85  EXPECT_TRUE(result == (test.begin() + 0));
86 
87  test = "AAAFAAAABCDEFGHIJKLMNOPQRSTUVWXYZ";
88  result = trimSequence(test, 'F', true);
89  EXPECT_TRUE(result == (test.begin() + 12));
90 
91  //
92  // from the right:
93  //
94  test = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
95  result = trimSequence(test, 'A', false);
96  EXPECT_TRUE(result == test.end());
97 
98  test = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
99  result = trimSequence(test, '~', false);
100  EXPECT_TRUE(result == test.begin());
101 
102  test = "ZYXWVUTSRQPONMLKJIHGFEDCBAAAAA";
103  result = trimSequence(test, 'B', false);
104  EXPECT_TRUE(result == (test.end() - 5));
105 
106  test = "ZYXWVUTSRQPONMLKJIHGFEDCBAAAAAAA";
107  result = trimSequence(test, 'B', false);
108  EXPECT_TRUE(result == (test.end() - 7));
109 
110  test = "ZYXWVUTSRQPONMLKJIHGFEDCBAAAAAAAA";
111  result = trimSequence(test, 'F', false);
112  EXPECT_TRUE(result == (test.end() - 12));
113 
114  test = "ZYXWVUTSRQPONMLKJIHGFEDCBAAAAAAAA";
115  result = trimSequence(test, '@', false);
116  EXPECT_TRUE(result == (test.end() + 0));
117 
118  test = "ZYXWVUTSRQPONMLKJIHGFEDCBAAAAFAAA";
119  result = trimSequence(test, 'F', false);
120  EXPECT_TRUE(result == (test.end() - 12));
121 };