C++program

profileKingfrog
MatrixStarterCode.zip

Matrix/CMakeLists.txt

cmake_minimum_required(VERSION 3.14) project(MatrixBuilder LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) add_subdirectory(src) add_subdirectory(testing)

Matrix/Makefile

#exe = exename #to be set on the command line build_dir = build all: cmake -E remove_directory $(build_dir) cmake -E make_directory $(build_dir) cmake -S . -B $(build_dir) cmake --build $(build_dir) --clean-first cmake -E copy $(build_dir)/$(exe) . cmake -E remove_directory $(build_dir)

Matrix/src/CMakeLists.txt

cmake_minimum_required(VERSION 3.14) project(Matrix LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) add_subdirectory(Matrix) add_subdirectory(Vector)

Matrix/src/Matrix/CMakeLists.txt

cmake_minimum_required(VERSION 3.14) project(MatrixMatrix LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) add_library(MatrixMatrix STATIC Matrix.cpp Matrix.h RowIterator.cpp RowIterator.h ConstRowIterator.cpp ConstRowIterator.h ColumnIterator.cpp ColumnIterator.h ConstColumnIterator.cpp ConstColumnIterator.h ) target_include_directories(MatrixMatrix PUBLIC .) target_link_libraries(MatrixMatrix PUBLIC MatrixVector) target_compile_options(MatrixMatrix PRIVATE -Wall -Wextra -Werror)

Matrix/src/Matrix/ColumnIterator.cpp

Matrix/src/Matrix/ColumnIterator.cpp

//
// Created by mfbut on 11/17/2019.
//

#include   "ColumnIterator.h"
#include   "ConstColumnIterator.h"
#include   "Matrix.h"

Matrix :: ColumnIterator :: ColumnIterator ( Matrix *  matrix ,   int  col )   {

}

Matrix :: ColumnIterator :: operator   ConstColumnIterator ()   const   {
}

Matrix :: ConstVectorRef   Matrix :: ColumnIterator :: operator * ()   const   {
   return   const_cast < const   Matrix *> ( matrix ) -> colAt ( col );
}

Matrix :: ColumnIterator :: value_type  Matrix :: ColumnIterator :: operator * ()   {
}



Matrix :: ConstVectorRef    Matrix :: ColumnIterator :: operator []( int  offset )   const   {
   return   const_cast < const   Matrix *> ( matrix ) -> colAt ( col  +  offset );
}

Matrix :: ColumnIterator :: value_type  Matrix :: ColumnIterator :: operator []( int  offset )   {
}

Matrix :: ColumnIterator &   Matrix :: ColumnIterator :: operator ++ ()   {
}

const   Matrix :: ColumnIterator   Matrix :: ColumnIterator :: operator ++ ( int )   {
}

Matrix :: ColumnIterator &   Matrix :: ColumnIterator :: operator -- ()   {
}

const   Matrix :: ColumnIterator   Matrix :: ColumnIterator :: operator -- ( int )   {
}

Matrix :: ColumnIterator &   Matrix :: ColumnIterator :: operator += ( int  amount )   {
}

Matrix :: ColumnIterator   Matrix :: ColumnIterator :: operator + ( int  amount )   const   {
}

Matrix :: ColumnIterator &   Matrix :: ColumnIterator :: operator -= ( int  amount )   {
}

Matrix :: ColumnIterator   Matrix :: ColumnIterator :: operator - ( int  amount )   const   {
}

Matrix :: ColumnIterator :: difference_type  Matrix :: ColumnIterator :: operator - ( const   ColumnIterator &  rhs )   {
}

bool   Matrix :: ColumnIterator :: operator == ( const   ColumnIterator &  rhs )   const   {
}

bool   Matrix :: ColumnIterator :: operator != ( const   ColumnIterator &  rhs )   const   {
}

bool   Matrix :: ColumnIterator :: operator < ( const   ColumnIterator &  rhs )   const   {
}

bool   Matrix :: ColumnIterator :: operator <= ( const   ColumnIterator &  rhs )   const   {
}

bool   Matrix :: ColumnIterator :: operator > ( const   ColumnIterator &  rhs )   const   {
}

bool   Matrix :: ColumnIterator :: operator >= ( const   ColumnIterator &  rhs )   const   {
}

Matrix/src/Matrix/ColumnIterator.h

// // Created by mfbut on 11/17/2019. // #ifndef ECS_36B_HOMEWORK_COLUMNITERATOR_H #define ECS_36B_HOMEWORK_COLUMNITERATOR_H #include <iterator> #include "ConstVectorRef.h" #include "VectorRef.h" namespace Matrix { class Matrix; class ConstColumnIterator; class ColumnIterator { public: //the iterator type tags using iterator_category = std::random_access_iterator_tag; using value_type = VectorRef; using difference_type = int; using pointer = const value_type*; using reference = const value_type&; //Create an column iterator over the specified matrix starting at the specified column ColumnIterator(Matrix* matrix, int col); ColumnIterator(const ColumnIterator& orig) = default; virtual ~ColumnIterator() = default; //return a ConstColumnIterator that is over the same matrix and at the same position explicit operator ConstColumnIterator() const; //get a reference to the column you are at ConstVectorRef operator* () const; value_type operator*(); //get a reference to a column offset past your current location ConstVectorRef operator[](int offset) const; value_type operator[](int offset); //move to the next column ColumnIterator& operator++(); //pre const ColumnIterator operator++(int); //post //move to the previous column ColumnIterator& operator--(); //pre const ColumnIterator operator--(int); //post //move forward amount columns ColumnIterator& operator+=(int amount); ColumnIterator operator+(int amount) const; //move backward amount columns ColumnIterator& operator-=(int amount); ColumnIterator operator-(int amount) const; //return the number of columns between yourself and rhs //for example if you were at column 10 and rhs was at column 7 //the difference would be 3 difference_type operator-(const ColumnIterator& rhs); //you and rhs are equal if you are over the same matrix and //at the same column bool operator==(const ColumnIterator& rhs) const; bool operator!=(const ColumnIterator& rhs) const; //are you at a column before rhs? bool operator<(const ColumnIterator& rhs) const; bool operator<=(const ColumnIterator& rhs) const; //are you at a column after rhs? bool operator>(const ColumnIterator& rhs) const; bool operator>=(const ColumnIterator& rhs) const; protected: Matrix* matrix; int col; }; } #endif //ECS_36B_HOMEWORK_COLUMNITERATOR_H

Matrix/src/Matrix/ConstColumnIterator.cpp

Matrix/src/Matrix/ConstColumnIterator.cpp

//
// Created by mfbut on 11/17/2019.
//

#include   "ConstColumnIterator.h"
#include   "Matrix.h"

Matrix :: ConstColumnIterator :: ConstColumnIterator ( const   Matrix *  matrix ,   int  col )   {

}


Matrix :: ConstColumnIterator :: value_type  Matrix :: ConstColumnIterator :: operator * ()   const   {
}

Matrix :: ConstColumnIterator :: value_type  Matrix :: ConstColumnIterator :: operator []( int  offset )   const   {
}

Matrix :: ConstColumnIterator &   Matrix :: ConstColumnIterator :: operator ++ ()   {

}

const   Matrix :: ConstColumnIterator   Matrix :: ConstColumnIterator :: operator ++ ( int )   {

}

Matrix :: ConstColumnIterator &   Matrix :: ConstColumnIterator :: operator -- ()   {

}

const   Matrix :: ConstColumnIterator   Matrix :: ConstColumnIterator :: operator -- ( int )   {

}

Matrix :: ConstColumnIterator &   Matrix :: ConstColumnIterator :: operator += ( int  amount )   {

}

Matrix :: ConstColumnIterator   Matrix :: ConstColumnIterator :: operator + ( int  amount )   const   {

}

Matrix :: ConstColumnIterator &   Matrix :: ConstColumnIterator :: operator -= ( int  amount )   {

}

Matrix :: ConstColumnIterator   Matrix :: ConstColumnIterator :: operator - ( int  amount )   const   {

}

Matrix :: ConstColumnIterator :: difference_type  Matrix :: ConstColumnIterator :: operator - ( const   ConstColumnIterator &  rhs )   {
}

bool   Matrix :: ConstColumnIterator :: operator == ( const   ConstColumnIterator &  rhs )   const   {
}

bool   Matrix :: ConstColumnIterator :: operator != ( const   ConstColumnIterator &  rhs )   const   {
}

bool   Matrix :: ConstColumnIterator :: operator < ( const   ConstColumnIterator &  rhs )   const   {
}

bool   Matrix :: ConstColumnIterator :: operator <= ( const   ConstColumnIterator &  rhs )   const   {
}

bool   Matrix :: ConstColumnIterator :: operator > ( const   ConstColumnIterator &  rhs )   const   {
}

bool   Matrix :: ConstColumnIterator :: operator >= ( const   ConstColumnIterator &  rhs )   const   {
}

Matrix/src/Matrix/ConstColumnIterator.h

// // Created by mfbut on 11/17/2019. // #ifndef ECS_36B_HOMEWORK_CONSTCOLUMNITERATOR_H #define ECS_36B_HOMEWORK_CONSTCOLUMNITERATOR_H #include <iterator> #include "ConstVectorRef.h" namespace Matrix { class Matrix; class ConstColumnIterator { public: //the iterator type tags using iterator_category = std::random_access_iterator_tag; using value_type = ConstVectorRef; using difference_type = int; using pointer = const value_type*; using reference = const value_type&; //Create an column iterator over the specified Matrix starting at the specified column ConstColumnIterator(const Matrix* matrix, int col); ConstColumnIterator(const ConstColumnIterator& orig) = default; virtual ~ConstColumnIterator() = default; //return a reference to the column you are at value_type operator* () const; //return a reference to the column offset columns from your current position value_type operator[](int offset) const; //move to the next column ConstColumnIterator& operator++(); //pre const ConstColumnIterator operator++(int); //post //move to the previous column ConstColumnIterator& operator--(); //pre const ConstColumnIterator operator--(int); //post //move forward amount columns ConstColumnIterator& operator+=(int amount); ConstColumnIterator operator+(int amount) const; //move backward amount columns ConstColumnIterator& operator-=(int amount); ConstColumnIterator operator-(int amount) const; //return the number of columns between yourself and rhs //for example if you were at column 10 and rhs was at column 7 //the difference would be 3 difference_type operator-(const ConstColumnIterator& rhs); //you and rhs are equal if you are over the same matrix and //at the same column bool operator==(const ConstColumnIterator& rhs) const; bool operator!=(const ConstColumnIterator& rhs) const; //are you at a column before rhs? bool operator<(const ConstColumnIterator& rhs) const; bool operator<=(const ConstColumnIterator& rhs) const; //are you at a column after rhs? bool operator>(const ConstColumnIterator& rhs) const; bool operator>=(const ConstColumnIterator& rhs) const; protected: }; } #endif //ECS_36B_HOMEWORK_CONSTCOLUMNITERATOR_H

Matrix/src/Matrix/ConstRowIterator.cpp

Matrix/src/Matrix/ConstRowIterator.cpp

//
// Created by mfbut on 11/17/2019.
//


#include   "ConstRowIterator.h"
#include   "Matrix.h"

Matrix :: ConstRowIterator :: ConstRowIterator ( const   Matrix *  matrix ,   int  row )   {

}

Matrix :: ConstRowIterator :: value_type  Matrix :: ConstRowIterator :: operator * ()   const   {

}

Matrix :: ConstRowIterator :: value_type  Matrix :: ConstRowIterator :: operator []( int  offset )   const   {

}

Matrix :: ConstRowIterator &   Matrix :: ConstRowIterator :: operator ++ ()   {

}

const   Matrix :: ConstRowIterator   Matrix :: ConstRowIterator :: operator ++ ( int )   {

}

Matrix :: ConstRowIterator &   Matrix :: ConstRowIterator :: operator -- ()   {

}

const   Matrix :: ConstRowIterator   Matrix :: ConstRowIterator :: operator -- ( int )   {

}

Matrix :: ConstRowIterator &   Matrix :: ConstRowIterator :: operator += ( int  amount )   {

}

Matrix :: ConstRowIterator   Matrix :: ConstRowIterator :: operator + ( int  amount )   const   {

}

Matrix :: ConstRowIterator &   Matrix :: ConstRowIterator :: operator -= ( int  amount )   {

}

