### Question:
TensorShapeValidation { public static void checkShapeIsSquareMatrix(long[] shape) { if (shape.length < 2) { throw new IllegalArgumentException("Input tensor must be a matrix"); } if (shape[shape.length - 1] != shape[shape.length - 2]) { throw new IllegalArgumentException("Input matrix must be square"); } } private  TensorShapeValidation(); static void checkTensorsMatchNonLengthOneShapeOrAreLengthOne(long[] proposalShape, long[]... shapes); static void checkDimensionExistsInShape(int dimension, long[] shape); static void checkTensorsAreScalar(String message, long[]... shapes); static long[] checkHasOneNonLengthOneShapeOrAllLengthOne(long[]... shapes); static boolean isBroadcastable(long[] left, long[] right); static boolean isBroadcastable(long[] a, long[]... b); static long[] checkTernaryConditionShapeIsValid(long[] predicate, long[] thn, long[] els); static void checkShapeIsSquareMatrix(long[] shape); static void checkShapesMatch(long[] actual, long[] expected); static long[] checkAllShapesMatch(long[]... shapes); static long[] checkAllShapesMatch(String errorMessage, long[]... shapes); static long[] checkAllShapesMatch(String errorMessage, Collection<long[]> shapes); static long[] checkAllShapesMatch(Collection<long[]> shapes); static long[] checkShapesCanBeConcatenated(int dimension, long[]... shapes); static void checkIndexIsValid(long[] shape, long... index); static long[] getMatrixMultiplicationResultingShape(long[] left, long[] right, boolean transposeLeft, boolean transposeRight);  }### Answer:
@Test public void checkSquareMatrixAcceptsSquareMatrices() { TensorShapeValidation.checkShapeIsSquareMatrix(new long[]{3, 3}); }
@Test(expected = IllegalArgumentException.class) public void checkSquareMatrixFailsOnNonSquareMatrices() { TensorShapeValidation.checkShapeIsSquareMatrix(new long[]{3, 2}); }
@Test(expected = IllegalArgumentException.class) public void checkSquareMatrixFailsOnNonSquareBatchMatrices() { TensorShapeValidation.checkShapeIsSquareMatrix(new long[]{3, 3, 2}); }