25 #ifndef WMATRIXSYM_TEST_H
26 #define WMATRIXSYM_TEST_H
32 #include <cxxtest/TestSuite.h>
33 #include <cxxtest/ValueTraits.h>
35 #include "../../exceptions/WOutOfBounds.h"
36 #include "../../test/WTraitsBase.h"
37 #include "../WMatrixSym.h"
39 #ifdef CXXTEST_RUNNING
42 CXXTEST_TEMPLATE_INSTANTIATION
57 std::stringstream tmp;
59 for(
size_t row = 0; row < m.
size(); row++ )
61 for(
size_t col = row + 1; col < m.
size(); col++ )
63 tmp << m( row, col ) <<
" ";
70 #endif // CXXTEST_RUNNING
84 TS_ASSERT_EQUALS( t.
m_data.size(), 3 );
94 double mydata[] = { 1.6, 0.2, 7.7 };
95 std::vector< double > data( mydata, mydata +
sizeof( mydata ) /
sizeof(
double ) );
97 TS_ASSERT_EQUALS( t( 1, 2 ), 7.7 );
98 TS_ASSERT_EQUALS( t( 2, 1 ), 7.7 );
109 double mydata[] = { 1.6, 0.2, 7.7 };
110 std::vector< double > data( mydata, mydata +
sizeof( mydata ) /
sizeof(
double ) );
111 TS_ASSERT_THROWS_EQUALS( t.
setData( data ),
WOutOfBounds &e, std::string( e.
what() ),
"Data vector length: 3 doesn't fit to number of rows and cols: 4" );
120 TS_ASSERT_THROWS_EQUALS( t( 0, 0 ),
WOutOfBounds &e, std::string( e.
what() ),
121 "Invalid Element Access ( 0, 0 ). No diagonal elements or indices bigger than 4 are allowed." );
130 double mydata[] = { 1.6, 0.2, 1/3.0 };
131 std::vector< double > data( mydata, mydata +
sizeof( mydata ) /
sizeof(
double ) );
133 std::string expected =
"0.000000000 1.600000000 0.200000000\n1.600000000 0.000000000 0.333333333\n0.200000000 0.333333333 0.000000000";
134 TS_ASSERT_EQUALS( expected, t.
toString() );
143 double mydata[] = { 1.6, 0.2, 1/3.0 };
144 std::vector< double > data( mydata, mydata +
sizeof( mydata ) /
sizeof(
double ) );
146 std::string expected =
"0.00 1.60 0.20\n1.60 0.00 0.33\n0.20 0.33 0.00";
147 std::stringstream ss;
148 ss << std::setprecision( 2 ) << std::fixed;
150 TS_ASSERT_EQUALS( expected, ss.str() );
159 double mydata[] = { 1.6, 0.2, 0.3 };
160 std::vector< double > data( mydata, mydata +
sizeof( mydata ) /
sizeof(
double ) );
162 std::stringstream ss(
"0.0 1.6 0.2\n1.6 0.0 0.3\n0.2 0.3 0.0" );
165 TS_ASSERT_EQUALS( expected, actual );
169 #endif // WMATRIXSYM_TEST_H
void testOperatorOn3x3Matrix(void)
Only the Elements of the upper/lower sym.
void testOutputStream(void)
There should be an output operator for symmetric matrices.
Unit test this LookUp table class.
void testInvalidAccessOnMainDiagonal(void)
Accessing diagonal elements is forbidden and an exception should be thrown.
void testSetDataWithInvalidLengthForDimension(void)
If new elements are set via the setData() method then it has to be checked if the dimension is valid ...
Symmetric square matrix, storing only the elements of the triangular matrix without the main diagonal...
std::vector< T > m_data
Internal data structure to store the elements.
Indicates invalid element access of a container.
void testToString(void)
Renders the matrix to a string, where each row is in a separate line.
void setData(const std::vector< T > &data)
Resets the internal data to the given vector of elements.
virtual const char * what() const
Returns the message string set on throw.
std::string toString(void) const
Renders the matrix to a full nxn matrix, where the main diagonal is set to 0.0 and the m(i...
void testInputStream(void)
There should be an input operator for symmetric matrices, reading data into a given matrix...
Base class to all custom Value Traits for CxxTest.
void testAccessOn3x3Matrix(void)
Access to elements on main diagonal is forbidden.
size_t size() const
Returns the number of rows and cols of the matrix.