Matrix :: ConstRowIterator   Matrix :: ConstRowIterator :: operator - ( int  amount )   const   {

}

Matrix :: ConstRowIterator :: difference_type  Matrix :: ConstRowIterator :: operator - ( const   ConstRowIterator &  rhs )   {

}

bool   Matrix :: ConstRowIterator :: operator == ( const   ConstRowIterator &  rhs )   const   {

}

bool   Matrix :: ConstRowIterator :: operator != ( const   ConstRowIterator &  rhs )   const   {

}

bool   Matrix :: ConstRowIterator :: operator < ( const   ConstRowIterator &  rhs )   const   {

}

bool   Matrix :: ConstRowIterator :: operator <= ( const   ConstRowIterator &  rhs )   const   {

}

bool   Matrix :: ConstRowIterator :: operator > ( const   ConstRowIterator &  rhs )   const   {

}

bool   Matrix :: ConstRowIterator :: operator >= ( const   ConstRowIterator &  rhs )   const   {

}


Matrix/src/Matrix/ConstRowIterator.h

// // Created by mfbut on 11/17/2019. // #ifndef ECS_36B_HOMEWORK_CONSTROWITERATOR_H #define ECS_36B_HOMEWORK_CONSTROWITERATOR_H #include <iterator> #include "ConstVectorRef.h" #include "Matrix.h" namespace Matrix { class Matrix; class ConstRowIterator { public: //the iterator type tags using iterator_category = std::random_access_iterator_tag; using value_type = ConstVectorRef; using difference_type = int; using pointer = const value_type*; using reference = const value_type&; //Create an row iterator over the specified Matrix starting at the specified row ConstRowIterator(const Matrix* matrix, int row); ConstRowIterator(const ConstRowIterator& orig) = default; virtual ~ConstRowIterator() = default; //return a reference to the row you are on value_type operator* () const; //return a reference to the row offset rows past your current position value_type operator[](int offset) const; //move forward one row ConstRowIterator& operator++(); //pre const ConstRowIterator operator++(int); //post //move backward one row ConstRowIterator& operator--(); //pre const ConstRowIterator operator--(int); //post //move forward amount rows ConstRowIterator& operator+=(int amount); ConstRowIterator operator+(int amount) const; //move backward rows ConstRowIterator& operator-=(int amount); ConstRowIterator operator-(int amount) const; //return the number of rows between yourself and rhs //for example if you were at row 10 and rhs was at row 7 //the difference would be 3 difference_type operator-(const ConstRowIterator& rhs); //you are equal to rhs if you are both over the same matrix //and you are on the same row bool operator==(const ConstRowIterator& rhs) const; bool operator!=(const ConstRowIterator& rhs) const; //are you at a row before rhs? bool operator<(const ConstRowIterator& rhs) const; bool operator<=(const ConstRowIterator& rhs) const; //are you at a row after rhs? bool operator>(const ConstRowIterator& rhs) const; bool operator>=(const ConstRowIterator& rhs) const; protected: }; } #endif //ECS_36B_HOMEWORK_CONSTROWITERATOR_H

Matrix/src/Matrix/Matrix.cpp

Matrix/src/Matrix/Matrix.cpp

//
// Created by mfbut on 11/14/2019.
//

#include   < algorithm >
#include   < functional >
#include   "Matrix.h"

Matrix :: Matrix :: Matrix ( int  numRows ,   int  numCols ,   const   Matrix :: Matrix :: element_type &  val )   ){

}

Matrix :: Matrix :: Matrix ( int  numRows ,   int  numCols )   {

}

Matrix :: Matrix :: Matrix ( const  std :: vector < std :: vector < element_type >>&  values )   {

}

Matrix :: Matrix :: Matrix ( const  std :: vector < Vector >&  values )   {

}

Matrix :: Matrix :: Matrix ( const  std :: vector < ConstVectorRef >&  values )   {

}

Matrix :: Matrix :: Matrix ( const  std :: vector < VectorRef >&  values )   {

}

Matrix :: Matrix   Matrix :: Matrix :: ident ( int  dim )   {

}

int   Matrix :: Matrix :: getNumRows ()   const   {

}

int   Matrix :: Matrix :: getNumCols ()   const   {

}

Matrix :: Matrix :: element_type &   Matrix :: Matrix :: at ( int  row ,   int  col )   {

}

const   Matrix :: Matrix :: element_type &   Matrix :: Matrix :: at ( int  row ,   int  col )   const   {

}

Matrix :: VectorRef   Matrix :: Matrix :: rowAt ( int  row )   {

}

  Matrix :: ConstVectorRef   Matrix :: Matrix :: rowAt ( int  row )   const   {

}

Matrix :: VectorRef   Matrix :: Matrix :: colAt ( int  col )   {

}

Matrix :: ConstVectorRef   Matrix :: Matrix :: colAt ( int  col )   const   {

}

Matrix :: VectorRef   Matrix :: Matrix :: operator []( int  row )   {

}

Matrix :: ConstVectorRef   Matrix :: Matrix :: operator []( int  row )   const   {

}

Matrix :: Matrix :: const_iterator  Matrix :: Matrix :: begin ()   const   {

}

Matrix :: Matrix :: const_iterator  Matrix :: Matrix :: end ()   const   {

}

Matrix :: Matrix :: iterator  Matrix :: Matrix :: begin ()   {

}

Matrix :: Matrix :: iterator  Matrix :: Matrix :: end ()   {

}

Matrix :: Matrix :: const_row_iterator  Matrix :: Matrix :: rowBegin ()   const   {

}

Matrix :: Matrix :: const_row_iterator  Matrix :: Matrix :: rowEnd ()   const   {
   ;
}

Matrix :: Matrix :: row_iterator  Matrix :: Matrix :: rowBegin ()   {

}

Matrix :: Matrix :: row_iterator  Matrix :: Matrix :: rowEnd ()   {

}

Matrix :: Matrix :: const_column_iterator  Matrix :: Matrix :: colBegin ()   const   {

}

Matrix :: Matrix :: const_column_iterator  Matrix :: Matrix :: colEnd ()   const   {

}

Matrix :: Matrix :: column_iterator  Matrix :: Matrix :: colBegin ()   {

}

Matrix :: Matrix :: column_iterator  Matrix :: Matrix :: colEnd ()   {

}

Matrix :: Matrix   Matrix :: Matrix :: operator - ()   const {

}

Matrix :: Matrix &   Matrix :: Matrix :: operator += ( const   Matrix &  rhs )   {

}

Matrix :: Matrix   Matrix :: Matrix :: operator + ( const   Matrix &  rhs )   {

}

Matrix :: Matrix &   Matrix :: Matrix :: operator -= ( const   Matrix &  rhs )   {

}

Matrix :: Matrix   Matrix :: Matrix :: operator - ( const   Matrix &  rhs )   {

}

Matrix :: Matrix &   Matrix :: Matrix :: operator *= ( const   Matrix &  rhs )   {

}

Matrix :: Matrix   Matrix :: Matrix :: operator * ( const   Matrix &  rhs )   {

}

Matrix :: Matrix &   Matrix :: Matrix :: operator += ( const  element_type &  rhs )   {

}

Matrix :: Matrix   Matrix :: Matrix :: operator + ( const  element_type &  rhs )   const   {

}

Matrix :: Matrix &   Matrix :: Matrix :: operator -= ( const  element_type &  rhs )   {

}

Matrix :: Matrix   Matrix :: Matrix :: operator - ( const  element_type &  rhs )   const {

}

Matrix :: Matrix &   Matrix :: Matrix :: operator *= ( const  element_type &  rhs )   {

}

Matrix :: Matrix   Matrix :: Matrix :: operator * ( const  element_type &  rhs )   const {

}


Matrix :: Matrix   Matrix :: operator + ( const   Matrix :: element_type &  lhs ,   const   Matrix &  rhs )   {

}

Matrix :: Matrix   Matrix :: operator - ( const   Matrix :: element_type &  lhs ,   const   Matrix &  rhs )   {

}

Matrix :: Matrix   Matrix :: operator * ( const   Matrix :: element_type &  lhs ,   const   Matrix &  rhs )   {

}




Matrix/src/Matrix/Matrix.h

// // Created by mfbut on 11/14/2019. // #ifndef ECS_36B_HOMEWORK_MATRIX_H #define ECS_36B_HOMEWORK_MATRIX_H #include <vector> #include "Vector.h" #include "VectorRef.h" #include "ConstVectorRef.h" namespace Matrix { class RowIterator; class ConstRowIterator; class ColumnIterator; class ConstColumnIterator; class Matrix { public: using element_type = Vector::value_type; using value_type = Vector; using reference = VectorRef; using const_reference = ConstVectorRef; using pointer = value_type*; using const_pointer = const value_type*; using difference_type = int; using row_iterator = RowIterator; using const_row_iterator = ConstRowIterator; using column_iterator = ColumnIterator; using const_column_iterator = ConstColumnIterator; //by default we go through the rows using iterator = row_iterator; using const_iterator = const_row_iterator; Matrix(const Matrix& orig) = default; //create a numRows X numCols Matrix where all of the elements are val Matrix(int numRows, int numCols, const element_type& val); //create a numRows X numCols Matrix where all of the elements are 0 Matrix(int numRows, int numCols); //create a matrix with the specified values explicit Matrix(const std::vector<std::vector<element_type>>& values); explicit Matrix(const std::vector<Vector>& values); explicit Matrix(const std::vector<ConstVectorRef>& values); explicit Matrix(const std::vector<VectorRef>& values); virtual ~Matrix() = default; //return an identity matrix that is dim X dim big //in the identity matrix all of the elements are 0 except for the ones //on the main diagonal //an example 3 X 3 identity matrix //1 0 0 //0 1 0 //0 0 1 static Matrix ident(int dim); //return the number of rows int getNumRows() const; //return the number of columns int getNumCols() const; //element access element_type& at(int row, int col); const element_type& at(int row, int col) const; //get a reference to the specified row VectorRef rowAt(int row); ConstVectorRef rowAt(int row) const; //get a reference to the specified column VectorRef colAt(int col); ConstVectorRef colAt(int col) const; //get a reference to the specified row VectorRef operator[](int row); ConstVectorRef operator[](int row) const; //const iterators. go through the matrix by row const_iterator begin() const; const_iterator end() const; //iterators. go through the matrix by row iterator begin(); iterator end(); //explicit const row iterators const_row_iterator rowBegin() const; const_row_iterator rowEnd() const; //explicit row iterators row_iterator rowBegin(); row_iterator rowEnd(); //explicit const column iterators const_column_iterator colBegin() const; const_column_iterator colEnd() const; //explicit column iterators column_iterator colBegin(); column_iterator colEnd(); //negate Matrix operator-() const; //Matrix + Matrix Matrix& operator+=(const Matrix& rhs); Matrix operator+(const Matrix& rhs); //Matrix - Matrix Matrix& operator-=(const Matrix& rhs); Matrix operator-(const Matrix& rhs); //Matrix * Matrix Matrix& operator*=(const Matrix& rhs); Matrix operator*(const Matrix& rhs); //Matrix + scalar Matrix& operator+=(const element_type& rhs); Matrix operator+(const element_type& rhs) const; //Matrix - scalar Matrix& operator-=(const element_type& rhs); Matrix operator-(const element_type& rhs) const; //Matrix * scalar Matrix& operator*=(const element_type& rhs); Matrix operator*(const element_type& rhs) const; protected: }; //scalar + Matrix Matrix operator+(const Matrix::element_type& lhs, const Matrix& rhs); //scalar - Matrix Matrix operator-(const Matrix::element_type& lhs, const Matrix& rhs); //scalar * Matrix Matrix operator*(const Matrix::element_type& lhs, const Matrix& rhs); } #include "ConstRowIterator.h" #include "RowIterator.h" #include "ConstColumnIterator.h" #include "ColumnIterator.h" #endif //ECS_36B_HOMEWORK_MATRIX_H

Matrix/src/Matrix/RowIterator.cpp

Matrix/src/Matrix/RowIterator.cpp

//
// Created by mfbut on 11/17/2019.
//

#include   "RowIterator.h"
#include   "Matrix.h"

Matrix :: RowIterator :: RowIterator ( Matrix *  matrix ,   int  row )    {

}

Matrix :: RowIterator :: operator   ConstRowIterator ()   const   {

}

