vector_matrix_test.cc File Reference
#include "generic.h"

Functions

int main (int argc, char *argv[])
 Driver code: Testing VectorMatrix class. More...
 

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)

Driver code: Testing VectorMatrix class.

36 {
37  std::ostringstream out_stream;
38  out_stream << "OUTPUT";
39 
40  std::ofstream out_file;
41  out_file.open(out_stream.str().c_str());
42 
43  VectorMatrix<int> vector_matrix_1(3,4,-1);
44 
45  // test 1: nrow(), should be 3
46  out_file << vector_matrix_1.nrow() << "\n";
47 
48  // test 2: ncol(), should be 4
49  out_file << vector_matrix_1.ncol() << "\n";
50 
51  // test 3: [] operator, should be -1
52  out_file << vector_matrix_1[2][2] << "\n";
53 
54  // test 4: [] operator
55  vector_matrix_1[2][2] = 42;
56  // should be 42
57  out_file << vector_matrix_1[2][2] << "\n";
58 
59  // test 5: resize
60  vector_matrix_1.resize(6,8,-13);
61 
62  // should be 6
63  out_file << vector_matrix_1.nrow() << "\n";
64  // should be 8
65  out_file << vector_matrix_1.ncol() << "\n";
66 
67  // elements [0][0] and [2][2] is not changed since it is within the
68  // resize bound.
69 
70  // should be -1
71  out_file << vector_matrix_1[0][0] << "\n";
72  // should be 42
73  out_file << vector_matrix_1[2][2] << "\n";
74  // should be -13 (the value given to resize)
75  out_file << vector_matrix_1[5][7] << "\n";
76 
77  // test 6: assign
78  vector_matrix_1.assign(24,32,-42);
79 
80 
81  // All elements should be destroyed and replaced, so all elements should be
82  // -42. Check a random one.
83  out_file << vector_matrix_1[24 * (rand() / (RAND_MAX + 1.0))]
84  [32 * (rand() / (RAND_MAX + 1.0))]<<"\n";
85 
86  // test clear
87  vector_matrix_1.clear();
88  // should be 0
89  out_file << vector_matrix_1.nrow() << "\n";
90  // should be 0
91  out_file << vector_matrix_1.ncol() << "\n";
92 
94 
95  // Lastly, check other constructors.
96  const unsigned nrow = 101;
97  const unsigned ncol = 97;
98  const double val = 77.7;
99 
100  // Default constructor
101  VectorMatrix<double> vector_matrix_2;
102  // should be 0
103  out_file << vector_matrix_2.nrow() << "\n";
104  // should be 0
105  out_file << vector_matrix_2.ncol() << "\n";
106 
107  // constructor: n by m, given val
108  VectorMatrix<double> vector_matrix_3(nrow,ncol,val);
109  // should be 101
110  out_file << vector_matrix_3.nrow() << "\n";
111  // should be 97
112  out_file << vector_matrix_3.ncol() << "\n";
113  // should be 77.7
114  out_file << vector_matrix_3[nrow * (rand() / (RAND_MAX + 1.0))]
115  [ncol * (rand() / (RAND_MAX + 1.0))]<<"\n";
116 
117  // constructor: n by n, given val
118  VectorMatrix<double>vector_matrix_4(nrow,ncol);
119  // should be 101
120  out_file << vector_matrix_4.nrow() << "\n";
121  // should be 97
122  out_file << vector_matrix_4.ncol() << "\n";
123  // should be 0.0
124  out_file << vector_matrix_4[nrow * (rand() / (RAND_MAX + 1.0))]
125  [nrow * (rand() / (RAND_MAX + 1.0))]<<"\n";
126 
127  out_file.close();
128 
129  return(EXIT_SUCCESS);
130 } // end_of_main
Definition: vector_matrix.h:79
const unsigned ncol() const
Definition: vector_matrix.h:146
const unsigned nrow() const
returns the number of rows. This is the outer Vector size.
Definition: vector_matrix.h:107
val
Definition: calibrate.py:119

References oomph::VectorMatrix< VALUE_TYPE >::assign(), oomph::VectorMatrix< VALUE_TYPE >::clear(), oomph::VectorMatrix< VALUE_TYPE >::ncol(), oomph::VectorMatrix< VALUE_TYPE >::nrow(), oomph::VectorMatrix< VALUE_TYPE >::resize(), and calibrate::val.