1 /* 2 * Copyright (c) 2007 John Weaver 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 #if !defined(_MATRIX_TEST_H_) 20 #define _MATRIX_TEST_H_ 21 22 #include "matrix.h" 23 #include <iostream> 24 25 template <class T> 26 bool operator == (const Matrix <T> & a, const Matrix <T> & b) 27 { 28 if (a.rows () != b.rows () || a.columns () != b.columns () ) { 29 return false; 30 } 31 32 for (unsigned int row = 0; row < a.rows (); ++row) { 33 for (unsigned int col = 0; col < a.columns (); ++col) { 34 if (a (row, col) != b (row, col) ) { 35 return false; 36 } 37 } 38 } 39 40 return true; 41 } 42 43 44 45 template <class T> 46 bool operator != (const Matrix <T> & a, const Matrix <T> & b) 47 { 48 return ! (a == b); 49 } 50 51 52 53 template <class T> 54 std::ostream & operator << (std::ostream & os, const Matrix <T> & m) 55 { 56 const std::string indent (" "); 57 os << "Matrix (" << & m << ") of " << m.rows () << "x" << m.columns () << std::endl; 58 for (unsigned int row = 0; row < m.rows (); ++row) { 59 os << indent; 60 for (unsigned int col = 0; col < m.columns (); ++col) { 61 os << std::setw (4) << std::setfill (' ') << m (row, col) << " "; 62 } 63 os << std::endl; 64 } 65 66 return os; 67 } 68 69 #endif /* !defined(_MATRIX_TEST_H_) */ 70 71