### Question:
TensorShapeValidation { public static void checkTensorsMatchNonLengthOneShapeOrAreLengthOne(long[] proposalShape, long[]... shapes) { Set<TensorShape> nonLengthOneShapes = getNonLengthOneShapes(shapes); if (!nonLengthOneShapes.isEmpty()) { boolean moreThanOneNonLengthOneShape = nonLengthOneShapes.size() > 1; if (moreThanOneNonLengthOneShape) { throw new IllegalArgumentException("More than a single non length one shape"); } long[] nonLengthOneShape = nonLengthOneShapes.iterator().next().getShape(); boolean nonLengthOneShapeDoesNotMatchProposal = !Arrays.equals(nonLengthOneShape, proposalShape); if (nonLengthOneShapeDoesNotMatchProposal) { throw new IllegalArgumentException( "Proposed shape " + Arrays.toString(proposalShape) + " does not match other non length one shapes " + Arrays.toString(nonLengthOneShape) ); } } } 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(expected = IllegalArgumentException.class) public void rejectsShapeNotMatchingParent() { TensorShapeValidation.checkTensorsMatchNonLengthOneShapeOrAreLengthOne(new long[]{2, 4}, twoByTwo1, scalar1); }
@Test(expected = IllegalArgumentException.class) public void rejectsMoreThanSingleNonScalarParent() { TensorShapeValidation.checkTensorsMatchNonLengthOneShapeOrAreLengthOne(new long[]{2, 2}, twoByTwo1, twoByThree); }
@Test public void acceptsMatchingParentsShape() { TensorShapeValidation.checkTensorsMatchNonLengthOneShapeOrAreLengthOne(new long[]{2, 2}, twoByTwo1, scalar1); }
@Test public void acceptsNonScalarToScalarParentShape() { TensorShapeValidation.checkTensorsMatchNonLengthOneShapeOrAreLengthOne(new long[]{2, 4}, scalar2, scalar1); }