Example #1
0
    def interval_validity_test(self):
        """Test if BaseMethod handles parameter validity correctly."""
        parameters = ["param1", "param2", "param3", "param4"]

        b = BaseMethod(parameters)

        # overwrite parameter validity dictionary for testing
        b._parameterIntervals = {
            "param1": [0.0, 1.0, False, False],
            "param2": [0.0, 1.0, False, True],
            "param3": [0.0, 1.0, True, False],
            "param4": [0.0, 1.0, True, True]
        }

        # definetely invalid parameters
        for value in [-1.5, 3.2]:
            for parameter in parameters:
                if b._in_valid_interval(parameter, value):
                    assert False  # pragma: no cover

        # definetly valid parameters
        for value in [0.3, 0.42]:
            for parameter in parameters:
                if not b._in_valid_interval(parameter, value):
                    assert False  # pragma: no cover
Example #2
0
    def value_error_message_test(self):
        """Test the value error message."""
        parameters = ["param1", "param2", "param3", "param4"]

        b = BaseMethod(parameters)

        # overwrite parameter validity dictionary for testing
        b._parameterIntervals = {
            "param1": [0.0, 1.0, False, False],
            "param2": [0.0, 1.0, False, True],
            "param3": [0.0, 1.0, True, False],
            "param4": [0.0, 1.0, True, True]
        }

        # Unknown parameters should return no message
        if None != b._get_value_error_message_for_invalid_prarameter(
                "unknown", 0.0):
            assert False  # pragma: no cover

        # Known parameters should return a message
        for parameter in parameters:
            if not isinstance(
                    b._get_value_error_message_for_invalid_prarameter(
                        parameter, 0.4), basestring):
                assert False  # pragma: no cover
Example #3
0
    def interval_validity_test(self):
        """Test if BaseMethod handles parameter validity correctly."""
        parameters = ["param1", "param2", "param3", "param4"]

        b = BaseMethod(parameters)

        # overwrite parameter validity dictionary for testing
        b._parameterIntervals = {
            "param1": [0.0, 1.0, False, False],
            "param2": [0.0, 1.0, False, True],
            "param3": [0.0, 1.0, True, False],
            "param4": [0.0, 1.0, True, True]
        }

        # definetely invalid parameters
        for value in [-1.5, 3.2]:
            for parameter in parameters:
                if b._in_valid_interval(parameter, value):
                    assert False    # pragma: no cover

        # definetly valid parameters
        for value in [0.3, 0.42]:
            for parameter in parameters:
                if not b._in_valid_interval(parameter, value):
                    assert False    # pragma: no cover
Example #4
0
    def get_interval_test(self):
        """Test if correct intervals are returned."""
        parameters = ["param1", "param2", "param3", "param4"]

        b = BaseMethod(parameters)

        # overwrite parameter validity dictionary for testing
        parameterIntervals = {
            "param1": [0.0, 1.0, False, False],
            "param2": [0.0, 1.0, False, True],
            "param3": [0.0, 1.0, True, False],
            "param4": [0.0, 1.0, True, True]
        }
        b._parameterIntervals = parameterIntervals

        for parameter in parameters:
            i = b.get_interval(parameter)
            if not i == parameterIntervals[parameter]:
                raise AssertionError  # pragma: no cover

        assert None == b.get_interval("unknown")
Example #5
0
    def get_interval_test(self):
        """Test if correct intervals are returned."""
        parameters = ["param1", "param2", "param3", "param4"]

        b = BaseMethod(parameters)

        # overwrite parameter validity dictionary for testing
        parameterIntervals = {
            "param1": [0.0, 1.0, False, False],
            "param2": [0.0, 1.0, False, True],
            "param3": [0.0, 1.0, True, False],
            "param4": [0.0, 1.0, True, True]
        }
        b._parameterIntervals = parameterIntervals

        for parameter in parameters:
            i = b.get_interval(parameter)
            if not i == parameterIntervals[parameter]:
                raise AssertionError    # pragma: no cover

        assert None == b.get_interval("unknown")
Example #6
0
    def value_error_message_test(self):
        """Test the value error message."""
        parameters = ["param1", "param2", "param3", "param4"]

        b = BaseMethod(parameters)

        # overwrite parameter validity dictionary for testing
        b._parameterIntervals = {
            "param1": [0.0, 1.0, False, False],
            "param2": [0.0, 1.0, False, True],
            "param3": [0.0, 1.0, True, False],
            "param4": [0.0, 1.0, True, True]
        }

        # Unknown parameters should return no message
        if None != b._get_value_error_message_for_invalid_prarameter("unknown", 0.0):
            assert False    # pragma: no cover

        # Known parameters should return a message
        for parameter in parameters:
            if not isinstance(b._get_value_error_message_for_invalid_prarameter(parameter, 0.4), basestring):
                assert False    # pragma: no cover