# This file is part of the pyMor project (http://www.pymor.org).
# Copyright Holders: Felix Albrecht, Rene Milk, Stephan Rave
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

from __future__ import absolute_import, division, print_function

import numpy as np
import random
from math import sin, exp

from pymortests.base import TestInterface, runmodule
from pymor.playground.expression_function import ExpressionFunction

FUNCTIONS = [(ExpressionFunction(['x**2'], 'x'), lambda x: np.array([x ** 2])),
             (ExpressionFunction(['x**2', 'sin(x)'], 'x'), lambda x: np.array([x ** 2, sin(x)])),
             (ExpressionFunction(['exp(xp)'], 'xp'), lambda x: np.array([exp(x)]))]


class TestExpressionFunction(TestInterface):

    def test_eval(self):
        for (fn, fe) in FUNCTIONS:
            for x in (random.uniform(0, 1) for _ in xrange(9000)):
                np.testing.assert_array_almost_equal(fn([x]), fe(x))


if __name__ == "__main__":
    random.seed()
    runmodule(filename=__file__)

# This file is part of the pyMor project (http://www.pymor.org).
# Copyright Holders: Felix Albrecht, Rene Milk, Stephan Rave
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

from __future__ import absolute_import, division, print_function

import numpy as np
import pytest
import random
from math import sin, exp

from pymortests.base import runmodule
from pymor.playground.expression_function import ExpressionFunction

FUNCTIONS = [(ExpressionFunction(['x**2'], 'x'), lambda x: np.array([x ** 2])),
             (ExpressionFunction(['x**2', 'sin(x)'], 'x'), lambda x: np.array([x ** 2, sin(x)])),
             (ExpressionFunction(['exp(xp)'], 'xp'), lambda x: np.array([exp(x)]))]

@pytest.mark.xfail
def test_eval():
    for (fn, fe) in FUNCTIONS:
        for x in (random.uniform(0, 1) for _ in xrange(9000)):
            np.testing.assert_array_almost_equal(fn([x]), fe(x))


if __name__ == "__main__":
    random.seed()
    runmodule(filename=__file__)

mark expression_function test with xfail