Matrix :: ConstVectorRef   Matrix :: RowIterator :: operator * ()   const   {
   //make sure that we call the const at method on matrix
   return   const_cast < const   Matrix *> ( matrix ) -> rowAt ( row );
}

Matrix :: ConstVectorRef   Matrix :: RowIterator :: operator []( int  offset )   const   {
   //make sure that we call the const at method on matrix
   return   const_cast < const   Matrix *> ( matrix ) -> rowAt ( row  +  offset );
}

Matrix :: RowIterator :: value_type  Matrix :: RowIterator :: operator * ()   {

}

Matrix :: RowIterator :: value_type  Matrix :: RowIterator :: operator []( int  offset )   {

}

Matrix :: RowIterator &   Matrix :: RowIterator :: operator ++ ()   {

}

const   Matrix :: RowIterator   Matrix :: RowIterator :: operator ++ ( int )   {

}

Matrix :: RowIterator &   Matrix :: RowIterator :: operator -- ()   {

}

const   Matrix :: RowIterator   Matrix :: RowIterator :: operator -- ( int )   {

}

Matrix :: RowIterator &   Matrix :: RowIterator :: operator += ( int  amount )   {

}

Matrix :: RowIterator   Matrix :: RowIterator :: operator + ( int  amount )   const   {

}

Matrix :: RowIterator &   Matrix :: RowIterator :: operator -= ( int  amount )   {

}

Matrix :: RowIterator   Matrix :: RowIterator :: operator - ( int  amount )   const   {

}

Matrix :: RowIterator :: difference_type  Matrix :: RowIterator :: operator - ( const   RowIterator &  rhs )   {

}

bool   Matrix :: RowIterator :: operator == ( const   RowIterator &  rhs )   const   {

}

bool   Matrix :: RowIterator :: operator != ( const   RowIterator &  rhs )   const   {

}

bool   Matrix :: RowIterator :: operator < ( const   RowIterator &  rhs )   const   {

}

bool   Matrix :: RowIterator :: operator <= ( const   RowIterator &  rhs )   const   {

}

bool   Matrix :: RowIterator :: operator > ( const   RowIterator &  rhs )   const   {

}

bool   Matrix :: RowIterator :: operator >= ( const   RowIterator &  rhs )   const   {

}

Matrix/src/Matrix/RowIterator.h

// // Created by mfbut on 11/17/2019. // #ifndef ECS_36B_HOMEWORK_ROWITERATOR_H #define ECS_36B_HOMEWORK_ROWITERATOR_H #include <iterator> #include "VectorRef.h" #include "ConstVectorRef.h" namespace Matrix { class Matrix; class ConstRowIterator; class RowIterator { public: //the iterator type tags using iterator_category = std::random_access_iterator_tag; using value_type = VectorRef; using difference_type = int; using pointer = const value_type*; using reference = const value_type&; //create a RowIterator over the specified matrix starting at the specified row RowIterator(Matrix* matrix, int row); RowIterator(const RowIterator& orig) = default; virtual ~RowIterator() = default; //return a ConstRowIterator over the same matrix and at the same row explicit operator ConstRowIterator() const; //return a reference to the row that you are on ConstVectorRef operator* () const; value_type operator*(); //return a reference to the row offset past your current row ConstVectorRef operator[](int offset) const; value_type operator[](int offset); //move to the next row RowIterator& operator++(); //pre const RowIterator operator++(int); //post //move to the previous row RowIterator& operator--(); //pre const RowIterator operator--(int); //post //move forward amount rows RowIterator& operator+=(int amount); RowIterator operator+(int amount) const; //move backward amount rows RowIterator& operator-=(int amount); RowIterator operator-(int amount) const; //return the number of rows between yourself and rhs //for example if you were at row 10 and rhs was at row 7 //the difference would be 3 difference_type operator-(const RowIterator& rhs); //you are equal to rhs if you are both over the same matrix //and you are on the same row bool operator==(const RowIterator& rhs) const; bool operator!=(const RowIterator& rhs) const; //are you at a row before rhs? bool operator<(const RowIterator& rhs) const; bool operator<=(const RowIterator& rhs) const; //are you at a row after rhs bool operator>(const RowIterator& rhs) const; bool operator>=(const RowIterator& rhs) const; protected: Matrix* matrix; int row; }; } #endif //ECS_36B_HOMEWORK_ROWITERATOR_H

Matrix/src/Vector/BaseVector.cpp

Matrix/src/Vector/BaseVector.cpp

//
// Created by mfbut on 11/14/2019.
//

#include   < functional >
#include   < algorithm >
#include   "BaseVector.h"
#include   "Vector.h"
#include   "ConstVectorIterator.h"
#include   "VectorIterator.h"
#include   "Matrix.h"

Matrix :: BaseVector :: operator   Matrix ()   const   {

}

Matrix :: VectorIterator   Matrix :: BaseVector :: begin ()   {

}

Matrix :: VectorIterator   Matrix :: BaseVector :: end ()   {

}

Matrix :: ConstVectorIterator   Matrix :: BaseVector :: begin ()   const   {

}

Matrix :: ConstVectorIterator   Matrix :: BaseVector :: end ()   const   {

}

Matrix :: ConstVectorIterator   Matrix :: BaseVector :: cbegin ()   const   {

}

Matrix :: ConstVectorIterator   Matrix :: BaseVector :: cend ()   const   {

}

Matrix :: BaseVector &   Matrix :: BaseVector :: operator += ( const   ConstBaseVector &  rhs )   {

}

Matrix :: BaseVector &   Matrix :: BaseVector :: operator -= ( const   ConstBaseVector &  rhs )   {

}

Matrix :: BaseVector &   Matrix :: BaseVector :: operator += ( const   BaseVector :: value_type &  rhs )   {

}

Matrix :: BaseVector &   Matrix :: BaseVector :: operator -= ( const   BaseVector :: value_type &  rhs )   {

}

Matrix :: BaseVector &   Matrix :: BaseVector :: operator *= ( const   BaseVector :: value_type &  rhs )   {

}












Matrix/src/Vector/BaseVector.h

// // Created by mfbut on 11/14/2019. // #ifndef ECS_36B_HOMEWORK_BASEVECTOR_H #define ECS_36B_HOMEWORK_BASEVECTOR_H #include "ConstBaseVector.h" namespace Matrix { class Vector; class VectorIterator; class ConstVectorIterator; class Matrix; class BaseVector : public virtual ConstBaseVector{ public: //the type tags using value_type = int; using reference = value_type&; using const_reference = const value_type&; using pointer = value_type*; using const_pointer = const value_type*; using difference_type = int; using iterator = VectorIterator; using const_iterator = ConstVectorIterator; virtual ~BaseVector() override = default; //return a 1 X N matrix with the same values as yourself explicit operator Matrix() const; //element access virtual const ConstBaseVector::value_type& at(int index) const override = 0; virtual value_type& at(int index) = 0; virtual const ConstBaseVector::value_type& operator[](int index) const override = 0; virtual value_type& operator[](int index) = 0; //iterators virtual VectorIterator begin(); virtual VectorIterator end(); virtual ConstVectorIterator begin() const override; virtual ConstVectorIterator end() const override; virtual ConstVectorIterator cbegin() const; virtual ConstVectorIterator cend() const; //vector += vector virtual BaseVector& operator+=(const ConstBaseVector& rhs); //vector -= vector virtual BaseVector& operator-=(const ConstBaseVector& rhs); //vector += scalar virtual BaseVector& operator+=(const value_type& rhs); //vector -= scalar virtual BaseVector& operator-=(const value_type& rhs); //vector *= scalar virtual BaseVector& operator*=(const value_type& rhs); }; } #include "ConstVectorIterator.h" #include "VectorIterator.h" #endif //ECS_36B_HOMEWORK_BASEVECTOR_H

Matrix/src/Vector/CMakeLists.txt

cmake_minimum_required(VERSION 3.14) project(MatrixVector LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) add_library(MatrixVector STATIC BaseVector.cpp BaseVector.h Vector.cpp Vector.h VectorIterator.cpp VectorIterator.h ConstVectorIterator.cpp ConstVectorIterator.h VectorRef.cpp VectorRef.h ConstBaseVector.cpp ConstBaseVector.h ConstVectorRef.cpp ConstVectorRef.h) target_include_directories(MatrixVector PUBLIC .) target_link_libraries(MatrixVector PUBLIC MatrixMatrix) target_compile_options(MatrixVector PRIVATE -Wall -Wextra -Werror)

Matrix/src/Vector/ConstBaseVector.cpp

Matrix/src/Vector/ConstBaseVector.cpp

//
// Created by mfbut on 11/17/2019.
//

#include   < algorithm >
#include   "Vector.h"
#include   "ConstBaseVector.h"

Matrix :: ConstVectorIterator   Matrix :: ConstBaseVector :: begin ()   const   {

}

Matrix :: ConstVectorIterator   Matrix :: ConstBaseVector :: end ()   const   {

}

Matrix :: Vector   Matrix :: ConstBaseVector :: operator - ()   const   {

}

Matrix :: Vector   Matrix :: ConstBaseVector :: operator + ( const   ConstBaseVector &  rhs )   {

}

Matrix :: Vector   Matrix :: ConstBaseVector :: operator - ( const   ConstBaseVector &  rhs )   {

}

Matrix :: Vector   Matrix :: ConstBaseVector :: operator * ( const   ConstBaseVector &  rhs )   const   {

}

Matrix :: Vector   Matrix :: ConstBaseVector :: operator + ( const   ConstBaseVector :: value_type &  rhs )   const   {

}

Matrix :: Vector   Matrix :: ConstBaseVector :: operator - ( const   ConstBaseVector :: value_type &  rhs )   const   {

}

Matrix :: Vector   Matrix :: ConstBaseVector :: operator * ( const   ConstBaseVector :: value_type &  rhs )   const   {

}

bool   Matrix :: ConstBaseVector :: operator == ( const   ConstBaseVector &  rhs )   const   {

}

bool   Matrix :: ConstBaseVector :: operator != ( const   ConstBaseVector &  rhs )   const   {

}

Matrix :: Vector   Matrix :: operator + ( const   ConstBaseVector :: value_type &  lhs ,   const   ConstBaseVector &  rhs )   {

}

Matrix :: Vector   Matrix :: operator - ( const   ConstBaseVector :: value_type &  lhs ,   const   ConstBaseVector &  rhs )   {

}

Matrix :: Vector   Matrix :: operator * ( const   ConstBaseVector :: value_type &  lhs ,   const   ConstBaseVector &  rhs )   {

}

Matrix/src/Vector/ConstBaseVector.h

// // Created by mfbut on 11/17/2019. // #ifndef ECS_36B_HOMEWORK_CONSTBASEVECTOR_H #define ECS_36B_HOMEWORK_CONSTBASEVECTOR_H namespace Matrix { class Vector; class ConstVectorIterator; class ConstBaseVector { public: //type tags using value_type = int; using reference = const value_type&; using const_reference = const value_type&; using pointer = const value_type*; using const_pointer = const value_type*; using difference_type = int; using iterator = ConstVectorIterator; using const_iterator = ConstVectorIterator; virtual ~ConstBaseVector() = default; virtual int size() const = 0; //element access virtual const value_type& at(int index) const = 0 ; virtual const value_type& operator[](int index) const = 0; //iterators virtual ConstVectorIterator begin() const; virtual ConstVectorIterator end() const; //negation virtual Vector operator-() const; //vector addition virtual Vector operator+(const ConstBaseVector& rhs); //vector subtraction virtual Vector operator-(const ConstBaseVector& rhs); //vector multiplication i.e. dot product virtual Vector operator*(const ConstBaseVector& rhs) const; //vector + scalar virtual Vector operator+(const value_type& rhs) const; //vector - scalar virtual Vector operator-(const value_type& rhs) const; //vector * scalar virtual Vector operator*(const value_type& rhs) const; //you are the same as rhs if you contain the same elements as rhs bool operator==(const ConstBaseVector& rhs) const; bool operator!=(const ConstBaseVector& rhs) const; }; //scalar + vector Vector operator+(const ConstBaseVector::value_type& lhs, const ConstBaseVector& rhs); //scalar + vector Vector operator-(const ConstBaseVector::value_type& lhs, const ConstBaseVector& rhs); //scalar * vector Vector operator*(const ConstBaseVector::value_type& lhs, const ConstBaseVector& rhs); } #include "ConstVectorIterator.h" #endif //ECS_36B_HOMEWORK_CONSTBASEVECTOR_H

