How to use the sciunit.capabilities.ProducesNumber function in sciunit

To help you get started, we’ve selected a few sciunit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scidash / sciunit / sciunit / unit_test / core_tests.py View on Github external
def test_capabilities(self):
        from sciunit import Model
        from sciunit.capabilities import ProducesNumber
        from sciunit.models import Model,UniqueRandomNumberModel,\
                                         RepeatedRandomNumberModel

        class MyModel(Model,ProducesNumber): 
            def produce_number(self):
                return 3.14
        m = MyModel()
        self.assertEqual(m.produce_number(),3.14)
        
        m = UniqueRandomNumberModel()
        self.assertNotEqual(m.produce_number(),m.produce_number())

        m = RepeatedRandomNumberModel()
        self.assertEqual(m.produce_number(),m.produce_number())
github scidash / sciunit / sciunit / unit_test / model_tests.py View on Github external
def test_capabilities(self):
        from sciunit import Model
        from sciunit.capabilities import ProducesNumber
        from sciunit.models import Model
        from sciunit.models.examples import UniqueRandomNumberModel,\
            RepeatedRandomNumberModel

        class MyModel(Model,ProducesNumber):
            def produce_number(self):
                return 3.14
        m = MyModel()
        self.assertEqual(m.produce_number(),3.14)

        m = UniqueRandomNumberModel()
        self.assertNotEqual(m.produce_number(),m.produce_number())

        m = RepeatedRandomNumberModel()
        self.assertEqual(m.produce_number(),m.produce_number())
github scidash / sciunit / sciunit / unit_test / core_tests.py View on Github external
def __init__(self, observation=None, name="ValueTest-M2M"):
                sciunit.TestM2M.__init__(self,observation,name)
                self.required_capabilities += (ProducesNumber,)
github scidash / sciunit / sciunit / unit_test / model_tests.py View on Github external
def test_get_model_capabilities(self):
        from sciunit.capabilities import ProducesNumber

        m = self.M(2, 3)
        self.assertEqual(m.capabilities, [ProducesNumber])
github scidash / sciunit / sciunit / tests.py View on Github external
"""
    # TODO: see if this needs to be updated and provided:
    def optimize(self, model):
        raise NotImplementedError(("Optimization not implemented "
                                   "for Test '%s'" % self))
    """


class RangeTest(Test):
    """Test if the model generates a number within a certain range"""

    def __init__(self, observation, name=None):
        super(RangeTest, self).__init__(observation, name=name)

    required_capabilities = (ProducesNumber,)
    score_type = BooleanScore

    def validate_observation(self, observation):
        assert type(observation) in (tuple, list, set)
        assert len(observation) == 2
        assert observation[1] > observation[0]

    def generate_prediction(self, model):
        return model.produce_number()

    def compute_score(self, observation, prediction):
        low = observation[0]
        high = observation[1]
        return self.score_type(low < prediction < high)
github scidash / sciunit / sciunit / unit_test / test_tests.py View on Github external
def __init__(self, observation=None, name="ValueTest-M2M"):
                TestM2M.__init__(self,observation,name)
                self.required_capabilities += (ProducesNumber,)