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
|
/* ----------------------------------------------------------------------------
* matrixtest.cpp
*
* Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
* See file LICENSE for more details
* ----------------------------------------------------------------------------
*/
#include "Math/math.hpp"
#include "testbench.hpp"
void test(TestBench &tb, const std::string &test_name, bool result)
{
tb.startTest(test_name);
tb.endTest(result);
if(!result)
{
throw std::runtime_error(test_name+" failed...");
}
}
bool matrixAssign()
{
yage::Matrix<4, 5, int> m;
m[2][3]=5;
return m[2][3]==5;
}
bool matrixAddition()
{
yage::Matrix<4, 4, int> m1, m2;
m1[1][1]=293;
m2[1][1]=583;
yage::Matrix<4, 4, int> m3=m1+m2;
std::cout<<m3<<'\n';
return m3[1][1]==876;
}
bool vectorDotProduct()
{
yage::Vector<3, int> v1, v2;
v1[0] = 2;
v1[1] = 3;
v1[2] = 5;
v2[0] = 9;
v2[1] = 6;
v2[2] = 8;
int x = yage::matrix::dot(v1, v2);
return x==76;
}
bool matrixMultiplication()
{
}
int main()
{
TestBench tb;
bool all_passed=true;
try{ test(tb, "Matrix Assign", matrixAssign()); }
catch(std::exception e) { std::cout<<e.what()<<'\n'; }
try{ test(tb, "Matrix Addition", matrixAddition()); }
catch(std::exception e) { std::cout<<e.what()<<'\n'; }
try{ test(tb, "Vector Dot Product", vectorDotProduct()); }
catch(std::string e) { std::cout<<e<<'\n'; }
tb.printResults();
return all_passed;
}
|