Matrix/src/Vector/ConstVectorIterator.cpp

Matrix/src/Vector/ConstVectorIterator.cpp

//
// Created by mfbut on 11/14/2019.
//

#include   "ConstVectorIterator.h"
#include   "BaseVector.h"

Matrix :: ConstVectorIterator :: ConstVectorIterator ( const   ConstBaseVector *  vector ,   int  pos ){

}

const   Matrix :: ConstVectorIterator :: value_type &   Matrix :: ConstVectorIterator :: operator * ()   const   {

}

const   Matrix :: ConstVectorIterator :: value_type &   Matrix :: ConstVectorIterator :: operator []( int  offset )   const   {

}

Matrix :: ConstVectorIterator &   Matrix :: ConstVectorIterator :: operator ++ ()   {

}

const   Matrix :: ConstVectorIterator   Matrix :: ConstVectorIterator :: operator ++ ( int )   {

}

Matrix :: ConstVectorIterator &   Matrix :: ConstVectorIterator :: operator -- ()   {

}

const   Matrix :: ConstVectorIterator   Matrix :: ConstVectorIterator :: operator -- ( int )   {

}

Matrix :: ConstVectorIterator &   Matrix :: ConstVectorIterator :: operator += ( int  amount )   {

}

Matrix :: ConstVectorIterator   Matrix :: ConstVectorIterator :: operator + ( int  amount )   const   {

}

Matrix :: ConstVectorIterator &   Matrix :: ConstVectorIterator :: operator -= ( int  amount )   {

}

Matrix :: ConstVectorIterator   Matrix :: ConstVectorIterator :: operator - ( int  amount )   const   {

}

Matrix :: ConstVectorIterator :: difference_type  Matrix :: ConstVectorIterator :: operator - ( const   ConstVectorIterator &  rhs )   {

}

bool   Matrix :: ConstVectorIterator :: operator == ( const   ConstVectorIterator &  rhs )   const   {

}

bool   Matrix :: ConstVectorIterator :: operator != ( const   ConstVectorIterator &  rhs )   const   {

}

bool   Matrix :: ConstVectorIterator :: operator < ( const   ConstVectorIterator &  rhs )   const   {

}

bool   Matrix :: ConstVectorIterator :: operator <= ( const   ConstVectorIterator &  rhs )   const   {

}

bool   Matrix :: ConstVectorIterator :: operator > ( const   ConstVectorIterator &  rhs )   const   {

}

bool   Matrix :: ConstVectorIterator :: operator >= ( const   ConstVectorIterator &  rhs )   const   {

}

Matrix/src/Vector/ConstVectorIterator.h

// // Created by mfbut on 11/14/2019. // #ifndef ECS_36B_HOMEWORK_CONSTVECTORITERATOR_H #define ECS_36B_HOMEWORK_CONSTVECTORITERATOR_H #include <iterator> #include "ConstBaseVector.h" namespace Matrix { class ConstBaseVector; class ConstVectorIterator { public: //the iterator type tags using iterator_category = std::random_access_iterator_tag; using value_type = ConstBaseVector::value_type; using difference_type = int; using pointer = const value_type*; using reference = const value_type&; //create a ConstVectorIterator over the specified vector starting at the specified position ConstVectorIterator(const ConstBaseVector* vector, int pos); ConstVectorIterator(const ConstVectorIterator& orig) = default; virtual ~ConstVectorIterator() = default; //return a reference to the element you are at const value_type& operator*() const; //return a reference to the element offset past your current position const value_type& operator[](int offset) const; //move to the next element ConstVectorIterator& operator++(); //pre const ConstVectorIterator operator++(int); //post //move to the previous element ConstVectorIterator& operator--(); //pre const ConstVectorIterator operator--(int); //post //move forward amount elements ConstVectorIterator& operator+=(int amount); ConstVectorIterator operator+(int amount) const; //move backward amount elements ConstVectorIterator& operator-=(int amount); ConstVectorIterator operator-(int amount) const; //return the number of elements between yourself and rhs //for example if you were at element 10 and rhs was at element 7 //the difference would be 3 difference_type operator-(const ConstVectorIterator& rhs); //you are equal to rhs if you are over the same vector //and at the same position bool operator==(const ConstVectorIterator& rhs) const; bool operator!=(const ConstVectorIterator& rhs) const; //are you at an element before rhs? bool operator<(const ConstVectorIterator& rhs) const; bool operator<=(const ConstVectorIterator& rhs) const; //are you at an element after rhs? bool operator>(const ConstVectorIterator& rhs) const; bool operator>=(const ConstVectorIterator& rhs) const; private: }; } #endif //ECS_36B_HOMEWORK_CONSTVECTORITERATOR_H

Matrix/src/Vector/ConstVectorRef.cpp

Matrix/src/Vector/ConstVectorRef.cpp

//
// Created by mfbut on 11/17/2019.
//

#include   "ConstVectorRef.h"
#include   "Matrix.h"

Matrix :: ConstVectorRef :: ConstVectorRef ( const   ConstBaseVector &  orig )    {
  elements . reserve ( orig . size ());
   for ( auto &  element  :  orig ){
     //the const cast here allows us to remove the const from the const int*
     //so that we can place the int* into our vector
     //const_cast can be dangerous if used correctly but
     //can be very helpful when applied correctly
     //please don't use it in your own code until we cover it in class
     //or you read up on it.
    elements . push_back ( const_cast < value_type *> ( & element ));
   }
}

Matrix :: ConstVectorRef :: ConstVectorRef ( const   Matrix &  matrix ,   int  col )   {
  elements . reserve ( matrix . getNumCols ());
   for ( const  auto &  row  :  matrix ){
     //again with the const cast to discard the constness
    elements . push_back ( const_cast < value_type *> ( & row . at ( col )));
   }
}

int   Matrix :: ConstVectorRef :: size ()   const   {

}

const   Matrix :: ConstBaseVector :: value_type &   Matrix :: ConstVectorRef :: at ( int  index )   const   {

}

const   Matrix :: ConstBaseVector :: value_type &   Matrix :: ConstVectorRef :: operator []( int  index )   const   {

}

Matrix/src/Vector/ConstVectorRef.h

// // Created by mfbut on 11/17/2019. // #ifndef ECS_36B_HOMEWORK_CONSTVECTORREF_H #define ECS_36B_HOMEWORK_CONSTVECTORREF_H #include <vector> #include "ConstBaseVector.h" namespace Matrix { class BaseVector; class Matrix; class ConstVectorRef : public virtual ConstBaseVector{ public: virtual ~ConstVectorRef() override = default; explicit ConstVectorRef(const ConstBaseVector& orig); //create a reference over the specified column in the given matrix ConstVectorRef(const Matrix& matrix, int col); //because this is a const reference we cannot change the value //that it refers to so we delete the operator= ConstVectorRef& operator=(ConstBaseVector& rhs) = delete; //return the number of elements in the vector you refer to virtual int size() const override; //return a reference to the element at the position you refer to virtual const value_type& at(int index) const override; virtual const value_type& operator[](int index) const override; protected: std::vector<value_type*> elements; }; } #endif //ECS_36B_HOMEWORK_CONSTVECTORREF_H

Matrix/src/Vector/Vector.cpp

Matrix/src/Vector/Vector.cpp

//
// Created by mfbut on 11/14/2019.
//

#include   "Vector.h"


Matrix :: Vector :: Vector ( const   ConstBaseVector &  orig )    {

}

Matrix :: Vector :: Vector ( int  numElements ,   const   BaseVector :: value_type &   value )   {

}

Matrix :: Vector :: Vector ( int  numElements )   {

}

Matrix :: Vector :: Vector ( const  std :: vector < value_type >&  values )   {

}

Matrix :: Vector :: Vector ()   {

}

int   Matrix :: Vector :: size ()   const   {

}

Matrix :: BaseVector :: value_type &   Matrix :: Vector :: at ( int  index )   {

}

const   Matrix :: BaseVector :: value_type &   Matrix :: Vector :: at ( int  index )   const   {

}

Matrix :: BaseVector :: value_type &   Matrix :: Vector :: operator []( int  index )   {

}

const   Matrix :: BaseVector :: value_type &   Matrix :: Vector :: operator []( int  index )   const   {

}

Matrix :: Vector &   Matrix :: Vector :: operator = ( const   ConstBaseVector &  rhs )   {

}










Matrix/src/Vector/Vector.h

// // Created by mfbut on 11/14/2019. // #ifndef ECS_36B_HOMEWORK_VECTOR_H #define ECS_36B_HOMEWORK_VECTOR_H #include <vector> #include "BaseVector.h" #include "ConstBaseVector.h" namespace Matrix { class Vector : public BaseVector{ public: //create a vector that contains the same elements as in orig explicit Vector(const ConstBaseVector& orig); //create a vector that holds numElements and each element is value Vector(int numElements, const BaseVector::value_type& value); //create a vector that holds numElements 0's explicit Vector(int numElements); //create a vector that contains the specified values explicit Vector(const std::vector<value_type>& values); //create a 1 X 1 vector with the value 0 Vector(); virtual ~Vector() override = default; //make all of the elements in this vector the same //as what is in rhs. adjust the size of this vector if necessary Vector& operator=(const ConstBaseVector& rhs); //return the number of elements in the Vector virtual int size() const override; //return the element at the position virtual value_type& at(int index) override; virtual const value_type& at(int index) const override; virtual value_type& operator[](int index) override; virtual const value_type& operator[](int index) const override; private: }; } #endif //ECS_36B_HOMEWORK_VECTOR_H

Matrix/src/Vector/VectorIterator.cpp

Matrix/src/Vector/VectorIterator.cpp

//
// Created by mfbut on 11/14/2019.
//

#include   "VectorIterator.h"
#include   "ConstColumnIterator.h"

Matrix :: VectorIterator :: VectorIterator ( BaseVector *  vector ,   int  pos )   {}

Matrix :: VectorIterator :: operator   ConstVectorIterator ()   const   {

}

Matrix :: VectorIterator :: value_type &   Matrix :: VectorIterator :: operator * ()   {

}

const   Matrix :: VectorIterator :: value_type &   Matrix :: VectorIterator :: operator * ()   const   {

}

const   Matrix :: VectorIterator :: value_type &   Matrix :: VectorIterator :: operator []( int  offset )   const   {

}

Matrix :: VectorIterator :: value_type &   Matrix :: VectorIterator :: operator []( int  offset )   {

}

Matrix :: VectorIterator &   Matrix :: VectorIterator :: operator ++ ()   {

}

const   Matrix :: VectorIterator   Matrix :: VectorIterator :: operator ++ ( int )   {

}

Matrix :: VectorIterator &   Matrix :: VectorIterator :: operator -- ()   {

}

const   Matrix :: VectorIterator   Matrix :: VectorIterator :: operator -- ( int )   {

}

Matrix :: VectorIterator &   Matrix :: VectorIterator :: operator += ( int  amount )   {

}

Matrix :: VectorIterator   Matrix :: VectorIterator :: operator + ( int  amount )   const   {

}

Matrix :: VectorIterator &   Matrix :: VectorIterator :: operator -= ( int  amount )   {

}

Matrix :: VectorIterator   Matrix :: VectorIterator :: operator - ( int  amount )   const   {

}

Matrix :: VectorIterator :: difference_type  Matrix :: VectorIterator :: operator - ( const   VectorIterator &  rhs )   {

}

bool   Matrix :: VectorIterator :: operator == ( const   VectorIterator &  rhs )   const   {

}

bool   Matrix :: VectorIterator :: operator != ( const   VectorIterator &  rhs )   const   {

}

bool   Matrix :: VectorIterator :: operator < ( const   VectorIterator &  rhs )   const   {


}

bool   Matrix :: VectorIterator :: operator <= ( const   VectorIterator &  rhs )   const   {


}

bool   Matrix :: VectorIterator :: operator > ( const   VectorIterator &  rhs )   const   {


}

bool   Matrix :: VectorIterator :: operator >= ( const   VectorIterator &  rhs )   const   {


}






Matrix/src/Vector/VectorIterator.h

