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)

[((14, 18, 14, 25), 'skopt.space.LogN', 'LogN', ({(14, 23, 14, 24): '2'}, {}), '(2)', False, 'from skopt.space import LogN, Normalize\n'), ((22, 18, 22, 25), 'skopt.space.LogN', 'LogN', ({(22, 23, 22, 24): '2'}, {}), '(2)', False, 'from skopt.space import LogN, Normalize\n'), ((30, 18, 30, 47), 'skopt.space.Normalize', 'Normalize', (), '', False, 'from skopt.space import LogN, Normalize\n'), ((35, 4, 35, 58), 'numpy.testing.assert_raises', 'assert_raises', ({(35, 18, 35, 28): 'ValueError', (35, 30, 35, 51): 'transformer.transform', (35, 53, 35, 57): '(20.6)'}, {}), '(ValueError, transformer.transform, 20.6)', False, 'from numpy.testing import assert_raises\n'), ((36, 4, 36, 57), 'numpy.testing.assert_raises', 'assert_raises', ({(36, 18, 36, 28): 'ValueError', (36, 30, 36, 51): 'transformer.transform', (36, 53, 36, 56): '(0.4)'}, {}), '(ValueError, transformer.transform, 0.4)', False, 'from numpy.testing import assert_raises\n'), ((40, 4, 40, 71), 'numpy.testing.assert_raises', 'assert_raises', ({(40, 18, 40, 28): 'ValueError', (40, 30, 40, 59): 'transformer.inverse_transform', (40, 61, 40, 70): '(1.0 + 1e-08)'}, {}), '(ValueError, transformer.inverse_transform, 1.0 + 1e-08)', False, 'from numpy.testing import assert_raises\n'), ((41, 4, 41, 63), 'numpy.testing.assert_raises', 'assert_raises', ({(41, 18, 41, 28): 'ValueError', (41, 30, 41, 51): 'transformer.transform', (41, 53, 41, 62): '(0.0 - 1e-08)'}, {}), '(ValueError, transformer.transform, 0.0 - 1e-08)', False, 'from numpy.testing import assert_raises\n'), ((46, 18, 46, 48), 'skopt.space.Normalize', 'Normalize', (), '', False, 'from skopt.space import LogN, Normalize\n'), ((49, 4, 49, 64), 'numpy.testing.assert_raises', 'assert_raises', ({(49, 18, 49, 28): 'ValueError', (49, 30, 49, 51): 'transformer.transform', (49, 53, 49, 63): '(20.0 + 1e-07)'}, {}), '(ValueError, transformer.transform, 20.0 + 1e-07)', False, 'from numpy.testing import assert_raises\n'), ((50, 4, 50, 64), 'numpy.testing.assert_raises', 'assert_raises', ({(50, 18, 50, 28): 'ValueError', (50, 30, 50, 51): 'transformer.transform', (50, 53, 50, 63): '(1.0 - 1e-07)'}, {}), '(ValueError, transformer.transform, 1.0 - 1e-07)', False, 'from numpy.testing import assert_raises\n'), ((51, 4, 51, 71), 'numpy.testing.assert_raises', 'assert_raises', ({(51, 18, 51, 28): 'ValueError', (51, 30, 51, 59): 'transformer.inverse_transform', (51, 61, 51, 70): '(1.0 + 1e-08)'}, {}), '(ValueError, transformer.inverse_transform, 1.0 + 1e-08)', False, 'from numpy.testing import assert_raises\n'), ((52, 4, 52, 63), 'numpy.testing.assert_raises', 'assert_raises', ({(52, 18, 52, 28): 'ValueError', (52, 30, 52, 51): 'transformer.transform', (52, 53, 52, 62): '(0.0 - 1e-08)'}, {}), '(ValueError, transformer.transform, 0.0 - 1e-08)', False, 'from numpy.testing import assert_raises\n'), ((17, 31, 17, 47), 'numpy.round', 'np.round', ({(17, 40, 17, 46): 'X_orig'}, {}), '(X_orig)', True, 'import numpy as np\n'), ((25, 31, 25, 47), 'numpy.round', 'np.round', ({(25, 40, 25, 46): 'X_orig'}, {}), '(X_orig)', True, 'import numpy as np\n')]