-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix_tests.cpp
executable file
·75 lines (66 loc) · 1.48 KB
/
matrix_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
#include "Matrix.h"
#include <iostream>
using std::cout;
// True if test passes, False otherwise
// mat is matrix to test, sol is the correct solution
// Outputs information on test to std::cout
bool test(const vector< vector<double> > &mat, const vector<double> &sol, int test_num) {
cout << "Test" + test_num + ": ";
Matrix test_mat = Matrix(mat);
vector<double> output = test_mat.solve();
if(output != sol) {
cout << "FAILED\n{";
for(int i = 0; i < output.size(); ++i) {
cout << output.at(i);
if(i != output.size() - 1)
cout << ", ";
}
cout << "} !=\n{"
for(int i = 0; i < sol.size(); ++i) {
cout << sol.at(i);
if(i != sol.size() - 1)
cout << ", ";
}
cout << "}\n";
return false;
}
else {
cout << "PASSED\n";
return true;
}
}
int main(int argc, char* argv[]) {
cout << "Beginning Matrix Solver Tests\n";
cout << "=============================\n";
// Test 1
vector< vector<double> > m1 {
{1, 2, 3, 0},
{4, 5, 6, 0},
{7, 8, 9, 0}
};
vector<double> s1 {0, 0, 0};
test(m1, s1, 1);
// Test 2
vector< vector<double> > m2 {
{1, 1, 1},
{2, -1, 5},
{3, 4, 2}
};
vector<double> s2 {2, -1};
test(m2, s2, 2);
// Test 3
vector< vector<double> > m3 {
{1, 2, 4, -8},
{4, 5, 6, -1},
{7, 8, 9, 2},
{5, 3, 1, 15},
};
vector<double> s3 {2, -1};
test(m3, s3, 2);
// Test 4
vector< vector<double> > m4 {
{1, 1}
};
vector<double> s4 {1};
test(m4, s4, 4);
}