// // Created by mfbut on 11/14/2019. // #ifndef ECS_36B_HOMEWORK_VECTORITERATOR_H #define ECS_36B_HOMEWORK_VECTORITERATOR_H #include <iterator> #include "BaseVector.h" namespace Matrix { class BaseVector; class ConstVectorIterator; class VectorIterator { public: //the iterator type tags using value_type = BaseVector::value_type; using difference_type = int; using pointer = value_type*; using reference = value_type&; using iterator_category = std::random_access_iterator_tag; //create an iterator over the given vector starting at the specified position VectorIterator(BaseVector* vector, int pos); virtual ~VectorIterator() = default; //conversion to a ConstVectorIterator explicit operator ConstVectorIterator() const; //return the element that you are at value_type& operator*(); const value_type& operator*() const; //return the element offset elements away from your current position value_type& operator[](int offset); const value_type& operator[](int offset) const; //go to the next element VectorIterator& operator++(); //pre const VectorIterator operator++(int); //post //go to the previous element VectorIterator& operator--(); //pre const VectorIterator operator--(int); //post //move amount elements forward VectorIterator& operator+=(int amount); VectorIterator operator+(int amount) const; //move amount elements backwards VectorIterator& operator-=(int amount); VectorIterator operator-(int amount) const; //return the number of elements between yourself and rhs //for example if you were at element 10 and rhs was at element 7 //the difference would be 3 difference_type operator-(const VectorIterator& rhs); //true if both this and rhs are over the same vector and at the same element bool operator==(const VectorIterator& rhs) const; bool operator!=(const VectorIterator& rhs) const; //are you at an element before rhs? bool operator<(const VectorIterator& rhs) const; bool operator<=(const VectorIterator& rhs) const; //are you at an element after rhs? bool operator>(const VectorIterator& rhs) const; bool operator>=(const VectorIterator& rhs) const; private: }; } #endif //ECS_36B_HOMEWORK_VECTORITERATOR_H

Matrix/src/Vector/VectorRef.cpp

Matrix/src/Vector/VectorRef.cpp

//
// Created by mfbut on 11/16/2019.
//

#include   "VectorRef.h"
#include   "Matrix.h"

Matrix :: VectorRef :: VectorRef ( BaseVector &  orig )    {
}

Matrix :: VectorRef :: VectorRef ( Matrix &  matrix ,   int  col )    {

}

int   Matrix :: VectorRef :: size ()   const   {

}

Matrix :: BaseVector :: value_type &   Matrix :: VectorRef :: at ( int  index )   {

}

const   Matrix :: BaseVector :: value_type &   Matrix :: VectorRef :: at ( int  index )   const   {

}

Matrix :: BaseVector :: value_type &   Matrix :: VectorRef :: operator []( int  index )   {

}

const   Matrix :: BaseVector :: value_type &   Matrix :: VectorRef :: operator []( int  index )   const   {

}

Matrix :: VectorRef &   Matrix :: VectorRef :: operator = ( const   BaseVector &  rhs )   {

}





Matrix/src/Vector/VectorRef.h

// // Created by mfbut on 11/16/2019. // #ifndef ECS_36B_HOMEWORK_VECTORREF_H #define ECS_36B_HOMEWORK_VECTORREF_H #include <vector> #include "BaseVector.h" #include "ConstVectorRef.h" namespace Matrix { class Matrix; class VectorRef : public ConstVectorRef, public BaseVector { public: //type tags using value_type = BaseVector::value_type; using reference = BaseVector::reference; using const_reference = BaseVector::const_reference; using pointer = BaseVector::pointer; using const_pointer = BaseVector::const_pointer; using difference_type = BaseVector::difference_type; using iterator = BaseVector::iterator; using const_iterator = BaseVector::const_iterator; VectorRef() = delete; virtual ~VectorRef() override = default; //create a reference to the given vector explicit VectorRef(BaseVector& orig); explicit VectorRef(const ConstBaseVector& orig) = delete; // make extra sure this doesn't get created //create a reference over the specified column in the given matrix VectorRef(Matrix& matrix, int col); VectorRef(const Matrix& matrix, int col) = delete; // make extra sure this doesn't get created //set the value of each element that we refer to //equal to the value at the corresponding position in rhs VectorRef& operator=(const BaseVector& rhs); //return the number of elements in the vector it refers to virtual int size() const override; //element access virtual value_type& at(int index) override; virtual const value_type& at(int index) const override; virtual value_type& operator[](int index) override; virtual const value_type& operator[](int index) const override; }; } #endif //ECS_36B_HOMEWORK_VECTORREF_H

Matrix/testing/CMakeLists.txt

cmake_minimum_required(VERSION 3.14) project(MatrixTesting LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) find_package(Threads REQUIRED) include(FetchContent) FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG master ) FetchContent_GetProperties(googletest) if (NOT googletest_POPULATED) FetchContent_Populate(googletest) endif () add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR}) add_subdirectory(Vector) add_subdirectory(Matrix) add_executable(MatrixTester test_main.cpp) target_link_libraries(MatrixTester VectorTesting MatrixTesting)

Matrix/testing/Matrix/CMakeLists.txt

cmake_minimum_required(VERSION 3.14) project(MatrixVectorTesting LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) add_library(MatrixTesting STATIC MatrixTesting.cpp MatrixTesting.h MatrixConstructorTests.cpp MatrixElementAccessTests.cpp MatrixArithmeticOperatorTests.cpp) target_link_libraries(MatrixTesting PUBLIC MatrixMatrix gtest gmock ) target_compile_options(MatrixTesting PRIVATE -Wall -Werror -Wextra) target_include_directories(MatrixTesting PUBLIC .)

Matrix/testing/Matrix/MatrixArithmeticOperatorTests.cpp

Matrix/testing/Matrix/MatrixArithmeticOperatorTests.cpp

//
// Created by mfbut on 11/21/2019.
//

#include   "MatrixTesting.h"
#include   "gmock/gmock.h"
TEST_F ( MatrixTesting ,   MatrixOperatorNegate )   {
   using   namespace   :: testing ;
  answer_type values {{ 10 ,   20 },
                      { 30 ,   40 },
                      { 45 ,   50 },
                      { 100 ,   200 }};
  answer_type answer {{ - 10 ,   - 20 },
                      { - 30 ,   - 40 },
                      { - 45 ,   - 50 },
                      { - 100 ,   - 200 }};

   Matrix :: Matrix  mat1 ( values );
  ASSERT_TRUE ( - mat1  ==  answer );
  ASSERT_TRUE ( mat1  ==  values );
}

TEST_F ( MatrixTesting ,   MatrixPlusEqualMatrix )   {
   using   namespace   :: testing ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  answer_type rhs {{ 100 ,   200 },
                   { 300 ,   400 },
                   { 500 ,   600 },
                   { 700 ,   800 }};
  answer_type answer {{ 110 ,   220 },
                      { 330 ,   440 },
                      { 545 ,   650 },
                      { 800 ,   1000 }};

   Matrix :: Matrix  mat1 ( lhs ),  mat2 ( rhs );
  auto &  ref  =  mat1  +=  mat2 ;
  ASSERT_TRUE ( mat1  ==  answer );
  ASSERT_EQ ( & mat1 ,   & ref );
}

TEST_F ( MatrixTesting ,   MatrixPlusMatrix )   {
   using   namespace   :: testing ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  answer_type rhs {{ 100 ,   200 },
                   { 300 ,   400 },
                   { 500 ,   600 },
                   { 700 ,   800 }};
  answer_type answer {{ 110 ,   220 },
                      { 330 ,   440 },
                      { 545 ,   650 },
                      { 800 ,   1000 }};

   Matrix :: Matrix  mat1 ( lhs ),  mat2 ( rhs );
  auto sum  =  mat1  +  mat2 ;
  ASSERT_TRUE ( sum  ==  answer );
}

TEST_F ( MatrixTesting ,   MatrixMinusEqualMatrix )   {
   using   namespace   :: testing ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  answer_type rhs {{ 100 ,   200 },
                   { 300 ,   400 },
                   { 500 ,   600 },
                   { 700 ,   800 }};
  answer_type answer {{ - 90 ,   - 180 },
                      { - 270 ,   - 360 },
                      { - 455 ,   - 550 },
                      { - 600 ,   - 600 }};

   Matrix :: Matrix  mat1 ( lhs ),  mat2 ( rhs );
  auto &  ref  =  mat1  -=  mat2 ;
  ASSERT_TRUE ( mat1  ==  answer );
  ASSERT_EQ ( & mat1 ,   & ref );
}

TEST_F ( MatrixTesting ,   MatrixMinusMatrix )   {
   using   namespace   :: testing ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  answer_type rhs {{ 100 ,   200 },
                   { 300 ,   400 },
                   { 500 ,   600 },
                   { 700 ,   800 }};
  answer_type answer {{ - 90 ,   - 180 },
                      { - 270 ,   - 360 },
                      { - 455 ,   - 550 },
                      { - 600 ,   - 600 }};

   Matrix :: Matrix  mat1 ( lhs ),  mat2 ( rhs );
  auto diff  =  mat1  -  mat2 ;
  ASSERT_TRUE ( diff  ==  answer );
}

TEST_F ( MatrixTesting ,   MatrixTimesEqualMatrix )   {
   using   namespace   :: testing ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  answer_type rhs {{ 100 ,   200 ,   300 },
                   { 400 ,   500 ,   600 }};

  answer_type answer {{ 9000 ,   12000 ,   15000 },
                      { 19000 ,   26000 ,   33000 },
                      { 24500 ,   34000 ,   43500 },
                      { 90000 ,   120000 ,   150000 }};

   Matrix :: Matrix  mat1 ( lhs ),  mat2 ( rhs );
  auto &  ref  =  mat1  *=  mat2 ;
  ASSERT_TRUE ( mat1  ==  answer );
  ASSERT_EQ ( & mat1 ,   & ref );
}

TEST_F ( MatrixTesting ,   MatrixTimesMatrix )   {
   using   namespace   :: testing ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  answer_type rhs {{ 100 ,   200 ,   300 },
                   { 400 ,   500 ,   600 }};

  answer_type answer {{ 9000 ,   12000 ,   15000 },
                      { 19000 ,   26000 ,   33000 },
                      { 24500 ,   34000 ,   43500 },
                      { 90000 ,   120000 ,   150000 }};

   Matrix :: Matrix  mat1 ( lhs ),  mat2 ( rhs );
  auto prod  =  mat1  *  mat2 ;
  ASSERT_TRUE ( prod  ==  answer );
}

TEST_F ( MatrixTesting ,   MatrixPlusEqualScalar )   {
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  elem_type rhs ( 100 );
  answer_type answer {{ 110 ,   120 },
                      { 130 ,   140 },
                      { 145 ,   150 },
                      { 200 ,   300 }};

   Matrix :: Matrix  mat1 ( lhs );
  auto &  ref  =  mat1  +=  rhs ;
  ASSERT_TRUE ( mat1  ==  answer );
  ASSERT_EQ ( & mat1 ,   & ref );
}

TEST_F ( MatrixTesting ,   MatrixPlusScalar )   {
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  elem_type rhs ( 100 );
  answer_type answer {{ 110 ,   120 },
                      { 130 ,   140 },
                      { 145 ,   150 },
                      { 200 ,   300 }};

   Matrix :: Matrix  mat1 ( lhs );
  auto sum  =  mat1  +  rhs ;
  ASSERT_TRUE ( sum  ==  answer );
}

TEST_F ( MatrixTesting ,   MatrixMinusEqualScalar )   {
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  elem_type rhs ( 10 );
  answer_type answer {{ 0 ,   10 },
                      { 20 ,   30 },
                      { 35 ,   40 },
                      { 90 ,   190 }};

   Matrix :: Matrix  mat1 ( lhs );
  auto &  ref  =  mat1  -=  rhs ;
  ASSERT_TRUE ( mat1  ==  answer );
  ASSERT_EQ ( & mat1 ,   & ref );
}

TEST_F ( MatrixTesting ,   MatrixMinusScalar )   {
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  elem_type rhs ( 10 );
  answer_type answer {{ 0 ,   10 },
                      { 20 ,   30 },
                      { 35 ,   40 },
                      { 90 ,   190 }};

   Matrix :: Matrix  mat1 ( lhs );
  auto diff  =  mat1  -  rhs ;
  ASSERT_TRUE ( diff  ==  answer );
}

