Commit b8b1b5f2fce7505fc46e8b4b5757c9bfde329f85

Authored by Stefan Eschbach
1 parent 23d56fb3

Bug Fix + adding of unit tests for new operators.

include/GMatrix.hpp
... ... @@ -256,7 +256,7 @@ GMatrix GMatrix::operator-(const GMatrix& matrix) const
256 256 * the value of scalar. The method makes use of the unary subtraction operator.
257 257 ***************************************************************************/
258 258 inline
259   -GMatrix GMatrix::operator+(const double& scalar) const
  259 +GMatrix GMatrix::operator-(const double& scalar) const
260 260 {
261 261 GMatrix result = *this;
262 262 result -= scalar;
... ...
src/linalg/GMatrix.cpp
... ... @@ -420,7 +420,7 @@ GMatrix& GMatrix::operator-=(const GMatrix& matrix)
420 420 *
421 421 * This method subtracts a given scalar from each matrix element.
422 422 ***************************************************************************/
423   -GMatrix& GMatrix::operator+=(const double& scalar)
  423 +GMatrix& GMatrix::operator-=(const double& scalar)
424 424 {
425 425 // Add all matrix elements
426 426 double* dst = m_data;
... ...
test/test_GMatrix.cpp
... ... @@ -532,7 +532,34 @@ void TestGMatrix::matrix_arithmetics(void)
532 532 test_assert(check_matrix(m_test), "Test source matrix");
533 533 test_assert(check_matrix(test, 1.0/3.0, 0.0), "Test GMatrix / 3.0",
534 534 "Unexpected result matrix:\n"+test.print());
  535 +
  536 + // GMatrix + 3.0
  537 + test = m_test + 3.0;
  538 + test_assert(check_matrix(m_test), "Test source matrix");
  539 + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrix + 3.0",
  540 + "Unexpected result matrix:\n"+test.print());
  541 +
  542 + // GMatrix += 3.0
  543 + test = m_test;
  544 + test += 3.0;
  545 + test_assert(check_matrix(m_test), "Test source matrix");
  546 + test_assert(check_matrix(test, 1.0, 3.0), "Test GMatrix + 3.0",
  547 + "Unexpected result matrix:\n"+test.print());
  548 +
  549 + // GMatrix - 5.0
  550 + test = m_test - 5.0;
  551 + test_assert(check_matrix(m_test), "Test source matrix");
  552 + test_assert(check_matrix(test, 1.0, -5.0), "Test GMatrix -= 5.0",
  553 + "Unexpected result matrix:\n"+test.print());
  554 +
  555 + // GMatrix -= 3.0
  556 + test = m_test;
  557 + test -= 3.0;
  558 + test_assert(check_matrix(m_test), "Test source matrix");
  559 + test_assert(check_matrix(test, 1.0, -3.0), "Test GMatrix -= 3.0",
  560 + "Unexpected result matrix:\n"+test.print());
535 561  
  562 +
536 563 // Test invalid matrix addition
537 564 test_try("Test invalid matrix addition");
538 565 try {
... ...