SHARE
TWEET

bestbruhs

bictoro Sep 19th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         MathMatrix mat1 = new MathMatrix(1, 1, 2);
  2.         int[][] e1 = new int[][] { { 2 } };
  3.         printTestResult(get2DArray(mat1), e1, 1, "Constructor with size and initial val specified.");
  4.  
  5.         // test 2, specify size and values constructor
  6.         mat1 = new MathMatrix(5, 2, -3);
  7.         e1 = new int[][] { { -3, -3 }, { -3, -3 }, { -3, -3 }, { -3, -3 }, { -3, -3 } };
  8.         printTestResult(get2DArray(mat1), e1, 2, "Constructor with size and initial val specified.");
  9.  
  10.         // test 3, deep copy constructor
  11.         int[][] data1 = new int[][] { { 1, 2, 3 }, { 2, 3, 4 }, { 3, 4, 5 } };
  12.         mat1 = new MathMatrix(data1);
  13.         data1[1][1] = 5;
  14.         // alter data1. mat1 should be unchanged if deep copy made
  15.         e1 = new int[][] { { 1, 2, 3 }, { 2, 5, 4 }, { 3, 4, 5 } };
  16.         printTestResult(data1, e1, 3, "constructor with one parameter of type int[][]");
  17.         // data1 altered. mat1 should be unchanged if deep copy made
  18.         e1 = new int[][] { { 1, 2, 3 }, { 2, 3, 4 }, { 3, 4, 5 } };
  19.         printTestResult(get2DArray(mat1), e1, 3,
  20.                 "constructor with one parameter of type int[][]. Testing deep copy made.");
  21.  
  22.         // test 4, deep copy constructor
  23.         data1 = new int[][] { { 0 } };
  24.         mat1 = new MathMatrix(data1);
  25.         data1 = new int[][] { { 1 } };
  26.         // alter data1. mat1 should be unchanged if deep copy made
  27.         e1 = new int[][] { { 1 } };
  28.         printTestResult(data1, e1, 4, "constructor with one parameter of type int[][]");
  29.         // data1 altered. mat1 should be unchanged if deep copy made
  30.         e1 = new int[][] { { 0 } };
  31.         printTestResult(get2DArray(mat1), e1, 4,
  32.                 "constructor with one parameter of type int[][]. Testing deep copy made.");
  33.  
  34.         // test 5, testing getNumRows()
  35.         data1 = new int[][] { { 1, 1, 1, 1, 1, 1 } };
  36.         mat1 = new MathMatrix(data1);
  37.         if (mat1.getNumRows() == 1)
  38.             System.out.println("Passed test 5, getNumRows().");
  39.         else
  40.             System.out.println("Failed test 5, getNumRows().");
  41.  
  42.         // test 6, testing getNumRows()
  43.         data1 = new int[][] { { 1 }, { 0 }, { 0 }, { 0 }, { 0 } };
  44.         mat1 = new MathMatrix(data1);
  45.         if (mat1.getNumRows() == 5)
  46.             System.out.println("Passed test 6, getNumRows().");
  47.         else
  48.             System.out.println("Failed test 6, getNumRows().");
  49.  
  50.         // test 7, testing getNumColumns()
  51.         data1 = new int[][] { { 1, 1, 1, 1, 1, 1 } };
  52.         mat1 = new MathMatrix(data1);
  53.         if (mat1.getNumColumns() == 6)
  54.             System.out.println("Passed test 7, getNumColumns().");
  55.         else
  56.             System.out.println("Failed test 7, getNumColumns().");
  57.  
  58.         // test 8, testing getNumColumns()
  59.         data1 = new int[][] { { 1 }, { 0 }, { 0 }, { 0 }, { 0 } };
  60.         mat1 = new MathMatrix(data1);
  61.         if (mat1.getNumColumns() == 1)
  62.             System.out.println("Passed test 8, getNumColumns().");
  63.         else
  64.             System.out.println("Failed test 8, getNumColumns().");
  65.  
  66.         // test 9, testing getVal()
  67.         if (mat1.getVal(3, 0) == 0)
  68.             System.out.println("Passed test 9, getVal().");
  69.         else
  70.             System.out.println("Failed test 9, getVal().");
  71.  
  72.         // test 10, testing getVal()
  73.         mat1 = new MathMatrix(4, 5, -1000);
  74.         if (mat1.getVal(3, 4) == -1000)
  75.             System.out.println("Passed test 10, getVal()");
  76.         else
  77.             System.out.println("Failed test 10, getVal()");
  78.  
  79.         // test 11, testing add method
  80.         data1 = new int[][] { { 2, 3, 4 }, { 5, 6, 7 }, { 8, 9, 10 } };
  81.         mat1 = new MathMatrix(data1);
  82.         MathMatrix mat2 = new MathMatrix(data1);
  83.         MathMatrix mat3 = mat1.add(mat2);
  84.         e1 = new int[][] { { 4, 6, 8 }, { 10, 12, 14 }, { 16, 18, 20 } };
  85.         printTestResult(get2DArray(mat3), e1, 11, "add method. Testing mat3 correct result.");
  86.  
  87.         // test 12, testing add method
  88.         mat1 = new MathMatrix(data1);
  89.         int[][] data2 = new int[][] { { -2, -3, -4 }, { -5, -6, -7 }, { -8, -9, -10 } };
  90.         mat2 = new MathMatrix(data2);
  91.         mat3 = mat1.add(mat2);
  92.         e1 = new int[][] { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
  93.         printTestResult(get2DArray(mat3), e1, 12, "add method. Testing mat3 correct result.");
  94.  
  95.         // test 13, testing subtract method
  96.         data1 = new int[][] { { 2, 3, 4 }, { 5, 6, 7 }, { 8, 9, 10 } };
  97.         mat1 = new MathMatrix(data1);
  98.         mat2 = new MathMatrix(data1);
  99.         mat3 = mat1.subtract(mat2);
  100.         e1 = new int[][] { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
  101.         printTestResult(get2DArray(mat3), e1, 13, "subtract method. Testing mat3 correct result.");
  102.  
  103.         // test 14, testing subtract method
  104.         mat1 = new MathMatrix(data1);
  105.         data2 = new int[][] { { -2, -3, -4 }, { -5, -6, -7 }, { -8, -9, -10 } };
  106.         mat2 = new MathMatrix(data2);
  107.         mat3 = mat2.subtract(mat1);
  108.         e1 = new int[][] { { -4, -6, -8 }, { -10, -12, -14 }, { -16, -18, -20 } };
  109.         printTestResult(get2DArray(mat3), e1, 14, "subtract method. Testing mat3 correct result.");
  110.  
  111.         // test 15, testing multiplication method
  112.         data1 = new int[][] { { 2, 3, 4, 5 }, { 1, 6, 7, 8 }, { 5, 2, 3, 4 } };
  113.         data2 = new int[][] { { 7, 4, 3 }, { 2, 1, 7 }, { 6, 5, 4 }, { 8, 9, 1 } };
  114.         mat1 = new MathMatrix(data1);
  115.         mat2 = new MathMatrix(data2);
  116.         mat3 = mat1.multiply(mat2);
  117.         e1 = new int[][] { { 84, 76, 48 }, { 125, 117, 81 }, { 89, 73, 45 } };
  118.         printTestResult(get2DArray(mat3), e1, 15, "multiply method. Testing mat3 correct result.");
  119.  
  120.         // test 16, testing multiplication method
  121.         data1 = new int[][] { { 2, 3, 4 }, { 5, 6, 7 }, { 8, 9, 10 }, { 11, 12, 13 } };
  122.         data2 = new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
  123.         mat1 = new MathMatrix(data1);
  124.         mat2 = new MathMatrix(data2);
  125.         mat3 = mat1.multiply(mat2);
  126.         e1 = new int[][] { { 42, 51, 60 }, { 78, 96, 114 }, { 114, 141, 168 }, { 150, 186, 222 } };
  127.         printTestResult(get2DArray(mat3), e1, 16, "multiply method. Testing mat3 correct result.");
  128.  
  129.         // test 17, testing getScaledMatrix()
  130.         mat3 = mat1.getScaledMatrix(100);
  131.         e1 = new int[][] { { 200, 300, 400 }, { 500, 600, 700 }, { 800, 900, 1000 }, { 1100, 1200, 1300 } };
  132.         printTestResult(get2DArray(mat3), e1, 17, "getScaledMatrix method. Testing mat3 correct result.");
  133.  
  134.         // test 18, testing getScaledMatrix()
  135.         data1 = new int[][] { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } };
  136.         mat1 = new MathMatrix(data1);
  137.         mat3 = mat1.getScaledMatrix(0);
  138.         e1 = new int[][] { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
  139.         printTestResult(get2DArray(mat3), e1, 18, "getScaledMatrix method. Testing mat3 correct result.");
  140.  
  141.         // test 19, testing transpose method
  142.         data1 = new int[][] { { 1, 2, 3, 4 }, { 4, 3, 2, 1 } };
  143.         mat1 = new MathMatrix(data1);
  144.         mat2 = mat1.getTranspose();
  145.         e1 = new int[][] { { 1, 4 }, { 2, 3 }, { 3, 2 }, { 4, 1 } };
  146.         printTestResult(get2DArray(mat2), e1, 19, "getTranspose() method. Testing mat3 correct result.");
  147.  
  148.         // test 20, testing transpose method
  149.         data1 = new int[][] { { 1 }, { 2 } };
  150.         mat1 = new MathMatrix(data1);
  151.         mat2 = mat1.getTranspose();
  152.         e1 = new int[][] { { 1, 2 } };
  153.         printTestResult(get2DArray(mat2), e1, 20, "getTranspose() method. Testing mat3 correct result.");
  154.  
  155.         // test 21, testing equals method
  156.         mat1 = new MathMatrix(data1);
  157.         mat2 = new MathMatrix(data1);
  158.         if (mat1.equals(mat2))
  159.             System.out.println("Passed test 21, equals method.");
  160.         else
  161.             System.out.println("Failed test 21, equals method.");
  162.  
  163.         // test 22, testing equals method
  164.         data1 = new int[][] { { 0 } };
  165.         mat1 = new MathMatrix(data1);
  166.         mat2 = new MathMatrix(data2);
  167.         if (!mat1.equals(mat2))
  168.             System.out.println("Passed test 22, equals method.");
  169.         else
  170.             System.out.println("Failed test 22, equals method.");
  171.  
  172.         // test 23, testing toString method
  173.         data1 = new int[][] { { 1, 100, 104, -100000 }, { 1000, 10, 55, 4 }, { 1, -1, 4, 0 } };
  174.         mat1 = new MathMatrix(data1);
  175.         String expected = "|       1     100     104 -100000|\n|    1000      10      55       4|\n|       1      -1       4       0|\n";
  176.         if (mat1.toString().equals(expected))
  177.             System.out.println("passed test 23, toString method.");
  178.         else
  179.             System.out.println("failed test 23, toString method.");
  180.  
  181.         // test 24, testing toString method
  182.         data1 = new int[][] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
  183.         mat1 = new MathMatrix(data1);
  184.         expected = "| 1 2 3|\n| 4 5 6|\n| 7 8 9|\n";
  185.         if (mat1.toString().equals(expected))
  186.             System.out.println("passed test 24, toString method.");
  187.         else
  188.             System.out.println("failed test 24, toString method.");
  189.  
  190.         // test 25, testing isTriangular method
  191.         data1 = new int[][] { { 0 } };
  192.         mat1 = new MathMatrix(data1);
  193.         if (mat1.isUpperTriangular())
  194.             System.out.println("Passed test 25, upperTriangular method.");
  195.         else
  196.             System.out.println("Failed test 25, upperTriangular method");
  197.  
  198.         // test 26, testing isTriangular method
  199.         data1 = new int[][] { { 1, 0 }, { 0, 1 } };
  200.         mat1 = new MathMatrix(data1);
  201.         if (mat1.isUpperTriangular())
  202.             System.out.println("Passed test 26, upperTriangular method.");
  203.         else
  204.             System.out.println("Failed test 26, upperTriangular method");
  205.  
  206.         // test 27, testing isTriangular method
  207.         data1 = new int[][] { { 1, 1, 1 }, { 1, 0, 0 }, { 0, 0, 0 } };
  208.         mat1 = new MathMatrix(data1);
  209.         if (!mat1.isUpperTriangular())
  210.             System.out.println("Passed test 27. upperTriangular method.");
  211.         else
  212.             System.out.println("Failed test 27, upperTriangular method.");
  213.  
  214.         mat1 = new MathMatrix(32213, 32213, 0);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top