ProteoWizard
MatrixIOTest.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
23#include <boost/filesystem/operations.hpp>
24#include <boost/make_shared.hpp>
25
26using namespace pwiz::util;
27using namespace pwiz::analysis;
28
30public:
31 void Run()
32 {
33 SetUp();
36 TearDown();
37 }
38
39protected:
40
41 virtual void SetUp()
42 {
43 }
44
45 void TearDown()
46 {
47 remove("TestMatrixIOTemp.log");
48 }
49
51 {
52 std::string testFilename = "TestMatrixIOTemp.log";
53 DemuxTypes::MatrixPtr matrix = boost::make_shared<DemuxTypes::MatrixType>(3, 3);
54 *matrix << 1, 2, 3,
55 4, 5, 6,
56 7, 8, 9;
58
59 DemuxTypes::MatrixPtr matrixIn = boost::make_shared<DemuxTypes::MatrixType>(1, 1);
61
62 unit_assert(matrixIn->isApprox(*matrix));
63 }
64
66 {
67 std::string testFilename = "TestMatrixIOTemp.log";
68
69 boost::filesystem::path full_path(boost::filesystem::current_path());
70
71 DemuxTypes::MatrixPtr A = boost::make_shared<DemuxTypes::MatrixType>(3, 4);
72 DemuxTypes::MatrixPtr B = boost::make_shared<DemuxTypes::MatrixType>(4, 3);
73 DemuxTypes::MatrixPtr C = boost::make_shared<DemuxTypes::MatrixType>(3, 3);
74 *A << -14.834628974133, -15.729764770592, 56.292839002858, 30.766363712773,
75 79.595747995303, -8.356622426449, 20.840197237638, 83.801095382748,
76 87.889866880787, 13.75327399942, 86.730656404499, -0.46420627108677;
77
78 *B << 23.588885367543, 49.667231605868, -86.700220187964,
79 51.392601274063, -77.511392742378, 23.389497301117,
80 -78.475202879706, -62.60684915327, -42.39206607192,
81 59.595164405161, 2.1025961854091, 65.787705013259;
82
83 *C = *A * *B;
84
85 std::ofstream out;
87 unit_assert(out.is_open());
91 out.flush();
92 out.close();
93
94 DemuxTypes::MatrixPtr AIn = boost::make_shared<DemuxTypes::MatrixType>(1, 1);
95 DemuxTypes::MatrixPtr BIn = boost::make_shared<DemuxTypes::MatrixType>(1, 1);
96 DemuxTypes::MatrixPtr CIn = boost::make_shared<DemuxTypes::MatrixType>(1, 1);
97
98 std::ifstream in;
100 unit_assert(in.is_open());
101 MatrixIO::ReadBinary(in, AIn);
102 MatrixIO::ReadBinary(in, BIn);
103 MatrixIO::ReadBinary(in, CIn);
104 in.close();
105
106 unit_assert(AIn->isApprox(*A));
107 unit_assert(BIn->isApprox(*B));
108 unit_assert(CIn->isApprox(*C));
109 }
110};
111
112int main(int argc, char* argv[])
113{
114 TEST_PROLOG(argc, argv)
115
116 try
117 {
118 MatrixIOTest tester;
119 tester.Run();
120 }
121 catch (exception& e)
122 {
123 TEST_FAILED(e.what())
124 }
125 catch (...)
126 {
127 TEST_FAILED("Caught unknown exception.")
128 }
129
131}
B
Definition Chemistry.hpp:81
C
Definition Chemistry.hpp:80
#define A
int main(int argc, char *argv[])
void testFilename()
virtual void SetUp()
void MultiReadWrite()
void SingleReadWrite()
static void ReadBinary(std::ifstream &in, boost::shared_ptr< DemuxTypes::MatrixType > matrix)
Convenience function for reading a single matrix from a file.
static void GetWriteStream(std::ofstream &out, const std::string &filename)
Factory method for generating output streams with fixed properties set for writing matrices.
static void WriteBinary(std::ofstream &out, boost::shared_ptr< DemuxTypes::MatrixType > matrix)
Writes a matrix to filestream including header information about the number of rows and columns....
static void GetReadStream(std::ifstream &in, const std::string &filename)
Factory method for generating input streams with fixed properties set for reading matrices.
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 TEST_PROLOG(argc, argv)
Definition unit.hpp:175