import structure.*;

public class MatrixTest 
{
    public static void main(String args[])
    {    
    
    	int row_id,col_id,val;
    	Matrix ret_mat;
    	
    	//create an array of arrays to bet copied into the matrix
		int[][] test = new int[][]{new int[]{1,-3,0,-1,0},
					   new int[]{0,0,-2,0,3},
					   new int[]{2,0,0,0,0},
					   new int[]{0,4,0,-4,0},					   					   
					   new int[]{5,0,-5,0,6}};
	
		//******** Test constructor 1, set, height and width method  *******/
		
		//create the matrix --- test constructor(int r, int c) 		
		SparseMatrix sparse_mat = new SparseMatrix(test.length, 
													test[0].length);
													
		System.out.print("The sparse matrix has "+sparse_mat.height()+" rows and "
							+ sparse_mat.width()+" columns.\n\n");													
				
		//copy the 2-d array into the matrix --- test "set" method
		for(int i = 0; i < test.length; i++)
		{
		    for(int j = 0; j < test[0].length; j++)
		    {	
				sparse_mat.set(i,j,new Integer(test[i][j]));								
		    }
		}
				
		//print out Vectors in sparse_mat
		System.out.print(sparse_mat.dump());						
		row_id = 0; col_id = 4; val= 88;
		//(row 0 col 4: change zero to non-zero)  				
		sparse_mat.set(row_id,col_id,(new Integer(val)));
		System.out.print("\nseting ("+row_id+','+col_id+") to "+val+": \n"+sparse_mat.dump());
		
		row_id = 1; col_id = 2; val = 0;
		//(row 1 col 2: change non-zero to zero)  				
		sparse_mat.set(row_id,col_id,(new Integer(val)));				
		System.out.print("\nseting ("+row_id+','+col_id+") to "+val+": \n");		
		
		row_id = 4; col_id = 2; val = 0;
		sparse_mat.set(4,2,(new Integer(0))); //no non-zero in column 2 now		
		System.out.print("\nseting ("+row_id+','+col_id+") to "+val+": \n"+sparse_mat.dump());
				
		row_id = 0; col_id = 1; val = 88;		
		//(row 0 col 1: chage non-zero to another non-zero)
		sparse_mat.set(row_id,col_id,(new Integer(val)));
		System.out.print("\nseting ("+row_id+','+col_id+") to "+val+": \n"+sparse_mat.dump());
		
		row_id = 2; col_id = 2; val = 0;
		//(row 2 col 2: chage zero to zero)
		sparse_mat.set(row_id,col_id,(new Integer(val)));
		//print out Vectors in sparse_mat
		System.out.print("\nseting ("+row_id+','+col_id+") to "+val+": \n"+sparse_mat.dump());
		
		// Now the matrix becomes
		//	1	88	0	-1	88
		//	0	0	0	0	3
		//	2	0	0	0	0
		//	0	4	0	-4	0
		//	5	0	0	0	6		
			
    	
    	//****************** Test get method *************************		
		System.out.print("\n"+sparse_mat.print()); 	
					
		//****************** Test addCol method *************************
		col_id = 4;
		sparse_mat.addCol(col_id);
		System.out.print("\n\nResult from addCol("+col_id+"):\n");		
		System.out.print("\n"+sparse_mat.dump());		
		System.out.print("\n"+sparse_mat.print());					
		
	
		//****************** Test addRow method *************************				
		row_id = 2;
		sparse_mat.addRow(row_id);
		System.out.print("\n\nResult from addRow("+row_id+"):\n");		
		System.out.print("\n"+sparse_mat.dump());		
		System.out.print("\n"+sparse_mat.print());					
			
			
		//*************** Test the constructor with Matrix input**************
		Matrix mat = new Matrix(test.length, test[0].length);
				
		//copy the 2-d array into the matrix --- test "set" method
		for(int i = 0; i < test.length; i++)
		{
		    for(int j = 0; j < test[0].length; j++)
		    {		    	
					mat.set(i,j,new Integer(test[i][j]));								
		    }
		}	
		
		sparse_mat = new SparseMatrix(mat);	
		System.out.print("Testing constructor with a Matrix object\n"+sparse_mat.dump());		
		System.out.print("\n"+sparse_mat.print());								
   	}
}
