Skip to content

Commit

Permalink
Merge pull request #117 from scidash/optimization
Browse files Browse the repository at this point in the history
Optimization
  • Loading branch information
rgerkin committed Jan 21, 2020
2 parents 1eb4b4f + a9dc805 commit 3b7cd62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions sciunit/suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def __init__(self, tests, name=None, weights=None, include_models=None,
self.name = name if name else "Suite_%d" % random.randint(0, 1e12)
if isinstance(tests, dict):
for key, value in tests.items():
if not isinstance(value, sciunit.Test):
if not isinstance(value, Test):
setattr(self, key, value)
tests = [test for test in tests.values if isinstance(test, sciunit.Test)]
tests = [test for test in tests.values() if isinstance(test, Test)]
self.tests = self.assert_tests(tests)
self.weights_ = [] if not weights else list(weights)
self.include_models = include_models if include_models else []
Expand Down Expand Up @@ -207,13 +207,19 @@ def from_observations(cls, tests_info, name=None):
return cls(tests, name=name)

def __getitem__(self, item):
options = [test for test in self.tests if test.name==item]
if len(options) == 0:
raise KeyError("No test in this suite with name '%s'" % item)
elif len(options) >= 2:
raise KeyError("Multiple tests found in this suite with name '%s'" % item)
test = options[0]
if isinstance(item, int):
test = self.tests[item]
else:
options = [test for test in self.tests if test.name==item]
if len(options) == 0:
raise KeyError("No test in this suite with name '%s'" % item)
elif len(options) >= 2:
raise KeyError("Multiple tests found in this suite with name '%s'" % item)
test = options[0]
return test

def __len__(self):
return len(self.tests)

def __str__(self):
"""Represent the TestSuite instance as a string."""
Expand Down
2 changes: 1 addition & 1 deletion sciunit/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def optimize(self, model):


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

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

0 comments on commit 3b7cd62

Please sign in to comment.