-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck.cpp
97 lines (87 loc) · 2.24 KB
/
check.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <gtest/gtest.h>
#include "problem-1/main.h"
#include "problem-2/main.h"
#include "problem-3/main.h"
#include "problem-4/main.h"
#include "problem-5/main.h"
const int n = 3;
const int m = 3;
int x[n][m] = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};
int y[n][m] = {{1, 1, 1},
{2, 2, 2},
{3, 3, 3}};
int z[n][m] = {{14, 14, 14},
{32, 32, 32},
{50, 50, 50}};
int **memcpy(int y[n][m]) {
int **t = new int *[n];
for (int i = 0; i < n; i++) {
t[i] = new int[m];
memcpy(t[i], y[i], sizeof(y[i]));
}
return t;
}
TEST(Problem_1_Test, Transpose_Test) {
int **t = memcpy(y);
int **r = transpose(t, n);
for(int i = 0; i< n; i++) {
for(int j = 0; j< n; j++) {
EXPECT_EQ(r[i][j], t[j][i]);
}
}
}
TEST(Problem_2_Test, Multiply_Test) {
int **t = memcpy(y);
for (int i = 0; i < n; i++) {
int *result = multiply(x[i], t, n);
for (int j = 0; j < m; j++)
EXPECT_EQ(result[j], z[i][j]);
delete[] result;
}
for (int i = 0; i < n; i++) {
delete[] t[i];
}
delete[] t;
}
TEST(Problem_3_Test, Multiply_Test) {
int **t1 = memcpy(x);
int **t2 = memcpy(y);
int **result = multiply(t1, t2, n, m);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) EXPECT_EQ(result[i][j], z[i][j]);
for (int i = 0; i < n; i++) {
delete[] result[i];
delete[] t1[i];
delete[] t2[i];
}
delete[] result;
delete[] t1;
delete[] t2;
}
TEST(Problem_4_Test, MultiplyMatrices_Test) {
int **t1 = memcpy(x);
int **t2 = memcpy(y);
int **result = multiplyMatrices(t1, t2, n, m);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) EXPECT_EQ(result[i][j], z[i][j]);
for (int i = 0; i < n; i++) {
delete[] result[i];
delete[] t1[i];
delete[] t2[i];
}
delete[] result;
delete[] t1;
delete[] t2;
}
TEST(Problem_5_Test, Factorial_Test) {
EXPECT_EQ(factorial(0), 1);
for (int i = 1, f = 1; i < 10; i++, f *= i) {
EXPECT_EQ(factorial(i), f);
}
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}