Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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())
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())
def __init__(self, observation=None, name="ValueTest-M2M"):
sciunit.TestM2M.__init__(self,observation,name)
self.required_capabilities += (ProducesNumber,)
def test_get_model_capabilities(self):
from sciunit.capabilities import ProducesNumber
m = self.M(2, 3)
self.assertEqual(m.capabilities, [ProducesNumber])
"""
# 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)
def __init__(self, observation=None, name="ValueTest-M2M"):
TestM2M.__init__(self,observation,name)
self.required_capabilities += (ProducesNumber,)