Commit b350886a authored by Edward Fauchon-Jones's avatar Edward Fauchon-Jones
Browse files

Add mass ordering interfield spec + tests

parent d65acdd9
Pipeline #12445 passed with stage
in 1 minute and 13 seconds
......@@ -60,7 +60,8 @@ format1 = OrderedDict((
("eccentricity", Eccentricity),
("mean_anomaly", MeanAnomaly))))))
format1Interfield = OrderedDict(())
format1Interfield = OrderedDict((
("mass-ordering", MassOrdering),))
format2 = OrderedDict((
('mass1-vs-time', Mass1VsTime),
......
......@@ -430,6 +430,30 @@ class MeanAnomaly(Spec):
dtype = float
class MassOrdering(InterfieldSpec):
"""Specification for the ordering of fields `mass1` and `mass2`"""
name = "mass-ordering"
validMsg = "mass1 >= mass2"
invalidMsg = "mass1 < mass2"
def valid(self, sim):
mass1Valid = Mass1().valid(sim)
mass2Valid = Mass2().valid(sim)
if not isinstance(mass1Valid, err.Valid):
return err.InvalidInterfields(self)
if not isinstance(mass2Valid, err.Valid):
return err.InvalidInterfields(self)
mass1 = sim.att('mass1')
mass2 = sim.att('mass2')
if mass1 >= mass2:
return err.ValidInterfield(self)
else:
return err.InvalidInterfield(self)
# Format 2
class Mass1VsTime(ROMSplineSpec):
"""Specification for the `mass1-vs-time` field"""
......
......@@ -69,6 +69,7 @@ templateOutput = """# Format 1
# Format 1 (Interfield)
- [=] mass-ordering (mass1 >= mass2)
# Format 2
......@@ -604,6 +605,10 @@ class TestMass1(TestField):
self.setOutput(
('- [WRONG TYPE] mass1 (invalid) '
'(Type must be <type \'float\'>)'))
self.setNamedOutput(
'mass-ordering',
('- [INVALID FIELDS] mass-ordering '
'(Field dependencies are invalid)'))
output = helper.lvcnrcheck(['-f', '3', self.f.name])
assert output.strip() == self.output
......@@ -618,6 +623,10 @@ class TestMass2(TestField):
self.setOutput(
('- [WRONG TYPE] mass2 (invalid) '
'(Type must be <type \'float\'>)'))
self.setNamedOutput(
'mass-ordering',
('- [INVALID FIELDS] mass-ordering '
'(Field dependencies are invalid)'))
output = helper.lvcnrcheck(['-f', '3', self.f.name])
assert output.strip() == self.output
......@@ -861,6 +870,49 @@ class TestMeanAnomaly(TestField):
assert output.strip() == self.output
class TestMassOrdering(TestInterfield):
name = 'mass-ordering'
def test_invalid_mass1(self):
self.setOutput(
('- [INVALID FIELDS] mass-ordering '
'(Field dependencies are invalid)'))
self.setNamedField('mass1', 'invalid')
self.setNamedOutput(
'mass1',
('- [WRONG TYPE] mass1 (invalid) '
'(Type must be <type \'float\'>)'))
output = helper.lvcnrcheck(['-f', '3', self.f.name])
assert output.strip() == self.output
def test_invalid_mass2(self):
self.setOutput(
('- [INVALID FIELDS] mass-ordering '
'(Field dependencies are invalid)'))
self.setNamedField('mass2', 'invalid')
self.setNamedOutput(
'mass2',
('- [WRONG TYPE] mass2 (invalid) '
'(Type must be <type \'float\'>)'))
output = helper.lvcnrcheck(['-f', '3', self.f.name])
assert output.strip() == self.output
def test_invalid_ordering(self):
self.setOutput(
('- [INVALID INTERFIELD] mass-ordering '
'(mass1 < mass2)'))
self.setNamedField('mass1', 1.0)
self.setNamedOutput('mass1', '- [=] mass1 (1.0)')
self.setNamedField('mass2', 4.0)
self.setNamedOutput('mass2', '- [=] mass2 (4.0)')
output = helper.lvcnrcheck(['-f', '3', self.f.name])
assert output.strip() == self.output
class TestMass1VsTime(TestROMSpline):
name = 'mass1-vs-time'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment