-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrices_test.cpp
69 lines (53 loc) · 1.39 KB
/
matrices_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "matrices.h"
using zst::Matrix;
int ** random_2d_array(int M, int N)
{
int ** tab = new int*[M];
for(int i = 0; i < M; i++)
{
tab[i] = new int[N];
for(int j = 0; j < N; j++)
{
tab[i][j] = rand() % 10;
}
}
return tab;
}
void read_array(int M, int N, int** arr)
{
for(int i = 0; i < M; i++)
{
for(int j = 0; j < N; j++)
std::cout << arr[i][j] << ' ' << std::flush;
std::cout << std::endl;
}
}
int main(int argc, char *argv[])
{
std::cout << "Test started." << std::endl;
srand(time(NULL));
int** tab = random_2d_array(2,3);
Matrix<int> A = Matrix<int>(2,3,tab);
delete [] tab; tab = nullptr;
tab = random_2d_array(3,5);
Matrix<int> B = Matrix<int>(3,5,tab);
delete [] tab;
Matrix<int> I = Matrix<int>(3,3,0);
for(int i = 0; i < 3; i++)
I.set_val(i,2-i,1);
try{
std::cout << "I=\n" << I.str_repr() << std::endl;
std::cout << "A=\n" << A.str_repr() << std::endl;
std::cout << "B=\n" << B.str_repr() << std::endl;
std::cout << "A*B=\n" << (A*B).str_repr() << std::endl;
}catch(char const* err_str)
{
std::cerr << err_str << std::endl;
}
delete [] tab;
std::cout << "Test finished." << std::endl;
return 0;
}