TEST_F ( MatrixTesting ,   MatrixTimesEqualScalar )   {
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  elem_type rhs ( 10 );
  answer_type answer {{ 100 ,   200 },
                      { 300 ,   400 },
                      { 450 ,   500 },
                      { 1000 ,   2000 }};

   Matrix :: Matrix  mat1 ( lhs );
  auto &  ref  =  mat1  *=  rhs ;
  ASSERT_TRUE ( mat1  ==  answer );
  ASSERT_EQ ( & mat1 ,   & ref );
}

TEST_F ( MatrixTesting ,   MatrixTimesScalar )   {
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;

  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  elem_type rhs ( 2 );

  answer_type answer {{ 20 ,   40 },
                      { 60 ,   80 },
                      { 90 ,   100 },
                      { 200 ,   400 }};

   Matrix :: Matrix  mat1 ( lhs );
  auto prod  =  mat1  *  rhs ;
  ASSERT_TRUE ( prod  ==  answer );
}

TEST_F ( MatrixTesting ,   ScalarPlusMatrix )   {
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  elem_type rhs ( 100 );
  answer_type answer {{ 110 ,   120 },
                      { 130 ,   140 },
                      { 145 ,   150 },
                      { 200 ,   300 }};

   Matrix :: Matrix  mat1 ( lhs );
  auto sum  =  rhs  +  mat1 ;
  ASSERT_TRUE ( sum  ==  answer );
}

TEST_F ( MatrixTesting ,   ScalarMinusMatrix )   {
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;
  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  elem_type rhs ( 10 );
  answer_type answer {{ 0 ,   - 10 },
                      { - 20 ,   - 30 },
                      { - 35 ,   - 40 },
                      { - 90 ,   - 190 }};

   Matrix :: Matrix  mat1 ( lhs );
  auto diff  =  rhs  -  mat1 ;
  ASSERT_TRUE ( diff  ==  answer );
}

TEST_F ( MatrixTesting ,   ScalarTimesMatrix )   {
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;

  answer_type lhs {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  elem_type rhs ( 2 );

  answer_type answer {{ 20 ,   40 },
                      { 60 ,   80 },
                      { 90 ,   100 },
                      { 200 ,   400 }};

   Matrix :: Matrix  mat1 ( lhs );
  auto prod  =  rhs  *  mat1 ;
  ASSERT_TRUE ( prod  ==  answer );
}

Matrix/testing/Matrix/MatrixConstructorTests.cpp

Matrix/testing/Matrix/MatrixConstructorTests.cpp

//
// Created by mfbut on 11/19/2019.
//

#ifndef  ECS_36B_HOMEWORK_MATRIXCONSTRUCTORTESTS_CPP
#define  ECS_36B_HOMEWORK_MATRIXCONSTRUCTORTESTS_CPP
#include   < vector >
#include   "Matrix.h"
#include   "MatrixTesting.h"
#include   "gmock/gmock.h"

TEST_F ( MatrixTesting ,   DimensionsAndValues )   {
   using   namespace   :: testing ;
   Matrix :: Matrix  mat1 ( 3 ,   4 ,   5 );
  answer_type ans ( 3 ,   { 5 ,   5 ,   5 ,   5 });
  EXPECT_TRUE ( mat1  ==  ans );
}

TEST_F ( MatrixTesting ,   DimensionsOnly )   {
   using   namespace   :: testing ;
   Matrix :: Matrix  mat1 ( 15 ,   3 ,   0 );
  answer_type ans ( 15 ,   { 0 ,   0 ,   0 });
  EXPECT_TRUE ( mat1  ==  ans );
}

TEST_F ( MatrixTesting ,   StdVectorOfStdVectorOfElementType )   {
   using   namespace   :: testing ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};

   Matrix :: Matrix  mat1 ( ans );
  EXPECT_TRUE ( mat1  ==  ans );
}

TEST_F ( MatrixTesting ,   StdVectorOfMatrixVector )   {
   using   namespace   :: testing ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  std :: vector < Matrix :: Vector >  initializer ( ans . begin (),  ans . end ());

   Matrix :: Matrix  mat1 ( initializer );
  EXPECT_TRUE ( mat1  ==  ans );
}

TEST_F ( MatrixTesting ,   StdVectorOfMatrixConstVectorRef )   {
   using   namespace   :: testing ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  std :: vector < Matrix :: Vector >  vectors ( ans . begin (),  ans . end ());
  std :: vector < Matrix :: ConstVectorRef >  initializer ( vectors . begin (),  vectors . end ());

   Matrix :: Matrix  mat1 ( initializer );
  EXPECT_TRUE ( mat1  ==  ans );
}

TEST_F ( MatrixTesting ,   StdVectorOfMatrixVectorRef )   {
   using   namespace   :: testing ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
  std :: vector < Matrix :: Vector >  vectors ( ans . begin (),  ans . end ());
  std :: vector < Matrix :: VectorRef >  initializer ( vectors . begin (),  vectors . end ());

   Matrix :: Matrix  mat1 ( initializer );
  EXPECT_TRUE ( mat1  ==  ans );
}

TEST_F ( MatrixTesting ,   MatrixIdentity )   {
   using   namespace   :: testing ;
  answer_type ans1 {{ 1 ,   0 ,   0 },
                    { 0 ,   1 ,   0 },
                    { 0 ,   0 ,   1 }},
      ans2 {{ 1 ,   0 ,   0 ,   0 },
            { 0 ,   1 ,   0 ,   0 },
            { 0 ,   0 ,   1 ,   0 },
            { 0 ,   0 ,   0 ,   1 }
   };

   Matrix :: Matrix  mat1  =   Matrix :: Matrix :: ident ( 3 ),
  mat2  =   Matrix :: Matrix :: ident ( 4 );

  EXPECT_TRUE ( mat1  ==  ans1 );
  EXPECT_TRUE ( mat2  ==  ans2 );
}

#endif   //ECS_36B_HOMEWORK_MATRIXCONSTRUCTORTESTS_CPP

Matrix/testing/Matrix/MatrixElementAccessTests.cpp

Matrix/testing/Matrix/MatrixElementAccessTests.cpp

//
// Created by mfbut on 11/20/2019.
//

#include   < algorithm >
#include   < functional >
#include   "MatrixTesting.h"
#include   "gmock/gmock.h"

TEST_F ( MatrixTesting ,   MatrixRowColAtRead )   {
   using   namespace   :: testing ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};

   const   int  numRows  =  ans . size (),  numCols  =  ans . front (). size ();
   Matrix :: Matrix  mat1 ( ans );

   for   ( int  row  =   0 ;  row  <  numRows ;   ++ row )   {
     for   ( int  col  =   0 ;  col  <  numCols ;   ++ col )   {
      ASSERT_EQ ( mat1 . at ( row ,  col ),  ans . at ( row ). at ( col ));
      ASSERT_TRUE ( mat1  ==  ans );
     }
   }
}

TEST_F ( MatrixTesting ,   MatrixRowColAtWrite )   {
   using   namespace   :: testing ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};

   const   int  numRows  =  ans . size (),  numCols  =  ans . front (). size ();
   Matrix :: Matrix  mat1 ( ans );

  auto &  ansRef  =  ans . at ( 2 ). at ( 1 );
  auto &  givenRef  =  mat1 . at ( 2 ,   1 );

   for   ( int  row  =   0 ;  row  <  numRows ;   ++ row )   {
     for   ( int  col  =   0 ;  col  <  numCols ;   ++ col )   {
      ASSERT_EQ ( mat1 . at ( row ,  col ),  ans . at ( row ). at ( col ));
      ASSERT_EQ ( givenRef ,  ansRef );
      mat1 . at ( row ,  col )   +=   14 ;
      ans . at ( row ). at ( col )   +=   14 ;
      ASSERT_EQ ( mat1 . at ( row ,  col ),  ans . at ( row ). at ( col ));
      ASSERT_EQ ( givenRef ,  ansRef );
      ASSERT_TRUE ( mat1  ==  ans );
     }
   }
}

TEST_F ( MatrixTesting ,   MatrixRowAtRead )   {
   using   namespace   :: testing ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};

   const   int  numRows  =  ans . size ();
   Matrix :: Matrix  mat1 ( ans );

  ASSERT_TRUE ( mat1  ==  ans );

   for   ( int  row  =   0 ;  row  <  numRows ;   ++ row )   {
    ASSERT_THAT ( mat1 . rowAt ( row ),   ElementsAreArray ( ans . at ( row )));
    ASSERT_TRUE ( mat1  ==  ans );
   }
}
TEST_F ( MatrixTesting ,   MatrixBracketRead )   {
   using   namespace   :: testing ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};

   const   int  numRows  =  ans . size ();
   Matrix :: Matrix  mat1 ( ans );

  ASSERT_TRUE ( mat1  ==  ans );

   for   ( int  row  =   0 ;  row  <  numRows ;   ++ row )   {
    ASSERT_THAT ( mat1 [ row ],   ElementsAreArray ( ans . at ( row )));
    ASSERT_TRUE ( mat1  ==  ans );
   }
}

TEST_F ( MatrixTesting ,   MatrixRowAtWrite )   {
   using   namespace   :: testing ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};

   const   int  numRows  =  ans . size ();
   Matrix :: Matrix  mat1 ( ans );

  ASSERT_TRUE ( mat1  ==  ans );
   for   ( int  row  =   0 ;  row  <  numRows ;   ++ row )   {
    auto &  curRow  =  ans . at ( row );
    std :: vector < Matrix :: Matrix :: element_type >  newRow ( curRow );
    std :: transform ( newRow . begin (),  newRow . end (),  curRow . rbegin (),  newRow . begin (),  std :: plus <> ());
    mat1 . rowAt ( row )   =   Matrix :: Vector ( newRow );
    curRow  =  newRow ;
    ASSERT_THAT ( mat1 . rowAt ( row ),   ElementsAreArray ( ans . at ( row )));
    ASSERT_TRUE ( mat1  ==  ans );
   }
}
TEST_F ( MatrixTesting ,   MatrixBracketWrite )   {
   using   namespace   :: testing ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};

   const   int  numRows  =  ans . size ();
   Matrix :: Matrix  mat1 ( ans );

  ASSERT_TRUE ( mat1  ==  ans );
   for   ( int  row  =   0 ;  row  <  numRows ;   ++ row )   {
    auto &  curRow  =  ans . at ( row );
    std :: vector < Matrix :: Matrix :: element_type >  newRow ( curRow );
    std :: transform ( newRow . begin (),  newRow . end (),  curRow . rbegin (),  newRow . begin (),  std :: plus <> ());
    mat1 . rowAt ( row )   =   Matrix :: Vector ( newRow );
    curRow  =  newRow ;
    ASSERT_THAT ( mat1 [ row ],   ElementsAreArray ( ans . at ( row )));
    ASSERT_TRUE ( mat1  ==  ans );
   }
}

TEST_F ( MatrixTesting ,   MatrixColAtRead )   {
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
   const   int  numRows  =  ans . size (),  numCols  =  ans . front (). size ();
   Matrix :: Matrix  mat1 ( ans );
  answer_type cols ( ans . front (). size (),  std :: vector < elem_type > ( ans . size ()));

   for   ( int  row  =   0 ;  row  <  numRows ;   ++ row )   {
     for   ( int  col  =   0 ;  col  <  numCols ;   ++ col )   {
      cols . at ( col ). at ( row )   =  ans . at ( row ). at ( col );
     }
   }


  ASSERT_TRUE ( mat1  ==  ans );

   for   ( int  col  =   0 ;  col  <  numCols ;   ++ col )   {
    ASSERT_THAT ( mat1 . colAt ( col ),   ElementsAreArray ( cols . at ( col )));
    ASSERT_TRUE ( mat1  ==  ans );
   }
}

TEST_F ( MatrixTesting ,   MatrixColAtWrite )   {
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;
  answer_type ans {{ 10 ,   20 },
                   { 30 ,   40 },
                   { 45 ,   50 },
                   { 100 ,   200 }};
   const   int  numRows  =  ans . size (),  numCols  =  ans . front (). size ();
   Matrix :: Matrix  mat1 ( ans );
  answer_type cols ( ans . front (). size (),  std :: vector < elem_type > ( ans . size ()));

   for   ( int  row  =   0 ;  row  <  numRows ;   ++ row )   {
     for   ( int  col  =   0 ;  col  <  numCols ;   ++ col )   {
      cols . at ( col ). at ( row )   =  ans . at ( row ). at ( col );
     }
   }


  ASSERT_TRUE ( mat1  ==  ans );
   for   ( int  col  =   0 ;  col  <  numCols ;   ++ col )   {
    auto &  curCol  =  cols . at ( col );
    mat1 . colAt ( col )   +=   Matrix :: Vector ( curCol );
    std :: transform ( curCol . begin (),  curCol . end (),  curCol . begin (),  curCol . begin (),  std :: plus <> ());
    ASSERT_THAT ( mat1 . colAt ( col ),   ElementsAreArray ( cols . at ( col )));
   }
}

