Esempio n. 1
0
    def test_str_expr_replacement(self):
        # Signature: name(cls, frm, to, expr_string, func_ok=False)
                # replaces all occurences of name 'frm' with 'to' in expr_string
                # ('frm' may not occur as a function name on the rhs) ...
                # 'to' can be an arbitrary string so this function can also be used for
                # argument substitution.
                #
                # Returns the resulting string.
        # from nineml.abstraction_layer.component.util import MathUtil
        t = 'b*c + d/(e*sin(f+g/e)) + b1 + e_ / exp(12*g)'

        t = MathUtil.str_expr_replacement('b', 'B', t)
        self.assertEqual(t, 'B*c + d/(e*sin(f+g/e)) + b1 + e_ / exp(12*g)')

        # 'e' is a builtin, so this function doesn't care.
        t = MathUtil.str_expr_replacement(frm='e', to='E', expr_string=t)
        self.assertEqual(t, 'B*c + d/(E*sin(f+g/E)) + b1 + e_ / exp(12*g)')