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))

[((442, 467), 'numpy.all', 'np.all', (['(result >= y - TOL)'], {}), '(result >= y - TOL)\n', (448, 467), True, 'import numpy as np\n'), ((481, 506), 'numpy.all', 'np.all', (['(result <= y + TOL)'], {}), '(result <= y + TOL)\n', (487, 506), True, 'import numpy as np\n'), ((899, 924), 'numpy.all', 'np.all', (['(result >= y - TOL)'], {}), '(result >= y - TOL)\n', (905, 924), True, 'import numpy as np\n'), ((938, 963), 'numpy.all', 'np.all', (['(result <= y + TOL)'], {}), '(result <= y + TOL)\n', (944, 963), True, 'import numpy as np\n'), ((610, 630), 'numpy.dtype', 'np.dtype', (['np.float32'], {}), '(np.float32)\n', (618, 630), True, 'import numpy as np\n'), ((147, 163), 'numpy.array', 'np.array', (['[3, 4]'], {}), '([3, 4])\n', (155, 163), True, 'import numpy as np\n'), ((395, 411), 'numpy.array', 'np.array', (['[3, 4]'], {}), '([3, 4])\n', (403, 411), True, 'import numpy as np\n'), ((547, 563), 'numpy.array', 'np.array', (['[3, 4]'], {}), '([3, 4])\n', (555, 563), True, 'import numpy as np\n'), ((852, 868), 'numpy.array', 'np.array', (['[3, 4]'], {}), '([3, 4])\n', (860, 868), True, 'import numpy as np\n')]