|
|
|
@ -17,7 +17,7 @@ class TemplateMatrixTest: public CppUnit::TestFixture { |
|
|
|
|
public: |
|
|
|
|
template<typename T> |
|
|
|
|
void initFromArray1() { |
|
|
|
|
Matrix<T,2,4> m {1, 2, 3, 4, |
|
|
|
|
const Matrix<T,2,4> m {1, 2, 3, 4, |
|
|
|
|
5, 6, 7, 8}; |
|
|
|
|
CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]); |
|
|
|
@ -30,7 +30,7 @@ class TemplateMatrixTest: public CppUnit::TestFixture { |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void initFromArray2() { |
|
|
|
|
Matrix<T,2,4> m(1, 2, 3, 4, |
|
|
|
|
const Matrix<T,2,4> m(1, 2, 3, 4, |
|
|
|
|
5, 6, 7, 8); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]); |
|
|
|
@ -43,7 +43,7 @@ class TemplateMatrixTest: public CppUnit::TestFixture { |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void initFromArray3() { |
|
|
|
|
Matrix<T,2,4> m({1, 2, 3, 4, |
|
|
|
|
const Matrix<T,2,4> m({1, 2, 3, 4, |
|
|
|
|
5, 6, 7, 8}); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL((T)1, m[0][0]); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL((T)2, m[0][1]); |
|
|
|
@ -81,7 +81,7 @@ class TemplateMatrixTest: public CppUnit::TestFixture { |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void initFromDefault() { |
|
|
|
|
Matrix<T,2,2> m; |
|
|
|
|
const Matrix<T,2,2> m; |
|
|
|
|
CPPUNIT_ASSERT_EQUAL((T)0, m[0][0]); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL((T)0, m[0][1]); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL((T)0, m[1][0]); |
|
|
|
@ -105,9 +105,69 @@ class TemplateMatrixTest: public CppUnit::TestFixture { |
|
|
|
|
5, 6, 7, 9); |
|
|
|
|
Matrix<T,2,4> m4(9, 2, 3, 4, |
|
|
|
|
5, 6, 7, 8); |
|
|
|
|
Matrix<T,2,4> m5(1, 2, 0, 4, |
|
|
|
|
5, 6, 7, 8); |
|
|
|
|
CPPUNIT_ASSERT(m1==m2); |
|
|
|
|
CPPUNIT_ASSERT(m1!=m3); |
|
|
|
|
CPPUNIT_ASSERT(m1!=m4); |
|
|
|
|
CPPUNIT_ASSERT(m1!=m5); |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void operator_plus() { |
|
|
|
|
const Matrix<T,2,4> m1(1, 2, 3, 4, |
|
|
|
|
5, 6, 7, 8); |
|
|
|
|
const Matrix<T,2,4> m2(2, 4, 6, 8, |
|
|
|
|
1, 3, 5, 7); |
|
|
|
|
const Matrix<T,2,4> m(m1+m2); |
|
|
|
|
const Matrix<T,2,4> res(3, 6, 9, 12, |
|
|
|
|
6, 9, 12, 15); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(res, m); |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void operator_minus() { |
|
|
|
|
const Matrix<T,2,4> m1(1, 2, 3, 4, |
|
|
|
|
5, 6, 7, 8); |
|
|
|
|
const Matrix<T,2,4> m2(2, 4, 6, 8, |
|
|
|
|
1, 3, 5, 7); |
|
|
|
|
const Matrix<T,2,4> m(m1-m2); |
|
|
|
|
const Matrix<T,2,4> res(-1, -2, -3, -4, |
|
|
|
|
4, 3, 2, 1); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(res, m); |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void scalar_mult() { |
|
|
|
|
const Matrix<T,2,4> m1(1, 2, 3, 4, |
|
|
|
|
5, 6, 7, 8); |
|
|
|
|
T two(2), three(3), four(4), big(32); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(m1*two, m1+m1); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(m1*three, m1+m1+m1); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(m1*four, m1+m1+m1+m1); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(two*m1, m1*two); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(three*m1, m1*three); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(four*m1, m1*four); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(two*m1*two, m1*four); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(big*m1*four, m1*four*big); |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void matrix_mult() { |
|
|
|
|
const Matrix<T,2,3> m1(1, 2, 3, |
|
|
|
|
4, 5, 6); |
|
|
|
|
const Matrix<T,3,4> m2(1, 4, 7, 10, |
|
|
|
|
2, 5, 8, 11, |
|
|
|
|
3, 6, 9, 12); |
|
|
|
|
const Matrix<T,2,4> m(m1*m2); |
|
|
|
|
const Matrix<T,2,4> res(14, 32, 50, 68, |
|
|
|
|
32, 77, 122, 167); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(res, m); |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void transpose() { |
|
|
|
|
const Matrix<T,2,3> m(1, 2, 3, |
|
|
|
|
4, 5, 6); |
|
|
|
|
const Matrix<T,3,2> res(1, 4, |
|
|
|
|
2, 5, |
|
|
|
|
3, 6); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(res, m.t()); |
|
|
|
|
} |
|
|
|
|
CPPUNIT_TEST_SUITE(TemplateMatrixTest); |
|
|
|
|
CPPUNIT_TEST(initFromArray1<int>); |
|
|
|
@ -146,6 +206,36 @@ class TemplateMatrixTest: public CppUnit::TestFixture { |
|
|
|
|
CPPUNIT_TEST(equality<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(equality<float>); |
|
|
|
|
CPPUNIT_TEST(equality<double>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<int>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<long>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<unsigned>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<float>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<double>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<int>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<long>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<unsigned>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<float>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<double>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<int>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<long>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<unsigned>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<float>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<double>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<int>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<long>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<unsigned>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<float>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<double>); |
|
|
|
|
CPPUNIT_TEST(transpose<int>); |
|
|
|
|
CPPUNIT_TEST(transpose<long>); |
|
|
|
|
CPPUNIT_TEST(transpose<unsigned>); |
|
|
|
|
CPPUNIT_TEST(transpose<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(transpose<float>); |
|
|
|
|
CPPUNIT_TEST(transpose<double>); |
|
|
|
|
CPPUNIT_TEST_SUITE_END(); |
|
|
|
|
}; |
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(TemplateMatrixTest); |
|
|
|
@ -241,6 +331,75 @@ class VariableMatrixTest: public CppUnit::TestFixture { |
|
|
|
|
CPPUNIT_ASSERT(m1!=m3); |
|
|
|
|
CPPUNIT_ASSERT(m1!=m4); |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void operator_plus() { |
|
|
|
|
const Matrix<T> m1(2, 4, |
|
|
|
|
1, 2, 3, 4, |
|
|
|
|
5, 6, 7, 8); |
|
|
|
|
const Matrix<T> m2(2, 4, |
|
|
|
|
2, 4, 6, 8, |
|
|
|
|
1, 3, 5, 7); |
|
|
|
|
const Matrix<T> m(m1+m2); |
|
|
|
|
const Matrix<T> res(2, 4, |
|
|
|
|
3, 6, 9, 12, |
|
|
|
|
6, 9, 12, 15); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(res, m); |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void operator_minus() { |
|
|
|
|
const Matrix<T> m1(2, 4, |
|
|
|
|
1, 2, 3, 4, |
|
|
|
|
5, 6, 7, 8); |
|
|
|
|
const Matrix<T> m2(2, 4, |
|
|
|
|
2, 4, 6, 8, |
|
|
|
|
1, 3, 5, 7); |
|
|
|
|
const Matrix<T> m(m1-m2); |
|
|
|
|
const Matrix<T> res(2, 4, |
|
|
|
|
-1, -2, -3, -4, |
|
|
|
|
4, 3, 2, 1); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(res, m); |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void scalar_mult() { |
|
|
|
|
const Matrix<T> m1(2, 4, |
|
|
|
|
1, 2, 3, 4, |
|
|
|
|
5, 6, 7, 8); |
|
|
|
|
T two(2), three(3), four(4), big(32); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(m1*two, m1+m1); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(m1*three, m1+m1+m1); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(m1*four, m1+m1+m1+m1); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(two*m1, m1*two); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(three*m1, m1*three); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(four*m1, m1*four); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(two*m1*two, m1*four); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(big*m1*four, m1*four*big); |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void matrix_mult() { |
|
|
|
|
const Matrix<T> m1(2, 3, |
|
|
|
|
1, 2, 3, |
|
|
|
|
4, 5, 6); |
|
|
|
|
const Matrix<T> m2(3, 4, |
|
|
|
|
1, 4, 7, 10, |
|
|
|
|
2, 5, 8, 11, |
|
|
|
|
3, 6, 9, 12); |
|
|
|
|
const Matrix<T> m(m1*m2); |
|
|
|
|
const Matrix<T> res(2, 4, |
|
|
|
|
14, 32, 50, 68, |
|
|
|
|
32, 77, 122, 167); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(res, m); |
|
|
|
|
} |
|
|
|
|
template<typename T> |
|
|
|
|
void transpose() { |
|
|
|
|
const Matrix<T> m(2, 3, |
|
|
|
|
1, 2, 3, |
|
|
|
|
4, 5, 6); |
|
|
|
|
const Matrix<T> res(3, 2, |
|
|
|
|
1, 4, |
|
|
|
|
2, 5, |
|
|
|
|
3, 6); |
|
|
|
|
CPPUNIT_ASSERT_EQUAL(res, m.t()); |
|
|
|
|
} |
|
|
|
|
CPPUNIT_TEST_SUITE(VariableMatrixTest); |
|
|
|
|
CPPUNIT_TEST(initFromArray1<int>); |
|
|
|
|
CPPUNIT_TEST(initFromArray1<long>); |
|
|
|
@ -272,6 +431,42 @@ class VariableMatrixTest: public CppUnit::TestFixture { |
|
|
|
|
CPPUNIT_TEST(equality<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(equality<float>); |
|
|
|
|
CPPUNIT_TEST(equality<double>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<int>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<long>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<unsigned>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<float>); |
|
|
|
|
CPPUNIT_TEST(operator_plus<double>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<int>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<long>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<unsigned>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<float>); |
|
|
|
|
CPPUNIT_TEST(operator_minus<double>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<int>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<long>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<unsigned>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<float>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<double>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<int>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<long>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<unsigned>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<float>); |
|
|
|
|
CPPUNIT_TEST(scalar_mult<double>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<int>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<long>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<unsigned>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<float>); |
|
|
|
|
CPPUNIT_TEST(matrix_mult<double>); |
|
|
|
|
CPPUNIT_TEST(transpose<int>); |
|
|
|
|
CPPUNIT_TEST(transpose<long>); |
|
|
|
|
CPPUNIT_TEST(transpose<unsigned>); |
|
|
|
|
CPPUNIT_TEST(transpose<unsigned long>); |
|
|
|
|
CPPUNIT_TEST(transpose<float>); |
|
|
|
|
CPPUNIT_TEST(transpose<double>); |
|
|
|
|
CPPUNIT_TEST_SUITE_END(); |
|
|
|
|
}; |
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(VariableMatrixTest); |
|
|
|
|