Skip to content

ValueTypeValidator class

This class has two static methods to validate if a given "float" or "int" number is a valid binary or integer number.

Source code in pyorlib/validators/value_type_validator.py
class ValueTypeValidator:
    """
    This class has two static methods to validate if a
    given "float" or "int" number is a valid binary or
    integer number.
    """

    @staticmethod
    def is_binary(num: float | int) -> bool:
        """
        This method checks if the given float/int number is binary or not.
        :param num: float/int number to be checked
        :return: True if the given float/int number is binary else False
        """
        return num is not None and num in [0, 1]

    @staticmethod
    def is_integer(num: float | int) -> bool:
        """
        This method checks if the given float/int number is a valid integer or not.
        :param num: float/int number to be checked
        :return: True if the given float/int number is an integer else False
        """
        return num is not None and (num == inf or num == -inf or isinstance(num, int) or float(num).is_integer())

Functions

is_binary staticmethod

is_binary(num: float | int) -> bool

This method checks if the given float/int number is binary or not.

PARAMETER DESCRIPTION
num

float/int number to be checked

TYPE: float | int

RETURNS DESCRIPTION
bool

True if the given float/int number is binary else False

Source code in pyorlib/validators/value_type_validator.py
@staticmethod
def is_binary(num: float | int) -> bool:
    """
    This method checks if the given float/int number is binary or not.
    :param num: float/int number to be checked
    :return: True if the given float/int number is binary else False
    """
    return num is not None and num in [0, 1]

is_integer staticmethod

is_integer(num: float | int) -> bool

This method checks if the given float/int number is a valid integer or not.

PARAMETER DESCRIPTION
num

float/int number to be checked

TYPE: float | int

RETURNS DESCRIPTION
bool

True if the given float/int number is an integer else False

Source code in pyorlib/validators/value_type_validator.py
@staticmethod
def is_integer(num: float | int) -> bool:
    """
    This method checks if the given float/int number is a valid integer or not.
    :param num: float/int number to be checked
    :return: True if the given float/int number is an integer else False
    """
    return num is not None and (num == inf or num == -inf or isinstance(num, int) or float(num).is_integer())