# Copyright (c) 2023, NVIDIA CORPORATION.  All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test preprocess ops."""
import pytest

# import numpy as np
import tensorflow as tf
from nvidia_tao_tf1.cv.mask_rcnn.ops import box_utils


@pytest.mark.parametrize("pd, gt, expected",
                         [([[0, 0, 10, 10]], [[5, 5, 10, 10]], 0.25),
                          ([[0, 0, 10, 10]], [[11, 11, 20, 20]], 0)])
def test_box_overlap(pd, gt, expected):
    """Test normalize image with torch means."""
    gt_box = tf.expand_dims(tf.constant(gt, dtype=tf.float32), axis=0)
    pd_box = tf.expand_dims(tf.constant(pd, dtype=tf.float32), axis=0)

    result = box_utils.bbox_overlap(pd_box, gt_box)
    init_op = tf.compat.v1.global_variables_initializer()

    with tf.compat.v1.Session() as sess:
        sess.run(init_op)
        output = sess.run(result)
        assert output == expected
