ProteoWizard
DiffTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Darren Kessner <darren@proteowizard.org>
6//
7// Copyright 2007 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#include "Diff.hpp"
24//#include "examples.hpp"
27#include <cstring>
28
29
30using namespace pwiz::util;
31using namespace pwiz::proteome;
32using namespace pwiz::data;
33
34
35ostream* os_ = 0;
36
37
38// BUG: Protein doesn't have a default ctor, should it?
39/*void testProtein()
40{
41 if (os_) *os_ << "testProtein()\n";
42
43 Protein a("420", 0, "", ""), b("420", 0, "", "");
44
45 Diff<Protein> diff(a, b);
46 if (diff) cout << diff;
47 unit_assert(!diff);
48
49 b.id = "421";
50 unit_assert(diff);
51}*/
52
53
55{
56 if (os_) *os_ << "testProteinList()\n";
57
58 ProteinListSimple aSimple, bSimple;
59
60 ProteinPtr protein1a = ProteinPtr(new Protein("420", 0, "", ""));
61 ProteinPtr protein1b = ProteinPtr(new Protein("420", 0, "", ""));
62
63 aSimple.proteins.push_back(protein1a);
64 bSimple.proteins.push_back(protein1b);
65
66 ProteinList& a = aSimple;
67 ProteinList& b = bSimple;
68
70
71 DiffConfig config_ignore;
72 config_ignore.ignoreMetadata = true;
73
74 Diff<ProteinList, DiffConfig, ProteinListSimple> diffIgnore(a, b, config_ignore);
76 unit_assert(!diffIgnore);
77
78 // check: different ProteinList::size()
79
80 ProteinPtr protein2 = ProteinPtr(new Protein("421", 0, "", ""));
81 aSimple.proteins.push_back(protein2);
82
83 diff(a, b);
84 if (os_) *os_ << diff << endl;
86 unit_assert(diff.a_b.proteins.size() == 1);
87
88 diffIgnore(a, b);
89 if (os_) *os_ << diffIgnore << endl;
90 unit_assert(diffIgnore);
91 unit_assert(diffIgnore.a_b.proteins.size() == 1);
92
93 // check: same ProteinList::size(), different last id
94
95 ProteinPtr protein3 = ProteinPtr(new Protein("422", 0, "", ""));
96 bSimple.proteins.push_back(protein3);
97
98 diff(a, b);
99 if (os_) *os_ << diff << endl;
101 unit_assert(diff.a_b.proteins.size() == 1);
102 unit_assert(diff.a_b.proteins[0]->id == "421");
103 unit_assert(diff.b_a.proteins.size() == 1);
104 unit_assert(diff.b_a.proteins[0]->id == "422");
105
106 // id is not ignored
107 diffIgnore(a, b);
108 unit_assert(diffIgnore);
109
110 // check: ids match, different description
111
112 bSimple.proteins.back() = ProteinPtr(new Protein("421", 0, "different metadata", ""));
113
114 diff(a, b);
115 if (os_) *os_ << diff << endl;
117 unit_assert(diff.a_b.proteins.size() == 1);
118 unit_assert(diff.a_b.proteins[0]->description == "");
119 unit_assert(diff.b_a.proteins.size() == 1);
120 unit_assert(diff.b_a.proteins[0]->description == "different metadata");
121
122
123 diffIgnore(a, b);
124 unit_assert(!diffIgnore);
125
126 // check: same metadata, different sequences
127
128 bSimple.proteins.back() = ProteinPtr(new Protein("421", 0, "", "ELVISLIVES"));
129
130 diff(a, b);
132
133 diffIgnore(a, b);
134 unit_assert(diffIgnore);
135}
136
137
139{
140 if (os_) *os_ << "testProteomeData()\n";
141
142 ProteomeData a, b;
143
144 a.id = "goober";
145 b.id = "goober";
146
149
150 b.id = "raisinet";
151
152 shared_ptr<ProteinListSimple> proteinList1(new ProteinListSimple);
153 proteinList1->proteins.push_back(ProteinPtr(new Protein("p1", 0, "", "")));
154 b.proteinListPtr = proteinList1;
155
156 diff(a, b);
157 if (os_) *os_ << diff << endl;
159
160 unit_assert(diff.a_b.proteinListPtr.get());
161 unit_assert(diff.a_b.proteinListPtr->size() == 1);
162}
163
164
165void test()
166{
167 //testProtein();
170}
171
172
173int main(int argc, char* argv[])
174{
175 TEST_PROLOG_EX(argc, argv, "_ProteomeData")
176
177 try
178 {
179 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
180 test();
181 }
182 catch (exception& e)
183 {
184 TEST_FAILED(e.what())
185 }
186 catch (...)
187 {
188 TEST_FAILED("Caught unknown exception.")
189 }
190
192}
193
void diff(const string &filename1, const string &filename2)
int main(int argc, char *argv[])
Definition DiffTest.cpp:173
void testProteinList()
Definition DiffTest.cpp:54
ostream * os_
Definition DiffTest.cpp:35
void test()
Definition DiffTest.cpp:165
void testProteomeData()
Definition DiffTest.cpp:138
boost::shared_ptr< Protein > ProteinPtr
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Definition diff_std.hpp:143
object_result_type a_b
Definition diff_std.hpp:156
configuration struct for diffs
Definition Diff.hpp:73
std::vector< ProteinPtr > proteins
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_PROLOG_EX(argc, argv, suffix)
Definition unit.hpp:157
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177