Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. //test 11,
  2. mat1 = new MathMatrix(3, 3, 5);
  3. e1 = new int[][] {{5, 5, 5}, {5, 5, 5}, {5, 5, 5}};
  4. printTestResult( get2DArray(mat1), e1, 11, "Constructor with size and initial val specified.");
  5.  
  6. //tests 12 and 13, int[][] constructor, deep copy
  7. data1 = new int[][] {{1, 2, 3, 0}, {0, 3, 2, 3}, {0, 0, 4, -1}, {1, 2, 3, 4}};
  8. mat1 = new MathMatrix( data1 );
  9. data1[0][0] = 20;
  10. // alter data1. mat1 should be unchanged if deep copy made
  11. e1 = new int[][] {{20, 2, 3, 0}, {0, 3, 2, 3}, {0, 0, 4, -1}, {1, 2, 3, 4}};
  12. printTestResult( data1, e1, 12, "constructor with one parameter of type int[][]");
  13. // data1 altered. mat1 should be unchanged if deep copy made
  14. e1 = new int[][] {{1, 2, 3, 0}, {0, 3, 2, 3}, {0, 0, 4, -1}, {1, 2, 3, 4}};
  15. printTestResult( get2DArray(mat1), e1, 13, "constructor with one parameter of type int[][]. Testing deep copy made.");
  16.  
  17. //tests 14 - 16, addition
  18. data1[0][0] = 1;
  19. mat1 = new MathMatrix(new int[][]{{6, 20, 5, 2}, {1, 4, 7, 6}});
  20. mat2 = new MathMatrix(new int[][]{{20, -4, 6, 2}, {1, 3, 4, 2}});
  21. mat3 = mat1.add(mat2);
  22. e1 = new int[][]{{6, 20, 5, 2}, {1, 4, 7, 6}};
  23. printTestResult( get2DArray(mat1), e1, 14, "add method. Testing mat1 unchanged.");
  24. e1 = new int[][]{{20, -4, 6, 2}, {1, 3, 4, 2}};
  25. printTestResult( get2DArray(mat2), e1, 15, "add method. Testing mat2 unchanged.");
  26. e1 = new int[][] { {26, 16, 11, 4}, {2, 7, 11, 8} };
  27. printTestResult( get2DArray(mat3), e1, 16, "add method. Testing mat3 correct result.");
  28.  
  29. //test 17, multiplication
  30. data1 = new int[][] { {6, 4, 1}, {3, 9, 1} };
  31. data2 = new int[][] { {1, 2}, {3, 1}, {2, 1} };
  32. mat2 = new MathMatrix(data2);
  33. mat1 = new MathMatrix(data1);
  34. mat3 = mat2.multiply(mat1);
  35. e1 = new int[][] { {12, 22, 3}, {21, 21, 4}, {15, 17, 3} };
  36. printTestResult( get2DArray(mat3), e1, 17, "multiply method");
  37.  
  38. //test 18, toString()
  39. data1 = new int[][] {{6, 85, 91, 15},
  40. {23, 0, 6, 5}};
  41. mat1 = new MathMatrix(data1);
  42. expected = " 6 85 91 15\n 23 0 6 5\n";
  43. if( mat1.toString().equals( expected ) )
  44. System.out.println("passed test 18, toString method.");
  45. else
  46. System.out.println("failed test 18, toString method.");
  47.  
  48. //test 19, upperTriangular
  49. data1 = new int[][] {{6, 2, 3, 91}, {0, 3, 2, 3}, {0, 0, 4, -1}, {0, 1, 0, 12}};
  50. mat1 = new MathMatrix(data1);
  51. if( !mat1.isUpperTriangular())
  52. System.out.println("Passed test 19, upperTriangular method.");
  53. else
  54. System.out.println("Failed test 19, upperTriangular method.");
  55.  
  56. //test 20, changeElement test
  57. mat1.changeElement(3, 1, 0);
  58. expected = " 6 2 3 91\n 0 3 2 3\n 0 0 4 -1\n 0 0 0 12\n";
  59. if(expected.equals(mat1.toString()))
  60. System.out.println("Passed test 20, changeElement method");
  61. else
  62. System.out.println("Failed test 20, changeElement method");
  63.  
  64. //test 21, numCols method
  65. if(mat1.numCols()==4)
  66. System.out.println("Passed test 21, numCols method");
  67. else
  68. System.out.println("Failed test 21, numCols method");
  69.  
  70. //test 22, numRows method
  71. if(mat1.numRows()==4)
  72. System.out.println("Passed test 22, numRows method");
  73. else
  74. System.out.println("Failed test 22, numRows method");
  75.  
  76. //test 23, getVal
  77. if(mat1.getVal(2, 2)==4)
  78. System.out.println("Passed test 23, getVal method");
  79. else
  80. System.out.println("Failed test 22, getVal method");
  81.  
  82. //test 24, subtraction
  83. mat1 = new MathMatrix(3, 2, 0);
  84. mat3 = mat2.subtract(mat2);
  85. if(mat1.equals(mat3))
  86. System.out.println("Passed test 24, subtract method");
  87. else
  88. System.out.println("Failed test 24, subtract method");
  89.  
  90. //test 25, equals
  91. mat1 = new MathMatrix(4, 4, 4);
  92. mat2 = new MathMatrix(4, 4, 4);
  93. if(mat1.equals(mat2))
  94. System.out.println("Passed test 25, equals method");
  95. else
  96. System.out.println("Failed test 25, equals method");
  97.  
  98. //test 26, equals
  99. mat1 = new MathMatrix(4, 4, 4);
  100. mat2 = new MathMatrix(5, 5, 4);
  101. if(!mat1.equals(mat2))
  102. System.out.println("Passed test 25, equals method");
  103. else
  104. System.out.println("Failed test 25, equals method");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement