aboutsummaryrefslogtreecommitdiffstats
path: root/test/matrixtest.cpp
blob: 50a0b29c7af157f0460283cde6c90f79b7ababaa (plain)
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
/* ------------------------------------------------------------------------------
 * MIT License
 *
 * Copyright (c) 2017 Yann Herklotz Grave
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 * ------------------------------------------------------------------------------
 * Description: 
 *
 * Tests the math class using different tests to see if matrix operations work 
 * correctly.
 * ------------------------------------------------------------------------------
 */

#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;
}