-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.cpp
More file actions
158 lines (141 loc) · 4.96 KB
/
tests.cpp
File metadata and controls
158 lines (141 loc) · 4.96 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "src/aux.h"
#include "src/matrix.h"
#include <algorithm>
#include <gtest/gtest.h>
/*
Usando o gtest https://zwarrior.medium.com/install-google-test-framework-gtest-on-ubuntu-20-04-368eb6951b12
Tutorial https://www.tutorialspoint.com/gtest/index.htm#gtest_features
*/
TEST(DETERMINANTES, N1) {
matrix m1({3});
EXPECT_EQ(m1.det(), 3);
}
TEST(DETERMINANTES, N2) {
matrix m1({2, 2}, {1, 2, 3, 4}); // det -2
EXPECT_EQ(m1.det(), -2);
}
TEST(DETERMINANTES, N3) {
matrix m1({3, 3}, {1, 2, 3, 4, 5, 6, 7, 8, 9}); // det 0
EXPECT_EQ(m1.det(), 0);
}
TEST(DETERMINANTES, N4) {
matrix m1({4, 4}, {2, 1, 3, 1, 1, 0, 1, 1, 0, 2, 1, 0, 0, 1, 2, 3});
EXPECT_EQ(m1.det(), 6);
}
TEST(MULTI, N1) {
matrix m1({1});
matrix m2({2});
matrix p = m1 * m2; // {2}
matrix r({2});
ASSERT_TRUE(p == r);
}
TEST(MULTI, N2) {
matrix m1({2, 2}, {1, 2, 3, 4});
matrix m2({2, 2}, {5, 6, 7, 8});
matrix p = m1 * m2; // {19, 22, 43, 50}
matrix r({2, 2}, {19, 22, 43, 50});
ASSERT_TRUE(p == r);
}
TEST(MULTI, N3) {
matrix m1({3, 3}, {1, 2, 3, 4, 5, 6, 7, 8, 9});
matrix m2({3, 3}, {10, 11, 12, 13, 14, 15, 16, 17, 18});
matrix p = m1 * m2; // {84, 90, 96, 201, 216, 231, 318, 342, 366}
matrix r({3, 3}, {84, 90, 96, 201, 216, 231, 318, 342, 366});
ASSERT_TRUE(p == r);
}
TEST(MULTI, NN) {
matrix m1({2, 2, 2},
{
1,
2,
3,
4,
5,
6,
7,
8,
});
matrix m2({2, 2, 2},
{
1,
2,
3,
4,
5,
6,
7,
8,
});
matrix p = m1 * m2; // {7,10,15,22,67,78,91,106}
matrix r({2, 2, 2}, {7, 10, 15, 22, 67, 78, 91, 106});
// std::cout << m1 << std::endl;
ASSERT_TRUE(p == r);
} // dimensões maiores
TEST(INVERT, N2) {
matrix m({2, 2}, {1, 2, 3, 4});
matrix r({2, 2}, {-2, 1, 1.5, -0.5});
matrix a = m.invert();
ASSERT_TRUE(r == a);
}
TEST(INVERT, N3) {
matrix m({3, 3}, {2, -1, 0, -1, 2, -1, 0, -1, 2});
matrix r({3, 3}, {0.75, 0.5, 0.25, 0.5, 1, 0.5, 0.25, 0.5, 0.75});
matrix a = m.invert();
ASSERT_TRUE(r == a);
}
TEST(NORMALIZE, N3) {
matrix m({3, 3}, {1, 2, 3, 4, 5, 6, 7, 8, 9});
matrix r({3, 3}, {0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1});
matrix a = m.normalize();
ASSERT_TRUE(r == a);
}
TEST(AUTOVALORES, N2) {
matrix m({2, 2}, {2, 1, 2, 1});
std::vector<d_type> r1 = {1, 3};
std::vector<d_type> a = m.autovalores();
bool e = r1.size() == a.size() && std::all_of(r1.begin(), r1.end(), [&](const d_type &m) {
return std::find(a.begin(), a.end(), m) != a.end();
});
ASSERT_TRUE(e);
}
TEST(AUTOVALORES, N3) {
matrix m({3, 3}, {2, 0, 0, 0, 3, 4, 0, 4, 9});
// talvez trocar para um vector
std::vector<d_type> r1 = {1, 2, 11};
std::vector<d_type> a = m.autovalores();
bool e = r1.size() == a.size() && std::all_of(r1.begin(), r1.end(), [&](const d_type &m) {
return std::find(a.begin(), a.end(), m) != a.end();
});
ASSERT_TRUE(e);
}
TEST(IGUALDADE, N3) {
matrix m1({3, 3}, {1, 2, 3, 4, 5, 6, 7, 8, 9});
matrix m2({3, 3}, {1, 2, 3, 4, 5, 6, 7, 8, 9});
ASSERT_TRUE(m1 == m2);
}
// Falta implementar operadores para esses testes funcionarem, com a verificacao
TEST(AUTOVETORES, N2) {
matrix m({2, 2}, {2, 1, 2, 1});
// talvez trocar para um vector
std::vector<matrix> r1 = {
matrix({2, 1}, {-1, 1}),
matrix({2, 1}, {1, 1}),
};
std::vector<matrix> a = m.autovetores();
// comparacao independete da ordem
bool e = r1.size() == a.size() && std::all_of(r1.begin(), r1.end(), [&](const matrix &m) {
return std::find(a.begin(), a.end(), m) != a.end();
});
ASSERT_TRUE(e);
}
TEST(AUTOVETORES, N3) {
matrix m({3, 3}, {2, 0, 0, 0, 3, 4, 0, 4, 9});
// talvez trocar para um vector
std::vector<matrix> r1 = {matrix({3, 1}, {0, -2, 1}), matrix({3, 1}, {1, 0, 0}), matrix({3, 1}, {0, 0.5, 1})};
std::vector<matrix> a = m.autovetores();
// comparacao independete da ordem
bool e = r1.size() == a.size() && std::all_of(r1.begin(), r1.end(), [&](const matrix &m) {
return std::find(a.begin(), a.end(), m) != a.end();
});
ASSERT_TRUE(e);
}