Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //test 11,
- mat1 = new MathMatrix(3, 3, 5);
- e1 = new int[][] {{5, 5, 5}, {5, 5, 5}, {5, 5, 5}};
- printTestResult( get2DArray(mat1), e1, 11, "Constructor with size and initial val specified.");
- //tests 12 and 13, int[][] constructor, deep copy
- data1 = new int[][] {{1, 2, 3, 0}, {0, 3, 2, 3}, {0, 0, 4, -1}, {1, 2, 3, 4}};
- mat1 = new MathMatrix( data1 );
- data1[0][0] = 20;
- // alter data1. mat1 should be unchanged if deep copy made
- e1 = new int[][] {{20, 2, 3, 0}, {0, 3, 2, 3}, {0, 0, 4, -1}, {1, 2, 3, 4}};
- printTestResult( data1, e1, 12, "constructor with one parameter of type int[][]");
- // data1 altered. mat1 should be unchanged if deep copy made
- e1 = new int[][] {{1, 2, 3, 0}, {0, 3, 2, 3}, {0, 0, 4, -1}, {1, 2, 3, 4}};
- printTestResult( get2DArray(mat1), e1, 13, "constructor with one parameter of type int[][]. Testing deep copy made.");
- //tests 14 - 16, addition
- data1[0][0] = 1;
- mat1 = new MathMatrix(new int[][]{{6, 20, 5, 2}, {1, 4, 7, 6}});
- mat2 = new MathMatrix(new int[][]{{20, -4, 6, 2}, {1, 3, 4, 2}});
- mat3 = mat1.add(mat2);
- e1 = new int[][]{{6, 20, 5, 2}, {1, 4, 7, 6}};
- printTestResult( get2DArray(mat1), e1, 14, "add method. Testing mat1 unchanged.");
- e1 = new int[][]{{20, -4, 6, 2}, {1, 3, 4, 2}};
- printTestResult( get2DArray(mat2), e1, 15, "add method. Testing mat2 unchanged.");
- e1 = new int[][] { {26, 16, 11, 4}, {2, 7, 11, 8} };
- printTestResult( get2DArray(mat3), e1, 16, "add method. Testing mat3 correct result.");
- //test 17, multiplication
- data1 = new int[][] { {6, 4, 1}, {3, 9, 1} };
- data2 = new int[][] { {1, 2}, {3, 1}, {2, 1} };
- mat2 = new MathMatrix(data2);
- mat1 = new MathMatrix(data1);
- mat3 = mat2.multiply(mat1);
- e1 = new int[][] { {12, 22, 3}, {21, 21, 4}, {15, 17, 3} };
- printTestResult( get2DArray(mat3), e1, 17, "multiply method");
- //test 18, toString()
- data1 = new int[][] {{6, 85, 91, 15},
- {23, 0, 6, 5}};
- mat1 = new MathMatrix(data1);
- expected = " 6 85 91 15\n 23 0 6 5\n";
- if( mat1.toString().equals( expected ) )
- System.out.println("passed test 18, toString method.");
- else
- System.out.println("failed test 18, toString method.");
- //test 19, upperTriangular
- data1 = new int[][] {{6, 2, 3, 91}, {0, 3, 2, 3}, {0, 0, 4, -1}, {0, 1, 0, 12}};
- mat1 = new MathMatrix(data1);
- if( !mat1.isUpperTriangular())
- System.out.println("Passed test 19, upperTriangular method.");
- else
- System.out.println("Failed test 19, upperTriangular method.");
- //test 20, changeElement test
- mat1.changeElement(3, 1, 0);
- expected = " 6 2 3 91\n 0 3 2 3\n 0 0 4 -1\n 0 0 0 12\n";
- if(expected.equals(mat1.toString()))
- System.out.println("Passed test 20, changeElement method");
- else
- System.out.println("Failed test 20, changeElement method");
- //test 21, numCols method
- if(mat1.numCols()==4)
- System.out.println("Passed test 21, numCols method");
- else
- System.out.println("Failed test 21, numCols method");
- //test 22, numRows method
- if(mat1.numRows()==4)
- System.out.println("Passed test 22, numRows method");
- else
- System.out.println("Failed test 22, numRows method");
- //test 23, getVal
- if(mat1.getVal(2, 2)==4)
- System.out.println("Passed test 23, getVal method");
- else
- System.out.println("Failed test 22, getVal method");
- //test 24, subtraction
- mat1 = new MathMatrix(3, 2, 0);
- mat3 = mat2.subtract(mat2);
- if(mat1.equals(mat3))
- System.out.println("Passed test 24, subtract method");
- else
- System.out.println("Failed test 24, subtract method");
- //test 25, equals
- mat1 = new MathMatrix(4, 4, 4);
- mat2 = new MathMatrix(4, 4, 4);
- if(mat1.equals(mat2))
- System.out.println("Passed test 25, equals method");
- else
- System.out.println("Failed test 25, equals method");
- //test 26, equals
- mat1 = new MathMatrix(4, 4, 4);
- mat2 = new MathMatrix(5, 5, 4);
- if(!mat1.equals(mat2))
- System.out.println("Passed test 25, equals method");
- else
- System.out.println("Failed test 25, equals method");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement