Statistiques
| Révision :

root / pobysoPythonSage / src / testPobyso.sage @ 116

Historique | Voir | Annoter | Télécharger (3,46 ko)

1 116 storres
"""
2 116 storres
Test module for pobyso.py functions.
3 116 storres
4 116 storres
AUTHORS:
5 116 storres
- S.T. (2014-02-26): initial version
6 116 storres
7 116 storres
TODO:
8 116 storres
- everything!
9 116 storres
10 116 storres
"""
11 116 storres
12 116 storres
print "\ntestPobyso loading..."
13 116 storres
#
14 116 storres
import inspect
15 116 storres
import resource
16 116 storres
17 116 storres
18 116 storres
def memory_usage_resource():
19 116 storres
    rusage_denom = RR("1024")
20 116 storres
    if sys.platform == 'darwin':
21 116 storres
        # ... it seems that in OSX the output is different units ...
22 116 storres
        rusage_denom = rusage_denom * rusage_denom
23 116 storres
    mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom
24 116 storres
    return mem
25 116 storres
# End memory_usage_resource()
26 116 storres
27 116 storres
#
28 116 storres
def test_pobyso_absolute_so_so():
29 116 storres
    for index in xrange(0,1000000):
30 116 storres
        absoluteSo = pobyso_absolute_so_so()
31 116 storres
        sollya_lib_clear_obj(absoluteSo)
32 116 storres
# End test_absolute_so_so
33 116 storres
34 116 storres
def test_pobyso_autoprint_so_so(iterationsNum=1000):
35 116 storres
    absoluteSo = pobyso_absolute_so_so()
36 116 storres
    for index in xrange(0,iterationsNum):
37 116 storres
        pobyso_autoprint(absoluteSo)
38 116 storres
    sollya_lib_clear_obj(absoluteSo)
39 116 storres
# End test_pobyso_autoprint
40 116 storres
41 116 storres
def test_pobyso_bounds_to_range_sa_so(iterationsNum=10000):
42 116 storres
    global t
43 116 storres
    print "Running", inspect.stack()[0][3]
44 116 storres
    lowerBoundSa = RR(1)
45 116 storres
    upperBoundSa = RR(2)
46 116 storres
    precSo = pobyso_get_prec_so()
47 116 storres
    pobyso_autoprint(precSo)
48 116 storres
    for index in xrange(0,iterationsNum):
49 116 storres
        rangeSo = pobyso_bounds_to_range_sa_so(lowerBoundSa, upperBoundSa)
50 116 storres
        sollya_lib_clear_obj(rangeSo)
51 116 storres
    precSo = pobyso_get_prec_so()
52 116 storres
    pobyso_autoprint(precSo)
53 116 storres
    sollya_lib_clear_obj(precSo)
54 116 storres
# End test_pobyso_bounds_to_range_sa_so
55 116 storres
56 116 storres
def test_pobyso_get_prec_so_sa(iterationsNum=10000):
57 116 storres
    print "Running", inspect.stack()[0][3]
58 116 storres
    for index in xrange(0,iterationsNum):
59 116 storres
        precSa = pobyso_get_prec_so_sa()
60 116 storres
# End test_pobyso_get_prec_so_sa
61 116 storres
62 116 storres
def test_pobyso_get_prec_of_constant_so_sa(iterationsNum=10000):
63 116 storres
    print "Running", inspect.stack()[0][3]
64 116 storres
    constSo = pobyso_constant_from_int_sa_so(2)
65 116 storres
    for index in xrange(0,iterationsNum):
66 116 storres
        precSa = pobyso_get_prec_of_constant_so_sa(constSo)
67 116 storres
    sollya_lib_clear_obj(constSo)
68 116 storres
# End test_pobyso_get_prec_of_constant_so_sa
69 116 storres
70 116 storres
def test_pobyso_lib_init(iterationsNum=10000):
71 116 storres
    """
72 116 storres
    Must be called exactly once. Leaks lots of memory otherwise.
73 116 storres
    """
74 116 storres
    print "Running", inspect.stack()[0][3]
75 116 storres
    for index in xrange(0,iterationsNum):
76 116 storres
        pobyso_lib_init()
77 116 storres
        #pobyso_lib_close()
78 116 storres
# End test_pobyso_lib_init
79 116 storres
80 116 storres
def test_pobyso_parse_string_sa_so(iterationsNum=10000):
81 116 storres
    print "Running", inspect.stack()[0][3]
82 116 storres
    for index in xrange(0,iterationsNum):
83 116 storres
        expressionSo = pobyso_parse_string_sa_so('exp(x)+2*x*sin(x)')
84 116 storres
        sollya_lib_clear_obj(expressionSo)
85 116 storres
# End pobyso_parse_string_sa_so
86 116 storres
87 116 storres
def test_pobyso_taylor_expansion_no_change_var_so_so(iterationsNum=10000):
88 116 storres
    functionSo  = pobyso_parse_string('exp(x)')
89 116 storres
    degreeSo    = pobyso_constant_from_int_sa_so(20)
90 116 storres
    rangeSo     = pobyso_bounds_to_range_sa_so(RR(1),RR(2))
91 116 storres
    errorTypeSo = pobyso_absolute_so_so()
92 116 storres
    for index in xrange(0,iterationsNum):
93 116 storres
        teSo = pobyso_taylor_expansion_no_change_var_so_so(functionSo,
94 116 storres
                                                           degreeSo,
95 116 storres
                                                           rangeSo,
96 116 storres
                                                           errorTypeSo)
97 116 storres
        sollya_lib_clear_obj(teSo[0])
98 116 storres
        sollya_lib_clear_obj(teSo[1])
99 116 storres
        sollya_lib_clear_obj(teSo[2])
100 116 storres
    sollya_lib_clear_obj(functionSo)
101 116 storres
    sollya_lib_clear_obj(degreeSo)
102 116 storres
    sollya_lib_clear_obj(rangeSo)
103 116 storres
    sollya_lib_clear_obj(errorTypeSo)
104 116 storres
# End test_pobyso_taylor_expansion_no_change_var_so_so
105 116 storres
106 116 storres
print "\t...testPobyso loaded"