ProteoWizard
CVTranslatorTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2008 Spielberg Family Center for Applied Proteomics
8// Cedars-Sinai Medical Center, Los Angeles, California 90048
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
24#include "CVTranslator.hpp"
27#include <cstring>
28
29
30using namespace pwiz::util;
31using namespace pwiz::cv;
32using namespace pwiz::data;
33
34
35ostream* os_ = 0;
36
37
38void test(const CVTranslator& translator, const string& text, CVID correct)
39{
40 CVID result = translator.translate(text);
41 if (os_) *os_ << text << " -> (" << cvTermInfo(result).id << ", \""
42 << cvTermInfo(result).name << "\")\n";
43 unit_assert(result == correct);
44}
45
46
47void test()
48{
49 if (os_) *os_ << "test()\n";
50
51 CVTranslator translator;
52 test(translator, "FT-ICR", MS_FT_ICR);
53 test(translator, " \nFT - \tICR\t", MS_FT_ICR);
54 test(translator, " Total \t\n iOn @#$CurRENT", MS_TIC);
55
56 unit_assert(translator.translate("Darren Kessner") == CVID_Unknown);
57 translator.insert("DARREN.#$@#$^KESSNER", MS_software);
58 test(translator, "dARren kESSner", MS_software);
59
60 // test collision detection
61 bool caught = false;
62 try
63 {
64 translator.insert("darren kessner", MS_m_z);
65 }
66 catch (exception& )
67 {
68 caught = true;
69 }
70 if (os_) *os_ << "collision caught: " << boolalpha << caught << endl;
71 unit_assert(caught);
72
73 // test default extra entries
74
75 test(translator, " itms ", MS_ion_trap);
76 test(translator, " FTmS\n", MS_FT_ICR);
77}
78
79
80int main(int argc, char* argv[])
81{
82 TEST_PROLOG(argc, argv)
83
84 try
85 {
86 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
87 test();
88 }
89 catch (exception& e)
90 {
91 TEST_FAILED(e.what())
92 }
93 catch (...)
94 {
95 TEST_FAILED("Caught unknown exception.")
96 }
97
99}
100
int main(int argc, char *argv[])
ostream * os_
void test()
translates text to CV terms
cv::CVID translate(const std::string &text) const
translate text -> CVID
void insert(const std::string &text, cv::CVID cvid)
insert a text-cvid pair into the dictionary
MS_TIC
TIC (total ion current): The sum of all the separate ion currents carried by the ions of different m/...
Definition cv.hpp:1410
MS_FT_ICR
FT_ICR (fourier transform ion cyclotron resonance mass spectrometer): A mass spectrometer based on th...
Definition cv.hpp:537
MS_software
software: Software related to the recording or transformation of spectra.
Definition cv.hpp:2199
CVID_Unknown
Definition cv.hpp:114
MS_m_z
m/z: Three-character symbol m/z is used to denote the quantity formed by dividing the mass of an ion ...
Definition cv.hpp:384
MS_ion_trap
ion trap: A device for spatially confining ions using electric and magnetic fields alone or in combin...
Definition cv.hpp:1278
PWIZ_API_DECL const CVTermInfo & cvTermInfo(CVID cvid)
returns CV term info for the specified CVID
std::string name
Definition cv.hpp:14947
std::string id
Definition cv.hpp:14946
#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