TEST_F ( MatrixTesting ,   RowIterate ){
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;
  answer_type vals ( 5 ,  std :: vector < elem_type > ( 6 ,   7 ));
   Matrix :: Matrix  mat ( vals );
  answer_type ans ( 5 ,  std :: vector < elem_type > ( 6 ,   10 ));

   for ( auto row  :  mat ){
    row  +=   3 ;
   }

  ASSERT_TRUE ( mat  ==  ans );
}

TEST_F ( MatrixTesting ,   ColIterate ){
   using   namespace   :: testing ;
   using  elem_type  =   Matrix :: Matrix :: element_type ;
  answer_type vals ( 5 ,  std :: vector < elem_type > ( 6 ,   7 ));
   Matrix :: Matrix  mat ( vals );
  answer_type ans ( 5 ,  std :: vector < elem_type > ( 6 ,   10 ));

   for ( auto itr  =  mat . colBegin ();  itr  !=  mat . colEnd ();   ++ itr ){
     * itr  +=   3 ;
   }

  ASSERT_TRUE ( mat  ==  ans );
}

Matrix/testing/Matrix/MatrixTesting.cpp

Matrix/testing/Matrix/MatrixTesting.cpp

//
// Created by mfbut on 11/17/2019.
//

#include   "MatrixTesting.h"

:: testing :: AssertionResult   operator == ( const   Matrix :: Matrix &  given ,   const   MatrixTesting :: answer_type &  answer )   {
   const   int  answerNumRows  =  answer . size (),  answerNumCols  =  answer . front (). size ();
   if   ( given . getNumRows ()   !=  answerNumRows )   {
     return   :: testing :: AssertionFailure ()   <<   "Given matrix has incorrect number of rows.\n"
                                             "It should have "   <<  answerNumRows  <<
                                          "rows but actually has "   <<  given . getNumRows ()   <<   " rows."   <<  std :: endl ;
   }   else   if   ( given . getNumCols ()   !=  answerNumCols )   {
     return   :: testing :: AssertionFailure ()   <<   "Given matrix has incorrect number of columns.\n"
                                             "It should have "   <<  answerNumCols  <<
                                          "columns but actually has "   <<  given . getNumCols ()   <<   " rows."   <<  std :: endl ;
   }   else   {
     for   ( int  row  =   0 ;  row  <  answerNumRows ;   ++ row )   {
       for   ( int  col  =   0 ;  col  <  answerNumCols ;   ++ col )   {
         if   ( answer . at ( row ). at ( col )   !=  given . at ( row ,  col ))   {
           return   :: testing :: AssertionFailure ()   <<
                                                "\nGiven matrix:\n"   <<  given  <<  std :: endl  <<
                                                "Does not match expected matrix:\n"   <<  answer  <<  std :: endl  <<
                                                "First mismatch occurs at position: "   <<  row  <<   ", "   <<  col  <<   "."
                                                <<  std :: endl  <<
                                                "The given matrix has "   <<  given . at ( row ,  col )
                                                <<   " there but it should be "   <<
                                               answer . at ( row ). at ( col )   <<   '.'    <<  std :: endl ;
         }
       }
     }
   }
   return   :: testing :: AssertionSuccess ();
}

std :: ostream &   operator << ( std :: ostream &  out ,   const   MatrixTesting :: answer_type &  answer )   {
   for   ( const  auto &  row  :  answer )   {
     for   ( const  auto &  element  :  row )   {
      out  <<  element  <<   ' ' ;
     }
    out  <<  std :: endl ;
   }
   return  out ;
}

std :: ostream &   operator << ( std :: ostream &  out ,   const   Matrix :: Matrix &  matrix )   {
   for   ( const  auto &  row  :  matrix )   {
     for   ( const  auto &  element  :  row )   {
      out  <<  element  <<   ' ' ;
     }
    out  <<  std :: endl ;
   }
   return  out ;
}

Matrix/testing/Matrix/MatrixTesting.h

// // Created by mfbut on 11/17/2019. // #ifndef ECS_36B_HOMEWORK_MATRIXTESTING_H #define ECS_36B_HOMEWORK_MATRIXTESTING_H #include <vector> #include <iostream> #include "Matrix.h" #include "gtest/gtest.h" class MatrixTesting : public ::testing::Test{ public: using answer_type = std::vector<std::vector<Matrix::Matrix::element_type>>; }; ::testing::AssertionResult operator==(const Matrix::Matrix& given, const MatrixTesting::answer_type& answer); std::ostream& operator << (std::ostream& out, const MatrixTesting::answer_type& answer); std::ostream& operator << (std::ostream& out, const Matrix::Matrix& matrix); #endif //ECS_36B_HOMEWORK_MATRIXTESTING_H

Matrix/testing/test_main.cpp

Matrix/testing/test_main.cpp

//
// Created by mfbut on 11/14/2019.
//

#include   "gtest/gtest.h"


/*
 * If you do not want to build the tests contained in a specific file
 * comment out the include below
 * and comment out the files in  either
 * testing/Matrix/CMakeLists.txt
 * or
 * testing/Vector/CMakeLists.txt
 */
//vector tests
#include   "VectorConstructorTests.cpp"
#include   "ConstBaseVectorTests.cpp"
#include   "BaseVectorTests.cpp"
#include   "VectorRefTesting.cpp"

//matrix tests
#include   "MatrixConstructorTests.cpp"
#include   "MatrixElementAccessTests.cpp"
#include   "MatrixArithmeticOperatorTests.cpp"

int  main ( int  argc ,   char   ** argv )   {
   :: testing :: InitGoogleTest ( & argc ,  argv );
   return  RUN_ALL_TESTS ();
}

Matrix/testing/Vector/BaseVectorTests.cpp

Matrix/testing/Vector/BaseVectorTests.cpp

//
// Created by mfbut on 11/19/2019.
//

#ifndef  ECS_36B_HOMEWORK_BASEVECTORTESTS_CPP
#define  ECS_36B_HOMEWORK_BASEVECTORTESTS_CPP
//====Methods defined in BaseVector=====

//element writes
#include   "VectorTesting.h"
#include   "gmock/gmock.h"

TEST_F ( VectorTesting ,   VectorAtWrite ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 12 ,   45 ,   - 89 ,   64 ,   - 1325 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );

   for   ( unsigned   int  i  =   0 ;  i  <  inV1 . size ();   ++ i )   {
    inV1 . at ( i )   +=   3 ;
    v1 . at ( i )    +=   3 ;
    ASSERT_EQ ( v1 . at ( i ),  inV1 . at ( i ));
   }

  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));

   for   ( unsigned   int  i  =   0 ;  i  <  inV2 . size ();   ++ i )   {
    inV2 . at ( i )   -=   3 ;
    v2 . at ( i )    -=   3 ;
    ASSERT_EQ ( v2 . at ( i ),  inV2 . at ( i ));
   }
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}

TEST_F ( VectorTesting ,   VectorBracketWrite ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 12 ,   45 ,   - 89 ,   64 ,   - 1325 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );

   for   ( unsigned   int  i  =   0 ;  i  <  inV1 . size ();   ++ i )   {
    inV1 [ i ]   *=   12 ;
    v1 [ i ]   *=   12 ;
    ASSERT_EQ ( v1 [ i ],  inV1 . at ( i ));
   }

  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));

   for   ( unsigned   int  i  =   0 ;  i  <  inV2 . size ();   ++ i )   {
    inV2 [ i ]   +=   12 ;
    v2 [ i ]   +=   12 ;
    ASSERT_EQ ( v2 [ i ],  inV2 . at ( i ));
   }

  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}


TEST_F ( VectorTesting ,   VectorIteratorWrite ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 , 4 , 5 };
   Vector  v1 ( inV1 );

   for ( auto &  elem  :  inV1 ){
    elem  *=   10 ;
   }

   for ( auto &  elem  :  v1 ){
    elem  *=   10 ;
   }

  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));
}



//arithmetic methods
TEST_F ( VectorTesting ,   VectorPlusEqualVector ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 10 ,   20 ,   30 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );

   const   Vector &  sum1  =   dynamic_cast < Vector &> ( v1  +=  v2 );
  ASSERT_THAT ( v1 ,   ElementsAre ( 11 ,   22 ,   33 ));
  ASSERT_THAT ( sum1 ,   ElementsAre ( 11 ,   22 ,   33 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));


  v1  +=  v1 ;
  ASSERT_THAT ( v1 ,   ElementsAre ( 22 ,   44 ,   66 ));
  ASSERT_THAT ( sum1 ,   ElementsAre ( 22 ,   44 ,   66 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));

   const   Vector &  sum2  =   dynamic_cast < Vector &> ( v2  +=  v1 );
  ASSERT_THAT ( v2 ,   ElementsAre ( 32 ,   64 ,   96 ));
  ASSERT_THAT ( sum2 ,   ElementsAre ( 32 ,   64 ,   96 ));
  ASSERT_THAT ( v1 ,   ElementsAre ( 22 ,   44 ,   66 ));
}

TEST_F ( VectorTesting ,   VectorMinusEqualVector ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 10 ,   20 ,   30 },  inV3 { 100 ,   200 ,   300 };
   Vector  v1 ( inV1 ),  v2 ( inV2 ),  v3 ( inV3 );

   const   Vector &  diff1  =   dynamic_cast < Vector &> ( v1  -=  v2 );
  ASSERT_THAT ( v1 ,   ElementsAre ( - 9 ,   - 18 ,   - 27 ));
  ASSERT_THAT ( diff1 ,   ElementsAre ( - 9 ,   - 18 ,   - 27 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));


  v1 . operator -= ( v1 );
  ASSERT_THAT ( v1 ,   ElementsAre ( 0   , 0   ,   0 ));
  ASSERT_THAT ( diff1 ,   ElementsAre ( 0   , 0   ,   0 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));

   const   Vector &  diff2  =   dynamic_cast < Vector &> ( v3  -=  v2 );
  ASSERT_THAT ( v3 ,   ElementsAre ( 90 ,   180 ,   270 ));
  ASSERT_THAT ( diff2 ,   ElementsAre ( 90 ,   180 ,   270 ));
  ASSERT_THAT ( v1 ,   ElementsAre ( 0   , 0   ,   0 ));
}

TEST_F ( VectorTesting ,   VectorPlusEqualScalar ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 10 ,   20 ,   30 ,   40 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );

   const   Vector &  sum1  =   dynamic_cast < Vector &> ( v1  +=   10 );
  ASSERT_THAT ( v1 ,   ElementsAre ( 11 ,   12 ,   13 ));
  ASSERT_THAT ( sum1 ,   ElementsAre ( 11 ,   12 ,   13 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));

   const   Vector &  sum2  =   dynamic_cast < Vector &> ( v2  +=   10 );
  ASSERT_THAT ( v2 ,   ElementsAre ( 20 ,   30 ,   40 ,   50 ));
  ASSERT_THAT ( sum2 ,   ElementsAre ( 20 ,   30 ,   40 ,   50 ));
  ASSERT_THAT ( v1 ,   ElementsAre ( 11 ,   12 ,   13 ));
}

TEST_F ( VectorTesting ,   VectorMinusEqualScalar ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 10 ,   20 ,   30 ,   40 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );

   const   Vector &  diff1  =   dynamic_cast < Vector &> ( v1  -=   - 1 );
  std :: vector < Vector :: value_type >  ans1 { 2 ,   3 ,   4 };
  ASSERT_THAT ( v1 ,   ElementsAreArray ( ans1 ));
  ASSERT_THAT ( diff1 ,   ElementsAreArray ( ans1 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));

   const   Vector &  sum2  =   dynamic_cast < Vector &> ( v2  -=   10 );
  std :: vector < Vector :: value_type >  ans2 { 0 ,   10 ,   20 ,   30 };
  ASSERT_THAT ( v2 ,   ElementsAreArray ( ans2 ));
  ASSERT_THAT ( sum2 ,   ElementsAreArray ( ans2 ));
  ASSERT_THAT ( v1 ,   ElementsAreArray ( ans1 ));
}

