def test_is_alias(self): # Signature: name(cls, alias_string) # Returns True if the string could be an alias for expr_str, (exp_lhs, exp_rhs) in Aliases: self.assertTrue(Alias.is_alias_str(expr_str)) for expr_str, (exp_dep, exp_indep, exp_rhs) in TimeDerivatives: self.assertFalse(Alias.is_alias_str(expr_str)) for expr_str, (exp_lhs, exp_rhs) in Assignments: self.assertFalse(Alias.is_alias_str(expr_str))
def test_get_prefixed_rhs_string(self): # Signature: name(cls, expr_obj, prefix='', exclude=None) # No Docstring # from nineml.abstraction_layer.component.util import MathUtil e = Alias.from_str("a := b*c + d/(e_*sin(f+g/e_)) + b1 + e_ / exp(12*g)") rhs_sub = MathUtil.get_prefixed_rhs_string(e, prefix="U_", exclude=["c", "e_"]) self.assertEqual(rhs_sub, "U_b*c + U_d/(e_*sin(U_f+U_g/e_)) + U_b1 + e_ / exp(12*U_g)")
def test_get_rhs_substituted(self): # Signature: name(cls, expr_obj, namemap) # No Docstring # from nineml.abstraction_layer.component.util import MathUtil e = Alias.from_str("a := b*c + d/(e*sin(f+g/e)) + b1 + e_ / exp(12*g)") rhs_sub = MathUtil.get_rhs_substituted(e, {"b": "B", "e": "E"}) self.assertEqual(rhs_sub, "B*c + d/(E*sin(f+g/E)) + b1 + e_ / exp(12*g)")
def test_get_prefixed_rhs_string(self): # Signature: name(cls, expr_obj, prefix='', exclude=None) # No Docstring # from nineml.abstraction_layer.component.util import MathUtil e = Alias.from_str('a := b*c + d/(e_*sin(f+g/e_)) + b1 + e_ / exp(12*g)') rhs_sub = MathUtil.get_prefixed_rhs_string(e, prefix='U_', exclude=['c', 'e_']) self.assertEqual( rhs_sub, 'U_b*c + U_d/(e_*sin(U_f+U_g/e_)) + U_b1 + e_ / exp(12*U_g)' )
def test_get_rhs_substituted(self): # Signature: name(cls, expr_obj, namemap) # No Docstring # from nineml.abstraction_layer.component.util import MathUtil e = Alias.from_str('a := b*c + d/(e*sin(f+g/e)) + b1 + e_ / exp(12*g)') rhs_sub = MathUtil.get_rhs_substituted(e, {'b': 'B', 'e': 'E'}) self.assertEqual( rhs_sub, 'B*c + d/(E*sin(f+g/E)) + b1 + e_ / exp(12*g)' )
def test_alias(self): for expr_str, (exp_lhs, exp_rhs) in Aliases: alias = Alias.from_str(expr_str) self.assertEqual(alias.lhs, exp_lhs) self.assertEqual(alias.rhs, exp_rhs)