### Question:
TensorShapeValidation { public static long[] checkHasOneNonLengthOneShapeOrAllLengthOne(long[]... shapes) { Set<TensorShape> nonLengthOneShapes = getNonLengthOneShapes(shapes); List<TensorShape> lengthOneShapes = getLengthOneShapesSortedByRank(shapes); if (nonLengthOneShapes.isEmpty()) { if (!lengthOneShapes.isEmpty()) { return lengthOneShapes.get(0).getShape(); } } else if (nonLengthOneShapes.size() == 1) { return nonLengthOneShapes.iterator().next().getShape(); } throw new IllegalArgumentException("Shapes must match or be length one but were: " + Arrays.stream(shapes) .map(Arrays::toString) .collect(Collectors.joining(",")) ); } 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 suggestSingleNonScalarShape() { long[] shapeProposal = TensorShapeValidation.checkHasOneNonLengthOneShapeOrAllLengthOne(scalar1, twoByTwo1, scalar2); assertArrayEquals(new long[]{2, 2}, shapeProposal); }
@Test public void suggestMatchingNonScalarShape() { long[] shapeProposal = TensorShapeValidation.checkHasOneNonLengthOneShapeOrAllLengthOne(scalar1, twoByTwo1, twoByTwo2); assertArrayEquals(new long[]{2, 2}, shapeProposal); }
@Test public void suggestScalar() { long[] shapeProposal = TensorShapeValidation.checkHasOneNonLengthOneShapeOrAllLengthOne(scalar1, scalar2); assertArrayEquals(Tensor.SCALAR_SHAPE, shapeProposal); }
@Test public void suggestHighestRankLengthOne() { long[] shapeProposal = TensorShapeValidation.checkHasOneNonLengthOneShapeOrAllLengthOne(new long[]{1, 1}, new long[]{1, 1, 1}, new long[]{1}); assertArrayEquals(new long[]{1, 1, 1}, shapeProposal); }
@Test(expected = IllegalArgumentException.class) public void rejectsMultipleNonScalars() { TensorShapeValidation.checkHasOneNonLengthOneShapeOrAllLengthOne(scalar1, twoByThree, twoByTwo1); }