def is_valid(cls, value): """Method validates the input value 'n' for Factorial Args: value (int): Positive integer value. Returns: int: if value is valid otherwise raises an exception. """ is_valid_input("n", value, config.FACTORIAL_MAX_VALUE) return value
def n_is_valid(cls, value): """Method validates the input value 'n' for Fibonacci s Args: value (int): Positive integer value. Returns: int: if value is valid otherwise raises an exception. """ is_valid_input("n", value, config.FIBONACCI_MAX_VALUE) return value
def is_valid(cls, values): """Method validates the input values 'm' and 'n' for Ackermann Args: value (AckermannValues): object of type AckermannValues Returns: AckermannValues: if both values are valid otherwise raises an exception. """ m, n = values.m, values.n is_valid_input("m", m, config.ACKERMANN_M_MAX) n_max_val = config.ACKERMANN_LIMITS["m"][m]["n"]["max"] is_valid_input("n", n, n_max_val) return values
def test_validator_with_invalid_data(): """Function tests validator with invalid data 1. Non-integer value 2. where n is a negative number 3. where n exceeds the max allowed value. """ with pytest.raises(HTTPException): is_valid_input("x", "string", 10) with pytest.raises(HTTPException): is_valid_input("x", -1, 10) with pytest.raises(HTTPException): is_valid_input("x", 11, 10)
def test_validator_with_valid_data(): """Function tests validator with valid data""" assert is_valid_input("x", 5, 10) == True