📄 testmatrix.java
字号:
M = B.getMatrix(rowindexset,columnindexset); try { check(SUB,M); try_success("getMatrix(int[],int[])... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"getMatrix(int[],int[])... ","submatrix not successfully retreived"); } } catch ( java.lang.ArrayIndexOutOfBoundsException e ) { errorCount = try_failure(errorCount,"getMatrix(int[],int[])... ","Unexpected ArrayIndexOutOfBoundsException"); }/** Various set methods:**/ try { B.set(B.getRowDimension(),B.getColumnDimension()-1,0.); errorCount = try_failure(errorCount,"set(int,int,double)... ","OutOfBoundsException expected but not thrown"); } catch ( java.lang.ArrayIndexOutOfBoundsException e ) { try { B.set(B.getRowDimension()-1,B.getColumnDimension(),0.); errorCount = try_failure(errorCount,"set(int,int,double)... ","OutOfBoundsException expected but not thrown"); } catch ( java.lang.ArrayIndexOutOfBoundsException e1 ) { try_success("set(int,int,double)... OutofBoundsException... ",""); } } catch ( java.lang.IllegalArgumentException e1 ) { errorCount = try_failure(errorCount,"set(int,int,double)... ","OutOfBoundsException expected but not thrown"); } try { B.set(ib,jb,0.); tmp = B.get(ib,jb); try { check(tmp,0.); try_success("set(int,int,double)... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"set(int,int,double)... ","Matrix element not successfully set"); } } catch ( java.lang.ArrayIndexOutOfBoundsException e1) { errorCount = try_failure(errorCount,"set(int,int,double)... ","Unexpected ArrayIndexOutOfBoundsException"); } M = new Matrix(2,3,0.); try { B.setMatrix(ib,ie+B.getRowDimension()+1,jb,je,M); errorCount = try_failure(errorCount,"setMatrix(int,int,int,int,Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } catch ( java.lang.ArrayIndexOutOfBoundsException e ) { try { B.setMatrix(ib,ie,jb,je+B.getColumnDimension()+1,M); errorCount = try_failure(errorCount,"setMatrix(int,int,int,int,Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } catch ( java.lang.ArrayIndexOutOfBoundsException e1 ) { try_success("setMatrix(int,int,int,int,Matrix)... ArrayIndexOutOfBoundsException... ",""); } } catch ( java.lang.IllegalArgumentException e1 ) { errorCount = try_failure(errorCount,"setMatrix(int,int,int,int,Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } try { B.setMatrix(ib,ie,jb,je,M); try { check(M.minus(B.getMatrix(ib,ie,jb,je)),M); try_success("setMatrix(int,int,int,int,Matrix)... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"setMatrix(int,int,int,int,Matrix)... ","submatrix not successfully set"); } B.setMatrix(ib,ie,jb,je,SUB); } catch ( java.lang.ArrayIndexOutOfBoundsException e1 ) { errorCount = try_failure(errorCount,"setMatrix(int,int,int,int,Matrix)... ","Unexpected ArrayIndexOutOfBoundsException"); } try { B.setMatrix(ib,ie+B.getRowDimension()+1,columnindexset,M); errorCount = try_failure(errorCount,"setMatrix(int,int,int[],Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } catch ( java.lang.ArrayIndexOutOfBoundsException e ) { try { B.setMatrix(ib,ie,badcolumnindexset,M); errorCount = try_failure(errorCount,"setMatrix(int,int,int[],Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } catch ( java.lang.ArrayIndexOutOfBoundsException e1 ) { try_success("setMatrix(int,int,int[],Matrix)... ArrayIndexOutOfBoundsException... ",""); } } catch ( java.lang.IllegalArgumentException e1 ) { errorCount = try_failure(errorCount,"setMatrix(int,int,int[],Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } try { B.setMatrix(ib,ie,columnindexset,M); try { check(M.minus(B.getMatrix(ib,ie,columnindexset)),M); try_success("setMatrix(int,int,int[],Matrix)... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"setMatrix(int,int,int[],Matrix)... ","submatrix not successfully set"); } B.setMatrix(ib,ie,jb,je,SUB); } catch ( java.lang.ArrayIndexOutOfBoundsException e1 ) { errorCount = try_failure(errorCount,"setMatrix(int,int,int[],Matrix)... ","Unexpected ArrayIndexOutOfBoundsException"); } try { B.setMatrix(rowindexset,jb,je+B.getColumnDimension()+1,M); errorCount = try_failure(errorCount,"setMatrix(int[],int,int,Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } catch ( java.lang.ArrayIndexOutOfBoundsException e ) { try { B.setMatrix(badrowindexset,jb,je,M); errorCount = try_failure(errorCount,"setMatrix(int[],int,int,Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } catch ( java.lang.ArrayIndexOutOfBoundsException e1 ) { try_success("setMatrix(int[],int,int,Matrix)... ArrayIndexOutOfBoundsException... ",""); } } catch ( java.lang.IllegalArgumentException e1 ) { errorCount = try_failure(errorCount,"setMatrix(int[],int,int,Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } try { B.setMatrix(rowindexset,jb,je,M); try { check(M.minus(B.getMatrix(rowindexset,jb,je)),M); try_success("setMatrix(int[],int,int,Matrix)... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"setMatrix(int[],int,int,Matrix)... ","submatrix not successfully set"); } B.setMatrix(ib,ie,jb,je,SUB); } catch ( java.lang.ArrayIndexOutOfBoundsException e1 ) { errorCount = try_failure(errorCount,"setMatrix(int[],int,int,Matrix)... ","Unexpected ArrayIndexOutOfBoundsException"); } try { B.setMatrix(rowindexset,badcolumnindexset,M); errorCount = try_failure(errorCount,"setMatrix(int[],int[],Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } catch ( java.lang.ArrayIndexOutOfBoundsException e ) { try { B.setMatrix(badrowindexset,columnindexset,M); errorCount = try_failure(errorCount,"setMatrix(int[],int[],Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } catch ( java.lang.ArrayIndexOutOfBoundsException e1 ) { try_success("setMatrix(int[],int[],Matrix)... ArrayIndexOutOfBoundsException... ",""); } } catch ( java.lang.IllegalArgumentException e1 ) { errorCount = try_failure(errorCount,"setMatrix(int[],int[],Matrix)... ","ArrayIndexOutOfBoundsException expected but not thrown"); } try { B.setMatrix(rowindexset,columnindexset,M); try { check(M.minus(B.getMatrix(rowindexset,columnindexset)),M); try_success("setMatrix(int[],int[],Matrix)... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"setMatrix(int[],int[],Matrix)... ","submatrix not successfully set"); } } catch ( java.lang.ArrayIndexOutOfBoundsException e1 ) { errorCount = try_failure(errorCount,"setMatrix(int[],int[],Matrix)... ","Unexpected ArrayIndexOutOfBoundsException"); }/** Array-like methods: minus minusEquals plus plusEquals arrayLeftDivide arrayLeftDivideEquals arrayRightDivide arrayRightDivideEquals arrayTimes arrayTimesEquals uminus**/ print("\nTesting array-like methods...\n"); S = new Matrix(columnwise,nonconformld); R = Matrix.random(A.getRowDimension(),A.getColumnDimension()); A = R; try { S = A.minus(S); errorCount = try_failure(errorCount,"minus conformance check... ","nonconformance not raised"); } catch ( IllegalArgumentException e ) { try_success("minus conformance check... ",""); } if (A.minus(R).norm1() != 0.) { errorCount = try_failure(errorCount,"minus... ","(difference of identical Matrices is nonzero,\nSubsequent use of minus should be suspect)"); } else { try_success("minus... ",""); } A = R.copy(); A.minusEquals(R); Z = new Matrix(A.getRowDimension(),A.getColumnDimension()); try { A.minusEquals(S); errorCount = try_failure(errorCount,"minusEquals conformance check... ","nonconformance not raised"); } catch ( IllegalArgumentException e ) { try_success("minusEquals conformance check... ",""); } if (A.minus(Z).norm1() != 0.) { errorCount = try_failure(errorCount,"minusEquals... ","(difference of identical Matrices is nonzero,\nSubsequent use of minus should be suspect)"); } else { try_success("minusEquals... ",""); } A = R.copy(); B = Matrix.random(A.getRowDimension(),A.getColumnDimension()); C = A.minus(B); try { S = A.plus(S); errorCount = try_failure(errorCount,"plus conformance check... ","nonconformance not raised"); } catch ( IllegalArgumentException e ) { try_success("plus conformance check... ",""); } try { check(C.plus(B),A); try_success("plus... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"plus... ","(C = A - B, but C + B != A)"); } C = A.minus(B); C.plusEquals(B); try { A.plusEquals(S); errorCount = try_failure(errorCount,"plusEquals conformance check... ","nonconformance not raised"); } catch ( IllegalArgumentException e ) { try_success("plusEquals conformance check... ",""); } try { check(C,A); try_success("plusEquals... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"plusEquals... ","(C = A - B, but C = C + B != A)"); } A = R.uminus(); try { check(A.plus(R),Z); try_success("uminus... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"uminus... ","(-A + A != zeros)"); } A = R.copy(); O = new Matrix(A.getRowDimension(),A.getColumnDimension(),1.0); C = A.arrayLeftDivide(R); try { S = A.arrayLeftDivide(S); errorCount = try_failure(errorCount,"arrayLeftDivide conformance check... ","nonconformance not raised"); } catch ( IllegalArgumentException e ) { try_success("arrayLeftDivide conformance check... ",""); } try { check(C,O); try_success("arrayLeftDivide... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"arrayLeftDivide... ","(M.\\M != ones)"); } try { A.arrayLeftDivideEquals(S); errorCount = try_failure(errorCount,"arrayLeftDivideEquals conformance check... ","nonconformance not raised"); } catch ( IllegalArgumentException e ) { try_success("arrayLeftDivideEquals conformance check... ",""); } A.arrayLeftDivideEquals(R); try { check(A,O); try_success("arrayLeftDivideEquals... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"arrayLeftDivideEquals... ","(M.\\M != ones)"); } A = R.copy(); try { A.arrayRightDivide(S); errorCount = try_failure(errorCount,"arrayRightDivide conformance check... ","nonconformance not raised"); } catch ( IllegalArgumentException e ) { try_success("arrayRightDivide conformance check... ",""); } C = A.arrayRightDivide(R); try { check(C,O); try_success("arrayRightDivide... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"arrayRightDivide... ","(M./M != ones)"); } try { A.arrayRightDivideEquals(S); errorCount = try_failure(errorCount,"arrayRightDivideEquals conformance check... ","nonconformance not raised"); } catch ( IllegalArgumentException e ) { try_success("arrayRightDivideEquals conformance check... ",""); } A.arrayRightDivideEquals(R); try { check(A,O); try_success("arrayRightDivideEquals... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"arrayRightDivideEquals... ","(M./M != ones)"); } A = R.copy(); B = Matrix.random(A.getRowDimension(),A.getColumnDimension()); try { S = A.arrayTimes(S); errorCount = try_failure(errorCount,"arrayTimes conformance check... ","nonconformance not raised"); } catch ( IllegalArgumentException e ) { try_success("arrayTimes conformance check... ",""); } C = A.arrayTimes(B); try { check(C.arrayRightDivideEquals(B),A); try_success("arrayTimes... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"arrayTimes... ","(A = R, C = A.*B, but C./B != A)"); } try { A.arrayTimesEquals(S); errorCount = try_failure(errorCount,"arrayTimesEquals conformance check... ","nonconformance not raised"); } catch ( IllegalArgumentException e ) { try_success("arrayTimesEquals conformance check... ",""); } A.arrayTimesEquals(B); try { check(A.arrayRightDivideEquals(B),R); try_success("arrayTimesEquals... ",""); } catch ( java.lang.RuntimeException e ) { errorCount = try_failure(errorCount,"arrayTimesEquals... ","(A = R, A = A.*B, but A./B != R)"); }/** I/O methods: read print serializable: writeObject readObject**/ print("\nTesting I/O methods...\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -