Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestMatrixIO.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8 
9  BIAS is free software; you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation; either version 2.1 of the License, or
12  (at your option) any later version.
13 
14  BIAS is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with BIAS; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
22 /*
23 Example Run output:
24 --------------------------------------------
25 instance1 is:
26 2 3
27 1.251258888515884900e-003 5.635853144932401200e-001 1.933042390209662200e-001
28 8.087405011139255900e-001 5.850093081453902100e-001 4.798730430005798700e-001
29 --------------------------------------------
30 instance2 is:
31 2 3
32 1.251260000000000100e-003 5.635850000000000000e-001 1.933040000000000000e-001
33 8.087410000000000400e-001 5.850090000000000000e-001 4.798729999999999900e-001
34 --------------------------------------------
35 equality test result is: 0
36 */
37 
38 
39 /**
40  @test TestMatrixIO.cpp
41  @brief Test Matrix I/O precision issues. Deprecated!
42  @ingroup g_tests
43  @author evers
44 */
45 
46 // file used for I/O
47 #ifdef WIN32
48 # define TMP "tmp.txt"
49 # define TMP2 "tmp.m"
50 #else //WIN32
51 # define TMP "/tmp/tmp.txt"
52 # define TMP2 "/tmp/tmp.m"
53 #endif //WIN32
54 
55 
56 #include <Base/Math/Matrix.hh>
57 #include <cmath>
58 #include <iomanip>
59 #include <iostream>
60 #include <string>
61 #include <fstream>
62 #include <cassert>
63 
64 using namespace std;
65 
66 double randomDouble_local(){
67  return ((double) rand() / (double) RAND_MAX);
68 }
69 
70 
71 int main(int argc, char* argv[]){
72 
73  //====== INITIAL INSTANCE ======================
74  //create an instance of the matrix class, and fill it with
75  // random data
76  BIAS::Matrix<double> instance1(2, 3);
77 
78  for( int r = 0; r < 2; r++)
79  for( int c = 0; c < 3; c++)
80  instance1[r][c] = randomDouble_local();
81 
82  //create output file, and write to it.
83  ofstream fOut(TMP, ios::out);
84 
85  fOut << instance1;
86  fOut.close();
87 
88  ofstream fmOut(TMP2, ios::out);
89 
90  instance1.WriteMatlab(fmOut, "randommat");
91  fOut.close();
92 
93  //====== INSTANCE POPULATED FROM FILE =========
94  //open the file created
95  ifstream fIn(TMP, ios::in );
96 
97  // create new instace of the object
98  BIAS::Matrix<double> instance2(2, 3);
99 
100  // read in from the file
101  fIn >> instance2;
102  fIn.close();
103 
104 
105  //======= TEST EQUALITY OF INSTANCES ==========
106 
107  //test that the outputed and inputed objects pass an equality test
108  bool equalityTestResult = (instance1 == instance2);
109 
110  //show a command line user the result(s)...
111  cout << setprecision(25);
112  cout << scientific;
113 
114  cout << "--------------------------------------------\n";
115  cout << "instance1 is: \n" << instance1 << "\n\n";
116 
117  cout << "--------------------------------------------\n";
118  cout << "instance2 is: \n" << instance2 << "\n\n";
119 
120  cout << "--------------------------------------------\n";
121  cout << "equality test result is: " <<boolalpha<< equalityTestResult << "\n";
122 
123  if (equalityTestResult == false)
124  cout << "Residuum: "<<instance2-instance1<<endl;
125 
126  //insure passes test
127  BIASASSERT( equalityTestResult == true ) ;
128 
129 }
#define TMP
Test Matrix I/O precision issues. Deprecated!