1#!/usr/local/bin/python3.8
2# -*- coding: utf-8 -*-
3
4
5import pytest
6from .helper import evaluate
7
8
9try:
10    import scipy.integrate
11    usescipy = True
12except:
13    usescipy = False
14
15
16if usescipy:
17    methods = ["Automatic", "Romberg", "Internal", "NQuadrature"]
18
19    generic_tests_for_nintegrate =     [
20     (r'NIntegrate[x^2, {x,0,1}, {method} ]', r'1/3.', ''),
21     (r'NIntegrate[x^2 y^(-1.+1/3.), {x,0,1},{y,0,1}, {method}]', r'1.', ''),
22    ]
23
24    tests_for_nintegrate = sum([
25        [ (tst[0].replace("{method}", "Method->"+ method),
26           tst[1],tst[2])
27          for tst in generic_tests_for_nintegrate]
28        for method in methods], [])
29else:
30    tests_for_nintegrate =     [(r'NIntegrate[x^2, {x,0,1}]', r'1/3.', ''),
31                                (r'NIntegrate[x^2 y^(-.5), {x,0,1},{y,0,1}]', r'1.', ''),
32    ]
33
34@pytest.mark.parametrize(
35    "str_expr, str_expected, msg",
36    tests_for_nintegrate
37)
38def test_nintegrate(str_expr: str, str_expected: str, msg: str, message=""):
39    result = evaluate(str_expr)
40    expected = evaluate(str_expected)
41    if msg:
42        assert result == expected, msg
43    else:
44        assert result == expected
45