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(StrToExpr.is_alias(expr_str)) for expr_str, (exp_dep, exp_indep, exp_rhs) in TimeDerivatives: self.assertFalse(StrToExpr.is_alias(expr_str)) for expr_str, (exp_lhs, exp_rhs) in Assignments: self.assertFalse(StrToExpr.is_alias(expr_str))
def test_state_assignment(self): # Signature: name(cls, state_assignment_string) # No Docstring for expr_str, (exp_lhs, exp_rhs) in Assignments: ass = StrToExpr.state_assignment(expr_str) self.assertEqual(ass.lhs, exp_lhs) self.assertEqual(ass.rhs, exp_rhs)
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 = StrToExpr.alias("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 = StrToExpr.alias("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_time_derivative(self): # Signature: name(cls, time_derivative_string) # Creates an TimeDerivative object from a string for expr_str, (exp_dep, exp_indep, exp_rhs) in TimeDerivatives: td = StrToExpr.time_derivative(expr_str) self.assertEquals(td.dependent_variable, exp_dep) self.assertEquals(td.independent_variable, exp_indep) self.assertEquals(td.rhs, exp_rhs)
def test_alias(self): for expr_str, (exp_lhs, exp_rhs) in Aliases: alias = StrToExpr.alias(expr_str) self.assertEqual(alias.lhs, exp_lhs) self.assertEqual(alias.rhs, exp_rhs)