Skip to content

Commit 57b6573

Browse files
committed
Enh test efficency and precision
1 parent 8d73ddd commit 57b6573

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

tests/test_labfloat.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import pytest
22
import numpy
3+
import itertools
34
from math import sqrt
45
import labfis
56

6-
dx = 1e-13
7+
dx = 1e-10
78

89

910
def labfloat_iterative(vardic, exp):
@@ -38,29 +39,34 @@ def labfloat_calc(vardic, exp):
3839

3940
rng = numpy.random.default_rng()
4041

41-
expresions = [
42-
"a*b*c",
43-
"a*b/c",
44-
"(a**b)*c",
45-
"2/b*(a/c)",
46-
"a+b+c",
47-
"a-b+c",
48-
"c**b/a",
49-
"(c**0.5+b**1.3)*"+str(numpy.e)+"**a"
50-
]
42+
operations = ["*", "/", "+", "-", "**"]
5143

5244
vals = {
5345
"a": (rng.random(), rng.random()),
5446
"b": (rng.random(), rng.random()),
55-
"c": (rng.random(), rng.random())
47+
"c": (rng.random(), rng.random()),
48+
"d": (rng.random(), rng.random()),
49+
"e": (rng.random(), rng.random())
5650
}
5751

5852

5953
def test_labfloat_expressions():
60-
for exp in expresions:
61-
result1 = labfloat_iterative(vals, exp)
62-
result2 = labfloat_calc(vals, exp)
63-
54+
print(vals)
55+
var = list(vals.keys())
56+
opers = itertools.combinations_with_replacement(operations, len(var)-1)
57+
for exp in opers:
58+
expression = ""
59+
for i in range(len(exp)):
60+
if i == len(exp)-1:
61+
expression += var[i]+exp[i]+var[i+1]
62+
else:
63+
expression += var[i]+exp[i]
64+
65+
result1 = labfloat_iterative(vals, expression)
66+
result2 = labfloat_calc(vals, expression)
67+
68+
print(expression)
6469
print(result1, result2)
70+
print(round(result1), round(result2))
6571

6672
assert round(result2) == round(result1)

0 commit comments

Comments
 (0)