Skip to content

Commit 7878461

Browse files
committed
tests: separated helper functions into standalone file
1 parent 834e8f0 commit 7878461

File tree

3 files changed

+70
-49
lines changed

3 files changed

+70
-49
lines changed

tests/inc/helpers.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

tests/inc/testslib.h

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -104,53 +104,4 @@
104104
}
105105
}
106106

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-
156107
#endif

tests/run.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <cstdlib>
1111
#include <iostream>
1212
#include "inc/testslib.h"
13+
#include "inc/helpers.h"
1314

1415
#include "../src/SparseMatrix/SparseMatrix.cpp"
1516
#include "cases/constructor.h"

0 commit comments

Comments
 (0)