ProteoWizard
DiffTest.cpp
Go to the documentation of this file.
1 //
2 // $Id: DiffTest.cpp 4129 2012-11-20 00:05:37Z chambm $
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 
30 using namespace pwiz::util;
31 using namespace pwiz::proteome;
32 using namespace pwiz::data;
33 
34 
35 ostream* 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);
75  unit_assert(!diff);
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;
85  unit_assert(diff);
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;
100  unit_assert(diff);
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;
116  unit_assert(diff);
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);
131  unit_assert(diff);
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 
148  unit_assert(!diff);
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;
158  unit_assert(diff);
159 
160  unit_assert(diff.a_b.proteinListPtr.get());
161  unit_assert(diff.a_b.proteinListPtr->size() == 1);
162 }
163 
164 
165 void test()
166 {
167  //testProtein();
168  testProteinList();
170 }
171 
172 
173 int 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