|
1 | 1 | import pytest |
2 | 2 | import numpy |
| 3 | +import itertools |
3 | 4 | from math import sqrt |
4 | 5 | import labfis |
5 | 6 |
|
6 | | -dx = 1e-13 |
| 7 | +dx = 1e-10 |
7 | 8 |
|
8 | 9 |
|
9 | 10 | def labfloat_iterative(vardic, exp): |
@@ -38,29 +39,34 @@ def labfloat_calc(vardic, exp): |
38 | 39 |
|
39 | 40 | rng = numpy.random.default_rng() |
40 | 41 |
|
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 = ["*", "/", "+", "-", "**"] |
51 | 43 |
|
52 | 44 | vals = { |
53 | 45 | "a": (rng.random(), rng.random()), |
54 | 46 | "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()) |
56 | 50 | } |
57 | 51 |
|
58 | 52 |
|
59 | 53 | 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) |
64 | 69 | print(result1, result2) |
| 70 | + print(round(result1), round(result2)) |
65 | 71 |
|
66 | 72 | assert round(result2) == round(result1) |
0 commit comments