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