-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.cpp
106 lines (66 loc) · 1.91 KB
/
tests.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
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <exception>
#include <limits>
#include <stdexcept>
#include <vector>
#include <cstdlib>
#include "Descomposition/TestDescomposition.h"
#include "Descomposition/MatrixDescomposition.h"
#include <gtest/gtest.h>
#include "Matrix/Matrix.hpp"
using namespace std;
using namespace anpi;
//+++Test cases+++
//testLU
TEST(testLU, NormError) {
Matrix<double> LU;
Matrix<double> M = {{4,5,7},{1,2,4},{1,1,3}};
MatrixDescomposition<double> * d = new MatrixDescomposition<double>();
TestDescomposition<double> * test = new TestDescomposition<double>();
d->lu(M,LU);
double norm = test->testLU(M,LU);
ASSERT_EQ(norm , 0);
}
//testQR
TEST(testQR, NormError) {
Matrix<double> Q;
Matrix<double> R;
Matrix<double> M = {{4,5,7},{1,2,4},{1,1,3}};
MatrixDescomposition<double> * d = new MatrixDescomposition<double>();
TestDescomposition<double> * test = new TestDescomposition<double>();
d->qr(M,Q,R);
double norm = test->testQR(M,Q,R);
ASSERT_EQ(norm , 0);
}
//testInvert (Must be passed)
TEST(testInvert, NoThrow) {
Matrix<double> M = {{4,5,7},{1,2,4},{1,1,3}};
Matrix<double> Mi;
MatrixDescomposition<double> * d = new MatrixDescomposition<double>();
ASSERT_NO_THROW(d->inverse(M,Mi));
}
//testInvert (Must fail)
TEST(testInvert, Throw) {
Matrix<double> M = {{0,0,0}, //Normal 1
{0,0,0},
{0,0,0}};
Matrix<double> Mi;
MatrixDescomposition<double> * d = new MatrixDescomposition<double>();
ASSERT_ANY_THROW(d->inverse(M,Mi));
}
//testMultiplication (Must be passed)
TEST(Multiplication, NoThrow) {
Matrix<double> M = {{4,5,7},{1,2,4},{1,1,3}}; ;
ASSERT_NO_THROW(M*M);
}
//testMultiplication (Must fail)
TEST(Multiplication, Throw) {
Matrix<double> M = {{4,5,7},{1,2,4},{1,1,3}}; ;
Matrix<double> M2 = {{1,1},
{1,2}};
ASSERT_ANY_THROW(M*M2);
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}