File tree Expand file tree Collapse file tree 3 files changed +70
-49
lines changed Expand file tree Collapse file tree 3 files changed +70
-49
lines changed Original file line number Diff line number Diff line change
1
+ /* *
2
+ * This file is part of the SparseMatrix library
3
+ *
4
+ * @license MIT
5
+ * @author Petr Kessler (https://kesspess.cz)
6
+ * @link https://github.com/uestla/Sparse-Matrix
7
+ */
8
+
9
+ #ifndef __HELPERS_H__
10
+
11
+ #define __HELPERS_H__
12
+
13
+ #include < vector>
14
+ #include < iostream>
15
+
16
+ using namespace std ;
17
+
18
+
19
+ // === GENERATORS =========================================
20
+
21
+ template <typename T>
22
+ vector<T> generateRandomVector (int size)
23
+ {
24
+ vector<T> vector (size, 0 );
25
+
26
+ for (int i = 0 ; i < size; i++) {
27
+ vector[i] = rand () % 101 ;
28
+ }
29
+
30
+ return vector;
31
+ }
32
+
33
+
34
+ template <typename T>
35
+ vector<vector<T> > generateRandomMatrix (int rows, int columns)
36
+ {
37
+ vector<vector<T> > matrix (rows, vector<int >(columns, 0 ));
38
+
39
+ for (int i = 0 ; i < rows; i++) {
40
+ for (int j = 0 ; j < columns; j++) {
41
+ matrix[i][j] = rand () % 101 ;
42
+ }
43
+ }
44
+
45
+ return matrix;
46
+ }
47
+
48
+
49
+ // === OUTPUT HELPERS =========================================
50
+
51
+ template <typename T>
52
+ ostream & operator << (ostream & os, const vector<T> & v)
53
+ {
54
+ os << " [" ;
55
+
56
+ for (int i = 0 , len = v.size (); i < len; i++) {
57
+ if (i != 0 ) {
58
+ os << " , " ;
59
+ }
60
+
61
+ os << v[i];
62
+ }
63
+
64
+ os << " ]" ;
65
+
66
+ return os;
67
+ }
68
+
69
+ #endif
Original file line number Diff line number Diff line change 104
104
}
105
105
}
106
106
107
-
108
- template <typename T>
109
- vector<T> generateRandomVector (int size)
110
- {
111
- vector<T> vector (size, 0 );
112
-
113
- for (int i = 0 ; i < size; i++) {
114
- vector[i] = rand () % 101 ;
115
- }
116
-
117
- return vector;
118
- }
119
-
120
-
121
- template <typename T>
122
- vector<vector<T> > generateRandomMatrix (int rows, int columns)
123
- {
124
- vector<vector<T> > matrix (rows, vector<int >(columns, 0 ));
125
-
126
- for (int i = 0 ; i < rows; i++) {
127
- for (int j = 0 ; j < columns; j++) {
128
- matrix[i][j] = rand () % 101 ;
129
- }
130
- }
131
-
132
- return matrix;
133
- }
134
-
135
-
136
- // === OUTPUT HELPERS =========================================
137
-
138
- template <typename T>
139
- ostream & operator << (ostream & os, const vector<T> & v)
140
- {
141
- os << " [" ;
142
-
143
- for (int i = 0 , len = v.size (); i < len; i++) {
144
- if (i != 0 ) {
145
- os << " , " ;
146
- }
147
-
148
- os << v[i];
149
- }
150
-
151
- os << " ]" ;
152
-
153
- return os;
154
- }
155
-
156
107
#endif
Original file line number Diff line number Diff line change 10
10
#include < cstdlib>
11
11
#include < iostream>
12
12
#include " inc/testslib.h"
13
+ #include " inc/helpers.h"
13
14
14
15
#include " ../src/SparseMatrix/SparseMatrix.cpp"
15
16
#include " cases/constructor.h"
You can’t perform that action at this time.
0 commit comments