|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
8 | | -from formulate import to_numexpr |
| 8 | +from formulate import from_numexpr, to_numexpr |
9 | 9 | from formulate import from_root, to_root |
10 | 10 |
|
11 | 11 | numexpr = pytest.importorskip("numexpr") |
@@ -34,16 +34,27 @@ def numexpr_eval(string, **kwargs): |
34 | 34 | return numexpr.evaluate(string, local_dict=kwargs) |
35 | 35 |
|
36 | 36 |
|
37 | | -def create_constant_test(root_string): |
| 37 | +def create_constant_test(input_string, input_backend='root'): |
| 38 | + assert input_backend in ('root', 'numexpr'), 'Unrecognised backend specified' |
| 39 | + input_from_method = { |
| 40 | + 'root': from_root, |
| 41 | + 'numexpr': from_numexpr, |
| 42 | + }[input_backend] |
| 43 | + |
38 | 44 | def test_constant(): |
39 | | - expression = from_root(root_string) |
| 45 | + expression = input_from_method(input_string) |
40 | 46 | root_result = to_root(expression) |
41 | 47 | numexpr_result = to_numexpr(expression) |
42 | | - assert pytest.approx(root_eval(root_string), root_eval(root_result)) |
| 48 | + assert pytest.approx(root_eval(input_string), root_eval(root_result)) |
43 | 49 | assert pytest.approx(root_eval(root_result), numexpr_eval(numexpr_result)) |
44 | 50 | return test_constant |
45 | 51 |
|
46 | 52 |
|
| 53 | +# Test basic numexpr constants |
| 54 | +test_numexpr_true = create_constant_test('True', input_backend='numexpr') |
| 55 | +test_numexpr_false = create_constant_test('False', input_backend='numexpr') |
| 56 | + |
| 57 | +# Test basic ROOT constants |
47 | 58 | test_true = create_constant_test('true') |
48 | 59 | test_false = create_constant_test('false') |
49 | 60 | test_sqrt2_1 = create_constant_test('sqrt2') |
|
0 commit comments