# Path: clrs/_src/algorithms/searching.py
# def minimum(A: _Array) -> _Out:
# def binary_search(x: _Numeric, A: _Array) -> _Out:
# def quickselect(
#     A: _Array,
#     A_pos=None,
#     p=None,
#     r=None,
#     i=None,
#     probes=None,
# ) -> _Out:
#   def partition(A, A_pos, p, r, target, probes):


from absl.testing import absltest
from clrs._src.algorithms import searching
import numpy as np
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

"""Unit tests for `searching.py`."""
# pylint: disable=invalid-name




EmptyArray = np.asarray([], dtype=np.int32)


class SearchingTest(absltest.TestCase):

  def test_minimum(self):
    for _ in range(17):
      A = np.random.randint(0, 100, size=(13,))
      idx, _ = searching.minimum(A)
      self.assertEqual(A.min(), A[idx])

  def test_binary_search(self):
    A = np.random.randint(0, 100, size=(13,))
    A.sort()
    x = np.random.choice(A)
    idx, _ = searching.binary_search(x, A)
    self.assertEqual(A[idx], x)

  def test_quickselect(self):
    A = np.random.randint(0, 100, size=(13,))

# Path: clrs/_src/algorithms/searching.py
# def minimum(A: _Array) -> _Out:
# def binary_search(x: _Numeric, A: _Array) -> _Out:
# def quickselect(
#     A: _Array,
#     A_pos=None,
#     p=None,
#     r=None,
#     i=None,
#     probes=None,
# ) -> _Out:
#   def partition(A, A_pos, p, r, target, probes):


# Path: clrs/_src/algorithms/searching_test.py
from absl.testing import absltest
from clrs._src.algorithms import searching
import numpy as np

# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

"""Unit tests for `searching.py`."""
# pylint: disable=invalid-name




EmptyArray = np.asarray([], dtype=np.int32)


class SearchingTest(absltest.TestCase):

  def test_minimum(self):
    for _ in range(17):
      A = np.random.randint(0, 100, size=(13,))
      idx, _ = searching.minimum(A)
      self.assertEqual(A.min(), A[idx])

  def test_binary_search(self):
    A = np.random.randint(0, 100, size=(13,))
    A.sort()
    x = np.random.choice(A)
    idx, _ = searching.binary_search(x, A)
    self.assertEqual(A[idx], x)

  def test_quickselect(self):
    A = np.random.randint(0, 100, size=(13,))

    idx, _ = searching.quickselect(A)