lab3 done
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @author Trevor Barnes (barnestr@msoe.edu)
|
||||
* @brief
|
||||
* @brief The main driver for the matrix implementation. This driver provides
|
||||
* test for matrix.cpp. Memory leak test were performed using valgrind
|
||||
* @version 1.0
|
||||
* @date 2022-03-29
|
||||
*
|
||||
@@ -19,22 +20,58 @@ int main()
|
||||
cin >> rows;
|
||||
cout << "Enter the number of columns in the test matrix: " << endl;
|
||||
cin >> cols;
|
||||
// Constructor Test
|
||||
Matrix m1(rows,cols);
|
||||
// add more tests
|
||||
Matrix m2(rows,cols);
|
||||
// Assign various arbitrary values
|
||||
for(int i = 0; i < rows; i++){
|
||||
for(int j = 0; j < cols; j++){
|
||||
m1[i][j] = 4.268394 + (i+7)*(j+7);
|
||||
m1[i][j] = 12.181998*(1+(i*j));
|
||||
m2[i][j] = 1.0 + i;
|
||||
}
|
||||
m1[0][0] = 4.20;
|
||||
m1[0][1] = 6.9;
|
||||
m1[0][2] = 1.337;
|
||||
m1[0][3] = 12.18;
|
||||
|
||||
}
|
||||
cout << m1 << endl;
|
||||
m1*5;
|
||||
cout << m1 << endl;
|
||||
m1.clear();
|
||||
cout << m1;
|
||||
// IO Test
|
||||
cout << "m1:" << endl << m1;
|
||||
// Copy Constructor Test with const
|
||||
const Matrix m1copy(m1);
|
||||
cout << "m1copy:" << endl << m1copy;
|
||||
cout << "m2:" << endl << m2;
|
||||
// Assignment Operator Test
|
||||
m1 = m2;
|
||||
cout << "m1 = m2:" << endl << m1;
|
||||
// Transpose Test
|
||||
m1 = ~m1;
|
||||
cout << "~m1:" << endl << m1;
|
||||
// Named Contructor Test
|
||||
Matrix ident = Matrix::identity(4);
|
||||
cout << "Identity matrix of size: " << rows << endl << ident;
|
||||
Matrix m3(3,4);
|
||||
Matrix m4(4,3);
|
||||
for(int i = 0; i < 3; i++){
|
||||
for(int j = 0; j < 4; j++){
|
||||
m3[i][j] = 1 + i*j;
|
||||
}
|
||||
}
|
||||
cout << "m3:" << endl << m3;
|
||||
// Scalar Multiplication Test
|
||||
m3 = 2.0*m3;
|
||||
cout << "m3 = 2.0*m3" << endl << m3;
|
||||
for(int i = 0; i < 4; i++){
|
||||
for(int j = 0; j < 3; j++){
|
||||
m4[i][j] = 2 + i*j;
|
||||
}
|
||||
}
|
||||
cout << "m4:" << endl << m4;
|
||||
Matrix m5(3,3);
|
||||
// Matrix Multiplication Test
|
||||
m5 = m3*m4;
|
||||
cout << "m5 = m3*m4" << endl << m5;
|
||||
// Clear Test
|
||||
m5.clear();
|
||||
cout << "m5.clear()" << endl << m5;
|
||||
|
||||
// Tested for memory leaks using valgrind:
|
||||
// Result: "All heap blocks were freed -- no leaks are possible"
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user