[docs]classValidCombination(ValidationModel[Tuple[int,...]]):""" A ValidationModel that validates a combination of dots in a game. Attributes: n_of_dots (int): The number of dots in the combination. n_of_colors (int): The number of colors available for the dots. """def__init__(self,number_of_dots:int,number_of_colors:int)->None:""" Initializes the ValidCombination with the number of dots and colors. """self.convert=lambdavalue:GameValidationUtils.convert(value)self.validate_arguments=lambda:GameValidationUtils.validate_arguments(self)super().__init__(n_of_dots=number_of_dots,n_of_colors=number_of_colors,)
[docs]defvalidate_value(self,value:Any)->Tuple[int,...]:""" Validates the given combination and returns the validated combination. Args: value (Any): The combination to be validated. Returns: Tuple[int, ...]: The validated combination. Raises: TypeValidationError: If the combination is not a tuple or list of integers. RangeError: If the combination does not have the correct number of dots or the dot values are not within the valid range. """ifisinstance(value,str):value=self.convert(value)ifnotisinstance(value,(tuple,list)):raiseTypeValidationError("A combination must be a tuple or list of integers")iflen(value)!=self.n_of_dots:raiseRangeError(f"Combination must have {self.n_of_dots} dots")GameValidationUtils.validate_integer_range(value,1,self.n_of_colors)returntuple(value)