File: test_guess.py

package info (click to toggle)
fityk 1.3.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 3,784 kB
  • sloc: cpp: 34,396; ansic: 4,673; python: 971; makefile: 366; sh: 117; java: 31; ruby: 27; perl: 25; xml: 16
file content (44 lines) | stat: -rwxr-xr-x 1,398 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python

import os
import sys
import math
import unittest
import fityk

class TestGuessability(unittest.TestCase):
    def setUp(self):
        xx = [(n-5)/2. for n in range(25)]
        yy = [11.2/(1+(x-3.3)**2) + math.sin(40*x)/40 - x/10. for x in xx]
        self.ftk = fityk.Fityk()
        self.ftk.set_option_as_number("verbosity", -1)
        self.ftk.load_data(0, xx, yy, [1]*len(xx), "loren")
        #self.ftk.execute("info state > debug.fit")

def create_guessability_test(func_type):
    def do_test(self):
        self.ftk.execute("guess %f = " + func_type)
        f = self.ftk.get_function('f')
        self.assertIsInstance(f, fityk.Func)
        self.assertEqual(f.get_template_name(), func_type)
        try:
            ctr = f.get_param_value("Center")
            if func_type not in ['Sigmoid']:
                self.assertAlmostEqual(ctr, 3.3, delta=0.3)
        except fityk.ExecuteError:
            pass
        self.ftk.execute("delete %f")
    return do_test

def add_guessability_tests():
    all_types = fityk.Fityk().get_info('types')
    for func_type in all_types.split():
        if func_type not in ['FCJAsymm']:
            test = create_guessability_test(func_type)
            test.__name__ = 'test_' + func_type
            setattr(TestGuessability, test.__name__, test)

add_guessability_tests()

if __name__ == '__main__':
    unittest.main()