All files / tools/src/stateManagement/segmentation/helpers validateSegmentationInput.ts

0% Statements 0/9
0% Branches 0/10
0% Functions 0/2
0% Lines 0/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                                                                                             
import * as Enums from '../../../enums';
import type { SegmentationPublicInput } from '../../../types/SegmentationStateTypes';
import { validatePublic as validatePublicLabelmap } from '../../../utilities/segmentation/validateLabelmap';
 
/**
 * Validates the given segmentationInputArray to ensure it contains
 * appropriate representationProps for the representation type being used.
 *
 * @param segmentationInputArray - Array of segmentation inputs
 * @throws If the segmentationInputArray is undefined or empty
 * @throws If the segmentationInput.segmentationId is undefined
 * @throws If the segmentationInput.representation is undefined
 * @internal
 */
function validateSegmentationInput(
  segmentationInputArray: SegmentationPublicInput[]
): void {
  if (!segmentationInputArray || segmentationInputArray.length === 0) {
    throw new Error(
      'The segmentationInputArray is undefined or an empty array'
    );
  }
 
  segmentationInputArray.forEach((segmentationInput) => {
    if (segmentationInput.segmentationId === undefined) {
      throw new Error(
        'Undefined segmentationInput.segmentationId. Please provide a valid segmentationId'
      );
    }
 
    if (segmentationInput.representation === undefined) {
      throw new Error(
        'Undefined segmentationInput.representation. Please provide a valid representation'
      );
    }
 
    if (
      segmentationInput.representation.type ===
      Enums.SegmentationRepresentations.Labelmap
    ) {
      validatePublicLabelmap(segmentationInput);
    }
  });
}
 
export default validateSegmentationInput;