Exemple #1
0
def test_signature(fspec):
    _, sig = Matlab(fspec).generate_auxfun(_NAME, _SPEC)

    assert _TEMPLATE[0].format(
        name=_NAME,
        args=', '.join([str(v) + '__' for v in _SPEC[0]]),
    ) == sig.split('\n')[0]  # FIXME: signature should be single string
Exemple #2
0
def test_pardef_section_for_two_params(fspec):
    fspec.pars = ['p', 'q']
    code, _ = Matlab(fspec).generate_auxfun(_NAME, _SPEC)

    assert '% Parameter definitions' in code
    assert 'p = p_(1);' in code
    assert 'q = p_(2);' in code
Exemple #3
0
    def test_pardef_section_for_two_params(self):
        self.fspec.pars = ['p', 'q']
        code, _ = Matlab(self.fspec).generate_auxfun(self.name, self.spec)

        assert '% Parameter definitions' in code
        assert 'p = p_(1);' in code
        assert 'q = p_(2);' in code
Exemple #4
0
    def test_signature(self):
        _, sig = Matlab(self.fspec).generate_auxfun(self.name, self.spec)

        assert self.template[0].format(
            name=self.name,
            args=', '.join([str(v) + '__' for v in self.spec[0]]),
        ) == sig.split('\n')[0]  # FIXME: signature should be single string
Exemple #5
0
def test_reuseterms_section(fspec):
    spec = (['x', 'y', 'z'], 'xz + y')
    fspec.reuseterms = {'x*z': 'xz'}

    code, _ = Matlab(fspec).generate_auxfun(_NAME, spec)

    assert '% reused term definitions ' in code
    assert 'xz = x__*z__;' in code
    assert 'y_ = xz + y__;' in code
Exemple #6
0
    def test_reuseterms_section(self):
        self.spec = (['x', 'y', 'z'], 'xz + y')
        self.fspec.reuseterms = {'x*z': 'xz'}

        code, _ = Matlab(self.fspec).generate_auxfun(self.name, self.spec)

        assert '% reused term definitions ' in code
        assert 'xz = x__*z__;' in code
        assert 'y_ = xz + y__;' in code
Exemple #7
0
def test_auxfun_value(fspec):
    code, _ = Matlab(fspec).generate_auxfun(_NAME, _SPEC)

    assert 'y_ = x__ * z__ + y__;' in code
Exemple #8
0
def test_reuseterms_section_when_no_reuseterms(fspec):
    code, _ = Matlab(fspec).generate_auxfun(_NAME, _SPEC)

    assert '% reused term definitions ' not in code
Exemple #9
0
def test_pardef_section_for_no_params(fspec):
    fspec.pars = []
    code, _ = Matlab(fspec).generate_auxfun(_NAME, _SPEC)

    # FIXME: do not insert "Parameter definitions" if no par definitions
    assert '% Parameter definitions' in code
Exemple #10
0
def test_intro_comment_follows_signature(fspec):
    code, _ = Matlab(fspec).generate_auxfun(_NAME, _SPEC)

    assert _TEMPLATE[1].format(name=_NAME, specname=fspec.name) in code
    assert _TEMPLATE[2] in code
Exemple #11
0
    def test_auxfun_value(self):
        code, _ = Matlab(self.fspec).generate_auxfun(self.name, self.spec)

        assert 'y_ = x__ * z__ + y__;' in code
Exemple #12
0
    def test_reuseterms_section_when_no_reuseterms(self):
        code, _ = Matlab(self.fspec).generate_auxfun(self.name, self.spec)

        assert '% reused term definitions ' not in code
Exemple #13
0
    def test_pardef_section_for_no_params(self):
        self.fspec.pars = []
        code, _ = Matlab(self.fspec).generate_auxfun(self.name, self.spec)

        # FIXME: do not insert "Parameter definitions" if no par definitions
        assert '% Parameter definitions' in code
Exemple #14
0
    def test_intro_comment_follows_signature(self):
        code, _ = Matlab(self.fspec).generate_auxfun(self.name, self.spec)

        assert self.template[1].format(name=self.name,
                                       specname=self.fspec.name) in code
        assert self.template[2] in code