


'''simple docstring'''

import pytest

from datasets import inspect_metric, list_metrics, load_metric






@pytest.fixture
def __UpperCamelCase   (			__lowerCamelCase		: Optional[int]				)      ->     int:







     '''simple docstring'''






     monkeypatch.setattr("datasets.utils.deprecation_utils._emitted_deprecation_warnings"      ,  set()				)






@pytest.fixture
def __UpperCamelCase   (			__lowerCamelCase		: Any				)      ->     Any:







     '''simple docstring'''






     class 						__SCREAMING_SNAKE_CASE					:






          def __init__(			self     ,							__UpperCamelCase		)       ->    Dict:
               _a						=		metric_id







     class 						__SCREAMING_SNAKE_CASE					:
          UpperCAmelCase 					=				[MetricMock(__SCREAMING_SNAKE_CASE ) for metric_id in ['accuracy', 'mse', 'precision', 'codeparrot/apps_metric']]






          def  a_					(			self		)       ->    Optional[Any]:
               return self._metrics







     monkeypatch.setattr("datasets.inspect.huggingface_hub"      ,  HfhMock()				)






@pytest.mark.parametrize(
    "func, args"      ,  [(load_metric, ("metrics/mse",)), (list_metrics, ()), (inspect_metric, ("metrics/mse", "tmp_path"))]				)
def __UpperCamelCase   (			__lowerCamelCase		: List[str]      ,  __lowerCamelCase		: Optional[int]      ,  __lowerCamelCase		: Dict      ,  __lowerCamelCase		: Optional[int]      ,  __lowerCamelCase		: Tuple				)      ->     Optional[int]:







     '''simple docstring'''






     if "tmp_path" in args:
          _a						=		tuple(arg if arg != "tmp_path" else tmp_path for arg in args				)
     with pytest.warns(lowerCAmelCase__      ,  match="https://huggingface.co/docs/evaluate"				):
          func(*lowerCAmelCase__				)





'''simple docstring'''

lowercase__				     =		256
# Modulus to hash a string
lowercase__				     =		1_000_003






def __UpperCamelCase   (			__lowerCamelCase		: str      ,  __lowerCamelCase		: str				)      ->     bool:







     '''simple docstring'''






     _a						=		len(__lowerCamelCase				)
     _a						=		len(__lowerCamelCase				)
     if p_len > t_len:
          return False

     _a						=		0
     _a						=		0
     _a						=		1

     # Calculating the hash of pattern and substring of text
     for i in range(__lowerCamelCase				):
          _a						=		(ord(pattern[i]				) + p_hash * alphabet_size) % modulus
          _a						=		(ord(text[i]				) + text_hash * alphabet_size) % modulus
          if i == p_len - 1:
               continue
          _a						=		(modulus_power * alphabet_size) % modulus

     for i in range(0      ,  t_len - p_len + 1				):
          if text_hash == p_hash and text[i : i + p_len] == pattern:
               return True
          if i == t_len - p_len:
               continue
          # Calculate the https://en.wikipedia.org/wiki/Rolling_hash
          _a						=		(
              (text_hash - ord(text[i]				) * modulus_power) * alphabet_size
              + ord(text[i + p_len]				)
          ) % modulus
     return False






def __UpperCamelCase   (			)      ->     None:







     '''simple docstring'''






     _a						=		"abc1abc12"
     _a						=		"alskfjaldsabc1abc1abc12k23adsfabcabc"
     _a						=		"alskfjaldsk23adsfabcabc"
     assert rabin_karp(__lowerCamelCase      ,  __lowerCamelCase				) and not rabin_karp(__lowerCamelCase      ,  __lowerCamelCase				)

     # Test 2)
     _a						=		"ABABX"
     _a						=		"ABABZABABYABABX"
     assert rabin_karp(__lowerCamelCase      ,  __lowerCamelCase				)

     # Test 3)
     _a						=		"AAAB"
     _a						=		"ABAAAAAB"
     assert rabin_karp(__lowerCamelCase      ,  __lowerCamelCase				)

     # Test 4)
     _a						=		"abcdabcy"
     _a						=		"abcxabcdabxabcdabcdabcy"
     assert rabin_karp(__lowerCamelCase      ,  __lowerCamelCase				)

     # Test 5)
     _a						=		"Lü"
     _a						=		"Lüsai"
     assert rabin_karp(__lowerCamelCase      ,  __lowerCamelCase				)
     _a						=		"Lue"
     assert not rabin_karp(__lowerCamelCase      ,  __lowerCamelCase				)
     print("Success."				)


if __name__ == "__main__":
   test_rabin_karp()

