ProteoWizard
DemuxDebugReadWriteTest.cpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Austin Keller <atkeller .@. uw.edu>
6//
7// Licensed under the Apache License, Version 2.0 (the "License");
8// you may not use this file except in compliance with the License.
9// You may obtain a copy of the License at
10//
11// http://www.apache.org/licenses/LICENSE-2.0
12//
13// Unless required by applicable law or agreed to in writing, software
14// distributed under the License is distributed on an "AS IS" BASIS,
15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16// See the License for the specific language governing permissions and
17// limitations under the License.
18//
19
24#include <boost/make_shared.hpp>
25
26using namespace pwiz::analysis;
27using namespace pwiz::util;
28using namespace DemuxTypes;
29
31
32public:
33
34 void Run()
35 {
36 SetUp();
38 TearDown();
39 }
40
41protected:
42
44 {
45 { // Use scope to ensure deletion of debug writer to close output file
46 DemuxDebugWriter debugWriter("DemuxDebugOutput_TestOut.log");
47 unit_assert(debugWriter.IsOpen());
48
49 for (size_t i = 0; i < spectrumList_.size(); i += 3)
50 {
51 debugWriter.WriteDeconvBlock(i, spectrumList_.at(i), spectrumList_.at(i + 1), spectrumList_.at(i + 2));
52 }
53 }
54
55 vector<MatrixPtr> readSpectrumList;
56
57 DemuxDebugReader debugReader("DemuxDebugOutput_TestOut.log");
58 unit_assert(debugReader.IsOpen());
59 unit_assert_operator_equal(3 * debugReader.NumBlocks(), spectrumList_.size());
60
61 uint64_t spectrumIndex;
62 for (size_t i = 0; i < debugReader.NumBlocks(); ++i)
63 {
64 auto index = static_cast<uint64_t>(spectrumIndex); // needed for 32-bit compatibility
65 debugReader.ReadDeconvBlock(index, A_, B_, C_);
66 readSpectrumList.push_back(A_);
67 readSpectrumList.push_back(B_);
68 readSpectrumList.push_back(C_);
69 }
70
71 unit_assert_operator_equal(readSpectrumList.size(), spectrumList_.size());
72
73 for (size_t i = 0; i < readSpectrumList.size(); ++i)
74 {
75 unit_assert(spectrumList_.at(i)->isApprox(*readSpectrumList.at(i)));
76 }
77 }
78
79 void SetUp() {
80 // Generate a list of spectra
81 A_ = boost::make_shared<MatrixType>(3, 4);
82 B_ = boost::make_shared<MatrixType>(4, 3);
83 C_ = boost::make_shared<MatrixType>(3, 3);
84 *A_ << -14.834628974133, -15.729764770592, 56.292839002858, 30.766363712773,
85 79.595747995303, -8.356622426449, 20.840197237638, 83.801095382748,
86 87.889866880787, 13.75327399942, 86.730656404499, -0.46420627108677;
87
88 *B_ << 23.588885367543, 49.667231605868, -86.700220187964,
89 51.392601274063, -77.511392742378, 23.389497301117,
90 -78.475202879706, -62.60684915327, -42.39206607192,
91 59.595164405161, 2.1025961854091, 65.787705013259;
92
93 *C_ = *A_ * *B_;
94
95 spectrumList_.push_back(A_);
96 spectrumList_.push_back(B_);
97 spectrumList_.push_back(C_);
98
99 MatrixPtr D = boost::make_shared<MatrixType>(3, 4);
100 MatrixPtr E = boost::make_shared<MatrixType>(4, 3);
101 MatrixPtr F = boost::make_shared<MatrixType>(3, 3);
102
103 *D = 5 * A_->eval();
104 *E = 3 * B_->eval();
105 *F = *A_ * *B_;
106
107 spectrumList_.push_back(A_);
108 spectrumList_.push_back(B_);
109 spectrumList_.push_back(C_);
110 }
111
112 void TearDown()
113 {
114 remove("DemuxDebugOutput_TestOut.log");
115 }
116
117 vector<MatrixPtr> spectrumList_;
121};
122
123
124int main(int argc, char* argv[])
125{
126 TEST_PROLOG(argc, argv)
127
128 try
129 {
130 DemuxDebugRWTest tester;
131 tester.Run();
132 }
133 catch (exception& e)
134 {
135 TEST_FAILED(e.what())
136 }
137 catch (...)
138 {
139 TEST_FAILED("Caught unknown exception.")
140 }
141
143}
F
Definition Chemistry.hpp:81
int main(int argc, char *argv[])
#define D
vector< MatrixPtr > spectrumList_
A class for reading demux matrices from file.
bool IsOpen() const
Should be called after construction to verify that the file was opened successfully.
size_t NumBlocks() const
Number of blocks (sets of matrices) that are contained in the file.
void ReadDeconvBlock(uint64_t &spectrumIndex, DemuxTypes::MatrixPtr masks, DemuxTypes::MatrixPtr solution, DemuxTypes::MatrixPtr signal)
Can be used to read through the blocks sequntially.
A class for writing demux matrices to file.
bool IsOpen() const
Should be called after construction to verify that the file was opened successfully.
void WriteDeconvBlock(uint64_t spectrumIndex, DemuxTypes::MatrixPtr masks, DemuxTypes::MatrixPtr solution, DemuxTypes::MatrixPtr signal)
Writes a set of matrices with the given spectrum index to file.
boost::shared_ptr< MatrixType > MatrixPtr
#define unit_assert(x)
Definition unit.hpp:85
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define unit_assert_operator_equal(expected, actual)
Definition unit.hpp:92
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175