ProteoWizard
KwCVMapTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Robert Burke <robert.burke@proteowizard.org>
6//
7// Copyright 2010 Spielberg Family Center for Applied Proteomics
8// University of Southern California, Los Angeles, California 90033
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21//
22
23#include "KwCVMap.hpp"
24#include "examples.hpp"
27
28using namespace pwiz::util;
29using namespace pwiz::data;
30using namespace pwiz::identdata;
31
32ostream* os_ = 0;
33//const double epsilon = numeric_limits<double>::epsilon();
34
36{
37 if (os_) (*os_) << "\ntestCVMap()\n";
38
39 CVMap map("sample name", MS_sample_name,
40 "/mzIdentML/AnalysisSampleCollection/Sample/cvParam");
41
42 unit_assert(map.keyword == "sample name");
44 unit_assert(map("sample name"));
45 unit_assert(!map("potato"));
46}
47
49{
50 if (os_) (*os_) << "\ntestRegexCVMap()\n";
51
52 RegexCVMap rx("[Ss]ample[ ]+[Nn]ame", MS_sample_name,
53 "/mzIdentML/AnalysisSampleCollection/Sample/cvParam");
54
55 //unit_assert(map.keyword == "sample name");
57 unit_assert(rx("sample name"));
58 unit_assert(rx("Sample name"));
59 unit_assert(rx("sample Name"));
60 unit_assert(rx("Sample Name"));
61 unit_assert(!rx("turnip"));
62}
63
65{
66 if (os_) (*os_) << "\ntestCVMapIO()\n";
67
68 CVMap map("sample name", MS_sample_name,
69 "/mzIdentML/AnalysisSampleCollection/Sample/cvParam");
70 stringstream ss;
71
72 ss << map;
73
74 if (os_) (*os_) << "insertion operator:\n" << ss.str();
75 unit_assert(ss.str() == "plain\tsample name\tMS:1000002"
76 "\t/mzIdentML/AnalysisSampleCollection/Sample/cvParam\n");
77
78 // Test CVMapPtr extraction
79 CVMapPtr cvmPtr;
80 ss >> cvmPtr;
81
82 if (os_) (*os_) << "NULL pointer returned?"
83 << (cvmPtr.get() == NULL) << endl;
84 unit_assert(cvmPtr.get());
85
86 if (os_) (*os_) << typeid(cvmPtr.get()).name() << endl;
87 unit_assert(typeid(cvmPtr.get()).name() == typeid(CVMap*).name());
88
89 if (os_) (*os_) << "keyword: " << cvmPtr->keyword << endl;
90 if (os_) (*os_) << "cvid: " << cvmPtr->cvid << endl;
91 unit_assert(cvmPtr->keyword == "sample name");
92 unit_assert(cvmPtr->cvid == MS_sample_name);
93}
94
96{
97 if (os_) (*os_) << "\ntestRegexCVMapIO()\n";
98
99 RegexCVMap map("[Ss]ample [Nn]ame", MS_sample_name,
100 "/mzIdentML/AnalysisSampleCollection/Sample/cvParam");
101 stringstream ss;
102
103 ss << map;
104
105 if (os_) (*os_) << "insertion operator:\n" << ss.str();
106 unit_assert(ss.str() == "regex\t[Ss]ample [Nn]ame\tMS:1000002\t"
107 "/mzIdentML/AnalysisSampleCollection/Sample/cvParam\n");
108
109 // Test CVMapPtr extraction
110 CVMapPtr cvmPtr;
111 ss >> cvmPtr;
112
113 if (os_) (*os_) << "NULL pointer returned?"
114 << (cvmPtr.get() == NULL) << endl;
115 unit_assert(cvmPtr.get());
116
117 if (os_) (*os_) << typeid(cvmPtr.get()).name() << endl;
118 unit_assert(typeid(cvmPtr.get()).name() == typeid(CVMap*).name());
119
120 if (os_) (*os_) << "keyword: " << cvmPtr->keyword << endl;
121 if (os_) (*os_) << "cvid: " << cvmPtr->cvid << endl;
122 unit_assert(cvmPtr->keyword == "[Ss]ample [Nn]ame");
123 unit_assert(cvmPtr->cvid == MS_sample_name);
124}
125
127{
128 if (os_) (*os_) << "\ntestVectorIO()\n";
129
130 const char* file =
131 "plain\tsample name\tMS:1000002\t/mzIdentML/AnalysisSampleCollection/Sample/cvParam\n"
132 "regex\t[Aa]ccuracy[ ]*\tMS:1000014\t/mzIdentML\n"
133 "regex\t[Ss]can start time[\\.]?\tMS:1000016\t/mzIdentML\n";
134
135 if (os_) (*os_) << "file used:\n" << file << endl;
136 istringstream iss(file);
137
138 vector<CVMapPtr> mappings;
139 iss >> mappings;
140
141 if (os_) (*os_) << "Records read in:\n";
142 for (vector<CVMapPtr>::iterator i=mappings.begin(); i!=mappings.end(); i++)
143 {
144 if (os_) (*os_) << *i;
145 }
146
147 // TODO add some record specific checking here.
148
149 ostringstream oss;
150
151 oss << mappings;
152
153 if (os_) (*os_) << "\nResulting vector output:\n";
154 if (os_) (*os_) << oss.str() << endl;
155 unit_assert(oss.str() == file);
156}
157
158void test()
159{
160 testCVMap();
162 testCVMapIO();
164 testVectorIO();
165}
166
167int main(int argc, char* argv[])
168{
169 TEST_PROLOG(argc, argv)
170
171 try
172 {
173 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
174 test();
175 }
176 catch (exception& e)
177 {
178 TEST_FAILED(e.what())
179 }
180 catch (...)
181 {
182 TEST_FAILED("Caught unknown exception.")
183 }
184
186}
187
int main(int argc, char *argv[])
void testVectorIO()
void testCVMapIO()
void testRegexCVMap()
void testCVMap()
ostream * os_
void testRegexCVMapIO()
void test()
MS_sample_name
sample name: A reference string relevant to the sample under study.
Definition cv.hpp:267
boost::shared_ptr< CVMap > CVMapPtr
Definition KwCVMap.hpp:58
std::string keyword
Definition KwCVMap.hpp:45
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175