import numpy as np

from dnnv.nn.converters.tensorflow import *
from dnnv.nn.operations import *


TOL = 1e-6


def test_Dropout_consts():
    x = np.array([3, 4]).astype(np.float32)
    op = Dropout(x)
    tf_op = TensorflowConverter().visit(op)
    result_ = tf_op()
    assert isinstance(result_, tuple)
    assert len(result_) == 2
    result, none = result_
    assert none is None
    y = np.array([3, 4]).astype(np.float32)
    assert np.all(result >= (y - TOL))
    assert np.all(result <= (y + TOL))


def test_Dropout_x_is_op():
    x = np.array([3, 4]).astype(np.float32)
    input_op = Input((2,), np.dtype(np.float32))
    op = Dropout(input_op)
    tf_op = TensorflowConverter().visit(op)
    result_ = tf_op(x)
    assert isinstance(result_, tuple)
    assert len(result_) == 2
    result, none = result_
    assert none is None
    y = np.array([3, 4]).astype(np.float32)
    assert np.all(result >= (y - TOL))
    assert np.all(result <= (y + TOL))

[((20, 11, 20, 38), 'numpy.all', 'np.all', ({(20, 18, 20, 37): '(result >= y - TOL)'}, {}), '(result >= y - TOL)', True, 'import numpy as np\n'), ((21, 11, 21, 38), 'numpy.all', 'np.all', ({(21, 18, 21, 37): '(result <= y + TOL)'}, {}), '(result <= y + TOL)', True, 'import numpy as np\n'), ((35, 11, 35, 38), 'numpy.all', 'np.all', ({(35, 18, 35, 37): '(result >= y - TOL)'}, {}), '(result >= y - TOL)', True, 'import numpy as np\n'), ((36, 11, 36, 38), 'numpy.all', 'np.all', ({(36, 18, 36, 37): '(result <= y + TOL)'}, {}), '(result <= y + TOL)', True, 'import numpy as np\n'), ((26, 27, 26, 47), 'numpy.dtype', 'np.dtype', ({(26, 36, 26, 46): 'np.float32'}, {}), '(np.float32)', True, 'import numpy as np\n'), ((11, 8, 11, 24), 'numpy.array', 'np.array', ({(11, 17, 11, 23): '[3, 4]'}, {}), '([3, 4])', True, 'import numpy as np\n'), ((19, 8, 19, 24), 'numpy.array', 'np.array', ({(19, 17, 19, 23): '[3, 4]'}, {}), '([3, 4])', True, 'import numpy as np\n'), ((25, 8, 25, 24), 'numpy.array', 'np.array', ({(25, 17, 25, 23): '[3, 4]'}, {}), '([3, 4])', True, 'import numpy as np\n'), ((34, 8, 34, 24), 'numpy.array', 'np.array', ({(34, 17, 34, 23): '[3, 4]'}, {}), '([3, 4])', True, 'import numpy as np\n')]