def check_lang53(): assert_parsable_to_connected_ndp(""" approx_lower(10, mcdp { provides a [s] requires x [s] requires y [s] x + y >= a })""")
def check_lang12_addition_as_resources(): assert_parsable_to_connected_ndp(""" mcdp { provides a [dimensionless] provides b [dimensionless] requires c [dimensionless] requires d [dimensionless] c + d >= a + b } """)
def check_lang_invplus(): assert_parsable_to_connected_ndp(""" mcdp { provides a [s] requires x [s] requires y [s] x + y >= a }""") s = """ mcdp { provides a [s] requires x [s] requires y [s] requires z [s] x + y * z >= a }""" try: parse_ndp(s) except DPSemanticError as e: if 'Inconsistent units' in str(e): pass else: msg = 'Expected inconsistent unit error.' raise_desc(Exception, msg) else: msg = 'Expected exception' raise_desc(Exception, msg) s = """ mcdp { provides a [s] requires x [s] requires y [hour] x + y >= a }""" try: parse_ndp(s) except DPNotImplementedError as e: pass else: msg = 'Expected DPNotImplementedError' raise_desc(Exception, msg)
def check_lang8_addition(): # x of b == x required by b p = assert_parsable_to_connected_ndp(""" mcdp { provides mission_time [s] provides extra_payload [g] requires total_weight [g] sub battery = instance mcdp { provides capacity [J] requires weight [kg] specific_weight = 1 J/kg weight >= capacity / specific_weight } sub actuation = instance mcdp { provides payload [g] requires power [W] c = 1 W/g power >= c * payload } capacity provided by battery >= mission_time * (power required by actuation) payload provided by actuation >= (weight required by battery) + extra_payload total_weight >= weight required by battery } """) assert_equal(p.get_rnames(), ['total_weight']) assert_equal(p.get_fnames(), ['mission_time', 'extra_payload'])
def check_ignore1(): # TODO: rename assert_parsable_to_connected_ndp(""" mcdp { a = instance mcdp { provides f [s] f <= 10 s } ignore f provided by a } """) assert_parsable_to_connected_ndp(""" mcdp { a = instance mcdp { requires r [s] r >= 10 s } ignore r required by a } """)
def check_variables15(): s = """ mcdp { variable x, y [Nat] variable z [Nat] x + y >= ceil(sqrt(x)) + ceil(sqrt(y)) + z requires x, y provides z } """ assert_parsable_to_connected_ndp(s) s = """ mcdp { requires z [Nat] provides z } """ assert_parsable_to_connected_ndp(s) s = """ mcdp { requires z [Nat] requires y [Nat] provides z, y } """ assert_parsable_to_connected_ndp(s)
def check_variables13(): # TODO: rename check_resources_shortcut4a() s = """ mcdp { provides z [Nat] variable x, y [Nat] x + y >= ceil(sqrt(x)) + ceil(sqrt(y)) + provided z requires x, y } """ assert_parsable_to_connected_ndp(s) s = """ mcdp { provides z [Nat] requires z } """ assert_parsable_to_connected_ndp(s)
def check_lang10_comments(): p = assert_parsable_to_connected_ndp(""" mcdp { provides f [dimensionless] sub hnlin = instance mcdp { provides x [dimensionless] requires r [dimensionless] r >= pow(x, 2) } hnlin.x >= max(f, hnlin.r) } """) assert_equal(p.get_rnames(), []) assert_equal(p.get_fnames(), ['f'])