import pytest
import numbers
import numpy as np
from numpy.testing import assert_raises
from numpy.testing import assert_array_equal
from numpy.testing import assert_equal
from numpy.testing import assert_raises_regex
from skopt.space import LogN, Normalize


@pytest.mark.fast_test
def test_logn2_integer():

    transformer = LogN(2)
    for X in range(2, 31):
        X_orig = transformer.inverse_transform(transformer.transform(X))
        assert_array_equal(int(np.round(X_orig)), X)

@pytest.mark.fast_test
def test_logn10_integer():

    transformer = LogN(2)
    for X in range(2, 31):
        X_orig = transformer.inverse_transform(transformer.transform(X))
        assert_array_equal(int(np.round(X_orig)), X)


@pytest.mark.fast_test
def test_normalize_integer():
    transformer = Normalize(1, 20, is_int=True)
    assert transformer.transform(19.8) == 1.0
    assert transformer.transform(20.2) == 1.0
    assert transformer.transform(1.2) == 0.0
    assert transformer.transform(0.9) == 0.0
    assert_raises(ValueError, transformer.transform, 20.6)
    assert_raises(ValueError, transformer.transform, 0.4)

    assert transformer.inverse_transform(0.99) == 20
    assert transformer.inverse_transform(0.01) == 1
    assert_raises(ValueError, transformer.inverse_transform, 1. + 1e-8)
    assert_raises(ValueError, transformer.transform, 0. - 1e-8)


@pytest.mark.fast_test
def test_normalize():
    transformer = Normalize(1, 20, is_int=False)
    assert transformer.transform(20.) == 1.0
    assert transformer.transform(1.) == 0.0
    assert_raises(ValueError, transformer.transform, 20. + 1e-7)
    assert_raises(ValueError, transformer.transform, 1.0 - 1e-7)
    assert_raises(ValueError, transformer.inverse_transform, 1. + 1e-8)
    assert_raises(ValueError, transformer.transform, 0. - 1e-8)

[((328, 335), 'skopt.space.LogN', 'LogN', (['(2)'], {}), '(2)\n', (332, 335), False, 'from skopt.space import LogN, Normalize\n'), ((559, 566), 'skopt.space.LogN', 'LogN', (['(2)'], {}), '(2)\n', (563, 566), False, 'from skopt.space import LogN, Normalize\n'), ((793, 822), 'skopt.space.Normalize', 'Normalize', (['(1)', '(20)'], {'is_int': '(True)'}), '(1, 20, is_int=True)\n', (802, 822), False, 'from skopt.space import LogN, Normalize\n'), ((1009, 1063), 'numpy.testing.assert_raises', 'assert_raises', (['ValueError', 'transformer.transform', '(20.6)'], {}), '(ValueError, transformer.transform, 20.6)\n', (1022, 1063), False, 'from numpy.testing import assert_raises\n'), ((1068, 1121), 'numpy.testing.assert_raises', 'assert_raises', (['ValueError', 'transformer.transform', '(0.4)'], {}), '(ValueError, transformer.transform, 0.4)\n', (1081, 1121), False, 'from numpy.testing import assert_raises\n'), ((1232, 1301), 'numpy.testing.assert_raises', 'assert_raises', (['ValueError', 'transformer.inverse_transform', '(1.0 + 1e-08)'], {}), '(ValueError, transformer.inverse_transform, 1.0 + 1e-08)\n', (1245, 1301), False, 'from numpy.testing import assert_raises\n'), ((1304, 1365), 'numpy.testing.assert_raises', 'assert_raises', (['ValueError', 'transformer.transform', '(0.0 - 1e-08)'], {}), '(ValueError, transformer.transform, 0.0 - 1e-08)\n', (1317, 1365), False, 'from numpy.testing import assert_raises\n'), ((1429, 1459), 'skopt.space.Normalize', 'Normalize', (['(1)', '(20)'], {'is_int': '(False)'}), '(1, 20, is_int=False)\n', (1438, 1459), False, 'from skopt.space import LogN, Normalize\n'), ((1553, 1615), 'numpy.testing.assert_raises', 'assert_raises', (['ValueError', 'transformer.transform', '(20.0 + 1e-07)'], {}), '(ValueError, transformer.transform, 20.0 + 1e-07)\n', (1566, 1615), False, 'from numpy.testing import assert_raises\n'), ((1618, 1679), 'numpy.testing.assert_raises', 'assert_raises', (['ValueError', 'transformer.transform', '(1.0 - 1e-07)'], {}), '(ValueError, transformer.transform, 1.0 - 1e-07)\n', (1631, 1679), False, 'from numpy.testing import assert_raises\n'), ((1683, 1752), 'numpy.testing.assert_raises', 'assert_raises', (['ValueError', 'transformer.inverse_transform', '(1.0 + 1e-08)'], {}), '(ValueError, transformer.inverse_transform, 1.0 + 1e-08)\n', (1696, 1752), False, 'from numpy.testing import assert_raises\n'), ((1755, 1816), 'numpy.testing.assert_raises', 'assert_raises', (['ValueError', 'transformer.transform', '(0.0 - 1e-08)'], {}), '(ValueError, transformer.transform, 0.0 - 1e-08)\n', (1768, 1816), False, 'from numpy.testing import assert_raises\n'), ((467, 483), 'numpy.round', 'np.round', (['X_orig'], {}), '(X_orig)\n', (475, 483), True, 'import numpy as np\n'), ((698, 714), 'numpy.round', 'np.round', (['X_orig'], {}), '(X_orig)\n', (706, 714), True, 'import numpy as np\n')]