ProteoWizard
ProteinListWrapperTest.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
27
28using namespace pwiz::proteome;
29using namespace pwiz::util;
30
31
32class MyWrapper : public ProteinListWrapper
33{
34 public:
35
37 : ProteinListWrapper(inner)
38 {}
39
40 void verifySize(size_t size)
41 {
42 // verify that we can see inner_
43 unit_assert(size == inner_->size());
44 }
45};
46
47
49{
50 // a simple filter that returns only even indices
51
52 public:
53
55 : ProteinListWrapper(inner)
56 {}
57
58 virtual size_t size() const {return inner_->size()/2;}
59 virtual ProteinPtr protein(size_t index, bool getSequence = true) const {return inner_->protein(index*2, getSequence);}
60};
61
62
63void test()
64{
65 typedef shared_ptr<ProteinListSimple> ProteinListSimplePtr;
66 ProteinListSimplePtr simple(new ProteinListSimple);
67
68 const size_t proteinCount = 10;
69 for (size_t i=0; i<proteinCount; i++)
70 simple->proteins.push_back(ProteinPtr(new Protein("PWIZ:" + lexical_cast<string>(i), i, "", "")));
71
72 // check MyWrapper
73
74 shared_ptr<MyWrapper> wrapper(new MyWrapper(simple));
75
76 wrapper->verifySize(10);
77 unit_assert(wrapper->size() == 10);
78 for (size_t i=0; i<proteinCount; i++)
79 {
80 string id = "PWIZ:" + lexical_cast<string>(i);
81
82 unit_assert(wrapper->find(id) == i);
83
84 ProteinPtr s = wrapper->protein(i);
85 unit_assert(s->id == id);
86 }
87
88 // check FilterWrapper
89
90 shared_ptr<FilterWrapper> filterWrapper(new FilterWrapper(simple));
91
92 unit_assert(filterWrapper->size() == 5);
93
94 for (size_t i=0; i<filterWrapper->size(); i++)
95 {
96 string id = "PWIZ:" + lexical_cast<string>(i*2);
97
98 unit_assert(filterWrapper->find(id) == i);
99
100 ProteinPtr s = filterWrapper->protein(i);
101 unit_assert(s->id == id);
102 }
103}
104
105
106int main(int argc, char* argv[])
107{
108 TEST_PROLOG(argc, argv)
109
110 try
111 {
112 test();
113 }
114 catch (exception& e)
115 {
116 TEST_FAILED(e.what())
117 }
118 catch (...)
119 {
120 TEST_FAILED("Caught unknown exception.")
121 }
122
124}
int main(int argc, char *argv[])
void test()
virtual ProteinPtr protein(size_t index, bool getSequence=true) const
FilterWrapper(const ProteinListPtr &inner)
virtual size_t size() const
MyWrapper(const ProteinListPtr &inner)
void verifySize(size_t size)
Inheritable pass-through implementation for wrapping a ProteinList.
boost::shared_ptr< Protein > ProteinPtr
boost::shared_ptr< ProteinList > ProteinListPtr
#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