TEST_F ( VectorTesting ,   VectorTimeEqualScalar ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 10 ,   20 ,   30 ,   40 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );

   const   Vector &  diff1  =   dynamic_cast < Vector &> ( v1  *=   - 2 );
  std :: vector < Vector :: value_type >  ans1 { - 2 ,   - 4 ,   - 6 };
  ASSERT_THAT ( v1 ,   ElementsAreArray ( ans1 ));
  ASSERT_THAT ( diff1 ,   ElementsAreArray ( ans1 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));

   const   Vector &  sum2  =   dynamic_cast < Vector &> ( v2  *=   - 10 );
  std :: vector < Vector :: value_type >  ans2 { - 100 ,   - 200 ,   - 300 ,   - 400 };
  ASSERT_THAT ( v2 ,   ElementsAreArray ( ans2 ));
  ASSERT_THAT ( sum2 ,   ElementsAreArray ( ans2 ));
  ASSERT_THAT ( v1 ,   ElementsAreArray ( ans1 ));
}

#endif   //ECS_36B_HOMEWORK_BASEVECTORTESTS_CPP

Matrix/testing/Vector/CMakeLists.txt

cmake_minimum_required(VERSION 3.14) project(MatrixVectorTesting LANGUAGES CXX) set(CMAKE_CXX_STANDARD 14) add_library(VectorTesting STATIC VectorTesting.cpp VectorTesting.h VectorConstructorTests.cpp ConstBaseVectorTests.cpp BaseVectorTests.cpp VectorRefTesting.cpp) target_link_libraries(VectorTesting PUBLIC MatrixVector gtest gmock ) target_compile_options(VectorTesting PRIVATE -Wall -Werror -Wextra) target_include_directories(VectorTesting PUBLIC .)

Matrix/testing/Vector/ConstBaseVectorTests.cpp

Matrix/testing/Vector/ConstBaseVectorTests.cpp

//
// Created by mfbut on 11/19/2019.
//

#include   "VectorTesting.h"
#include   "gmock/gmock.h"

//====Methods defined in ConstBaseVector=====

//element reads
TEST_F ( VectorTesting ,   VectorAtRead ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 12 ,   45 ,   - 89 ,   64 ,   - 1325 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );

   for   ( unsigned   int  i  =   0 ;  i  <  inV1 . size ();   ++ i )   {
    ASSERT_EQ ( v1 . at ( i ),  inV1 . at ( i ));
   }

   for   ( unsigned   int  i  =   0 ;  i  <  inV2 . size ();   ++ i )   {
    ASSERT_EQ ( v2 . at ( i ),  inV2 . at ( i ));
   }
}

TEST_F ( VectorTesting ,   VectorBracketRead ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 12 ,   45 ,   - 89 ,   64 ,   - 1325 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );

   for   ( unsigned   int  i  =   0 ;  i  <  inV1 . size ();   ++ i )   {
    ASSERT_EQ ( v1 [ i ],  inV1 . at ( i ));
   }

   for   ( unsigned   int  i  =   0 ;  i  <  inV2 . size ();   ++ i )   {
    ASSERT_EQ ( v2 [ i ],  inV2 . at ( i ));
   }
}

//arithmetic methods
TEST_F ( VectorTesting ,   VectorNegate ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 12 ,   45 ,   - 89 ,   64 ,   - 1325 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );

  ASSERT_THAT ( - v1 ,   ElementsAre ( - 1 , - 2 , - 3 ));
  ASSERT_THAT ( - v2 ,   ElementsAre ( - 12 ,   - 45 ,   89 ,   - 64 ,   1325 ));
}


TEST_F ( VectorTesting ,   VectorPlusVector ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 10 ,   20 ,   30 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );
   Vector  sum1  =  v1  +  v2 ;
  ASSERT_THAT ( sum1  ,   ElementsAre ( 11 ,   22 ,   33 ));
  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}

TEST_F ( VectorTesting ,   VectorMinusVector ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 10 ,   20 ,   30 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );
   Vector  diff  =  v1  -  v2 ;
  ASSERT_THAT ( diff  ,   ElementsAre ( - 9 ,   - 18 ,   - 27 ));
  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}

TEST_F ( VectorTesting ,   VectorTimesVector ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 10 ,   20 ,   30 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );
   Vector  prod  =  v1  *  v2 ;
  ASSERT_THAT ( prod  ,   ElementsAre ( 140 ));
  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}

TEST_F ( VectorTesting ,   VectorEqualToVector ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 10 ,   20 ,   30 };
   Vector  v1 ( inV1 ),  v2 ( inV2 ),  v3 ( v1 ),  v4 ( v2 );

   //you should be equal to yourself
  ASSERT_EQ ( v1 ,  v1 );
  ASSERT_EQ ( v2 ,  v2 );
  ASSERT_EQ ( v3 ,  v3 );
  ASSERT_EQ ( v4 ,  v4 );

   //you should be equal to your copy
  ASSERT_EQ ( v1 ,  v3 );
  ASSERT_EQ ( v2 ,  v4 );

   //you shouldn't be equal to anything else
  ASSERT_FALSE ( v1  ==  v2 );
  ASSERT_FALSE ( v1  ==  v4 );
  ASSERT_FALSE ( v3  ==  v2 );
  ASSERT_FALSE ( v3  ==  v4 );
}

TEST_F ( VectorTesting ,   VectorNotEqualVector ){
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 10 ,   20 ,   30 };
   Vector  v1 ( inV1 ),  v2 ( inV2 ),  v3 ( v1 ),  v4 ( v2 );
  ASSERT_NE ( v1 ,  v2 );
  ASSERT_NE ( v1 ,  v4 );
  ASSERT_NE ( v3 ,  v2 );
  ASSERT_NE ( v3 ,  v4 );


   //you should be equal to yourself
  ASSERT_FALSE ( v1  !=  v1 );
  ASSERT_FALSE ( v2  !=  v2 );
  ASSERT_FALSE ( v3  !=  v3 );
  ASSERT_FALSE ( v4  !=  v4 );

   //you should be equal to your copy
  ASSERT_FALSE ( v1  !=   v3 );
  ASSERT_FALSE ( v2  !=   v4 );
}


TEST_F ( VectorTesting ,   VectorPlusScalar )   {
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 ,   2 ,   3 },  inV2 { 10 ,   20 ,   30 ,   40 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );
  ASSERT_THAT ( v1  +   7 ,   ElementsAre ( 8 ,   9 ,   10 ));
  ASSERT_THAT ( v2  +   100 ,   ElementsAre ( 110 ,   120 ,   130 ,   140 ));

  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}

TEST_F ( VectorTesting ,   ScalarPlusVector )   {
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 ,   2 ,   3 },  inV2 { 10 ,   20 ,   30 ,   40 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );
  ASSERT_THAT ( 7   +  v1 ,   ElementsAre ( 8 ,   9 ,   10 ));
  ASSERT_THAT ( 100   +  v2  ,   ElementsAre ( 110 ,   120 ,   130 ,   140 ));

  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}

TEST_F ( VectorTesting ,   VectorMinusScalar )   {
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 ,   2 ,   3 },  inV2 { 10 ,   20 ,   30 ,   40 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );
  ASSERT_THAT ( v1  -   7 ,   ElementsAre ( - 6 ,   - 5 ,   - 4 ));
  ASSERT_THAT ( v2  -   100 ,   ElementsAre ( - 90 ,   - 80 ,   - 70 ,   - 60 ));

  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}

TEST_F ( VectorTesting ,   ScalarMinusVector )   {
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 ,   2 ,   3 },  inV2 { 10 ,   20 ,   30 ,   40 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );
  ASSERT_THAT ( 7   -  v1 ,   ElementsAre ( 6 ,   5 ,   4 ));
  ASSERT_THAT ( 100   -  v2  ,   ElementsAre ( 90 ,   80 ,   70 ,   60 ));

  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}


TEST_F ( VectorTesting ,   VectorTimesScalar )   {
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 ,   2 ,   3 },  inV2 { 10 ,   20 ,   30 ,   40 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );
  ASSERT_THAT ( v1  *   7 ,   ElementsAre ( 7 ,   14 ,   21 ));
  ASSERT_THAT ( v2  *   100 ,   ElementsAre ( 1000 ,   2000 ,   3000 ,   4000 ));

  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}

TEST_F ( VectorTesting ,   ScalarTimesVector )   {
   using   namespace   Matrix ;
   using   namespace   :: testing ;
  std :: vector < Vector :: value_type >  inV1 { 1 ,   2 ,   3 },  inV2 { 10 ,   20 ,   30 ,   40 };
   Vector  v1 ( inV1 ),  v2 ( inV2 );
  ASSERT_THAT ( 7   *  v1  ,   ElementsAre ( 7 ,   14 ,   21 ));
  ASSERT_THAT ( 100   *  v2  ,   ElementsAre ( 1000 ,   2000 ,   3000 ,   4000 ));

  ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));
  ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}

Matrix/testing/Vector/VectorConstructorTests.cpp

Matrix/testing/Vector/VectorConstructorTests.cpp

//
// Created by mfbut on 11/19/2019.
//

#include   "VectorTesting.h"
#include   "gmock/gmock.h"

TEST_F ( VectorTesting ,   NumElementsValueConstructor ){
using   namespace   Matrix ;
using   namespace   :: testing ;
Vector  v1 ( 3 ,   4 ),  v2 ( 5 ,   7 );
ASSERT_EQ ( v1 . size (),   3 );
ASSERT_EQ ( v2 . size (),   5 );
ASSERT_THAT ( v1 ,   ElementsAre ( 4 , 4 , 4 ));
ASSERT_THAT ( v2 ,   ElementsAre ( 7 , 7 , 7 , 7 , 7 ));
}

TEST_F ( VectorTesting ,   NumElementsConstructor ){
using   namespace   Matrix ;
using   namespace   :: testing ;
Vector  v1 ( 2 ),  v2 ( 8 );
ASSERT_EQ ( v1 . size (),   2 );
ASSERT_EQ ( v2 . size (),   8 );
ASSERT_THAT ( v1 ,   ElementsAre ( 0 ,   0 ));
ASSERT_THAT ( v2 ,   ElementsAre ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ));
}

TEST_F ( VectorTesting ,   StdVectorConstructor ){
using   namespace   Matrix ;
using   namespace   :: testing ;
std :: vector < Vector :: value_type >  inV1 { 1 , 2 , 3 },  inV2 { 12 ,   45 ,   - 89 ,   64 ,   - 1325 };
Vector  v1 ( inV1 ),  v2 ( inV2 );
ASSERT_EQ ( v1 . size (),   3 );
ASSERT_EQ ( v2 . size (),   5 );
ASSERT_THAT ( v1 ,   ElementsAreArray ( inV1 ));
ASSERT_THAT ( v2 ,   ElementsAreArray ( inV2 ));
}

Matrix/testing/Vector/VectorRefTesting.cpp

Matrix/testing/Vector/VectorRefTesting.cpp

//
// Created by mfbut on 11/21/2019.
//
#include   < algorithm >
#include   < functional >
#include   "VectorTesting.h"
#include   "VectorRef.h"

#include   "gmock/gmock.h"

TEST_F ( VectorTesting ,   VectorRefTest ){
   using   namespace   :: testing ;
   using   namespace   Matrix ;

   Vector  v ( 3 , 7 );
   VectorRef  vr ( v );

   for ( auto &  val  :  vr ){
   val  +=   4 ;
   }

  ASSERT_EQ ( v ,  vr );

   for ( auto &  val  :  v ){
    val  *=   2 ;
   }

  ASSERT_EQ ( v ,  vr );


}

Matrix/testing/Vector/VectorTesting.cpp

Matrix/testing/Vector/VectorTesting.cpp

//
// Created by mfbut on 11/14/2019.
//








Matrix/testing/Vector/VectorTesting.h

// // Created by mfbut on 11/14/2019. // #ifndef ECS_36B_HOMEWORK_VECTORTESTING_H #define ECS_36B_HOMEWORK_VECTORTESTING_H #include "gtest/gtest.h" #include "Vector.h" class VectorTesting : public ::testing::Test{ public: VectorTesting() = default; protected: //std::vector<Matrix::Vector> _2, _3, _4; }; #endif //ECS_36B_HOMEWORK_VECTORTESTING_H