





import doctest
import glob
import importlib
import inspect
import os
import re
from contextlib import contextmanager
from functools import wraps
from unittest.mock import patch

import numpy as np
import pytest
from absl.testing import parameterized

import datasets
from datasets import load_metric

from .utils import for_all_test_methods, local, slow


# mark all tests as integration
_lowercase 							=       pytest.mark.integration


_lowercase 							=       {"""comet"""}
_lowercase 							=       importlib.util.find_spec("""fairseq""") is not None

_lowercase 							=       {"""code_eval"""}
_lowercase 							=       os.name == """nt"""

_lowercase 							=       {"""bertscore""", """frugalscore""", """perplexity"""}
_lowercase 							=       importlib.util.find_spec("""transformers""") is not None





def   lowerCamelCase__       (       UpperCamelCase__     :    List[Any]  )     ->	Any:



					'''simple docstring'''




					@wraps(__SCREAMING_SNAKE_CASE  )
					def wrapper(self     :    int    ,      UpperCamelCase__     :    str  ):
										if not _has_fairseq and metric_name in REQUIRE_FAIRSEQ:
															self.skipTest('\"test requires Fairseq\"'  )
										else:
															test_case(self    ,      __SCREAMING_SNAKE_CASE  )

					return wrapper





def   lowerCamelCase__       (       UpperCamelCase__     :    Optional[Any]  )     ->	Union[str, Any]:



					'''simple docstring'''




					@wraps(__SCREAMING_SNAKE_CASE  )
					def wrapper(self     :    Dict    ,      UpperCamelCase__     :    Dict  ):
										if not _has_transformers and metric_name in REQUIRE_TRANSFORMERS:
															self.skipTest('\"test requires transformers\"'  )
										else:
															test_case(self    ,      __SCREAMING_SNAKE_CASE  )

					return wrapper





def   lowerCamelCase__       (       UpperCamelCase__     :    Optional[Any]  )     ->	Optional[int]:



					'''simple docstring'''




					@wraps(__SCREAMING_SNAKE_CASE  )
					def wrapper(self     :    List[str]    ,      UpperCamelCase__     :    List[str]  ):
										if _on_windows and metric_name in UNSUPPORTED_ON_WINDOWS:
															self.skipTest('\"test not supported on Windows\"'  )
										else:
															test_case(self    ,      __SCREAMING_SNAKE_CASE  )

					return wrapper





def   lowerCamelCase__       (       )     ->	Any:



					'''simple docstring'''




					_snake_case													=			[metric_dir.split(os.sep  )[-2] for metric_dir in glob.glob('./metrics/*/'  )]
					return [{"testcase_name": x, "metric_name": x} for x in metrics if x != "gleu"]  # gleu is unfinished
@parameterized.named_parameters(get_local_metric_names()   )
@for_all_test_methods(
    __snake_case							,					__snake_case							,					__snake_case   )
@local
class      UpperCamelCase_						(					parameterized.TestCase   ):
					lowerCAmelCase_							=		{}
					lowerCAmelCase_							=		None




					@pytest.mark.filterwarnings('ignore:metric_module_factory is deprecated:FutureWarning'					)
					@pytest.mark.filterwarnings('ignore:load_metric is deprecated:FutureWarning'					)
					def 		lowerCAmelCase     (						self			,  lowerCAmelCase_					)						->							List[str]:
										_snake_case													=			"[...]"
										_snake_case													=			importlib.import_module(
										    datasets.load.metric_module_factory(os.path.join('metrics'			,  UpperCamelCase__					)					).module_path					)
										_snake_case													=			datasets.load.import_main_class(metric_module.__name__			,  dataset=UpperCamelCase__					)
										# check parameters
										_snake_case													=			inspect.signature(metric._compute					).parameters
										self.assertTrue(all(p.kind != p.VAR_KEYWORD for p in parameters.values()					)					)  # no **kwargs
										# run doctest
										with self.patch_intensive_calls(UpperCamelCase__			,  metric_module.__name__					):
															with self.use_local_metrics():
																				try:
																									_snake_case													=			doctest.testmod(UpperCamelCase__			,  verbose=UpperCamelCase__			,  raise_on_error=UpperCamelCase__					)
																				except doctest.UnexpectedException as e:
																									raise e.exc_info[1]  # raise the exception that doctest caught
										self.assertEqual(results.failed			,  0					)
										self.assertGreater(results.attempted			,  1					)




					@slow
					def 		lowerCAmelCase     (						self			,  lowerCAmelCase_					)						->							Tuple:
										_snake_case													=			"[...]"
										_snake_case													=			importlib.import_module(
										    datasets.load.metric_module_factory(os.path.join('metrics'			,  UpperCamelCase__					)					).module_path					)
										# run doctest
										with self.use_local_metrics():
															_snake_case													=			doctest.testmod(UpperCamelCase__			,  verbose=UpperCamelCase__			,  raise_on_error=UpperCamelCase__					)
										self.assertEqual(results.failed			,  0					)
										self.assertGreater(results.attempted			,  1					)




					@contextmanager
					def 		lowerCAmelCase     (						self			,  lowerCAmelCase_			,  lowerCAmelCase_					)						->							Optional[int]:


										if metric_name in self.INTENSIVE_CALLS_PATCHER:
															with self.INTENSIVE_CALLS_PATCHER[metric_name](UpperCamelCase__					):
																				yield
										else:
															yield




					@contextmanager
					def 		lowerCAmelCase     (						self					)						->							Tuple:


										def load_local_metric(lowerCAmelCase_			,  *lowerCAmelCase_			,  **lowerCAmelCase_					):
															return load_metric(os.path.join('metrics'			,  UpperCamelCase__					)			,  *UpperCamelCase__			,  **UpperCamelCase__					)

										with patch('datasets.load_metric'					) as mock_load_metric:
															_snake_case													=			load_local_metric
															yield






					@classmethod
					def 		lowerCAmelCase     (						cls			,  lowerCAmelCase_					)						->							Tuple:


										def wrapper(lowerCAmelCase_					):
															_snake_case													=			contextmanager(UpperCamelCase__					)
															_snake_case													=			patcher
															return patcher

										return wrapper





@LocalMetricTest.register_intensive_calls_patcher('bleurt'  )
def   lowerCamelCase__       (       UpperCamelCase__     :    List[str]  )     ->	int:



					'''simple docstring'''




					import tensorflow.compat.va as tf
					from bleurt.score import Predictor

					tf.flags.DEFINE_string('sv'    ,      ''    ,      ''  )  # handle pytest cli flags
					class      UpperCamelCase_						(					__snake_case   ):




										def 		lowerCAmelCase     (						self			,  lowerCAmelCase_					)						->							Tuple:
															assert len(input_dict['input_ids']					) == 2
															return np.array([1.03, 1.04]					)

    # mock predict_fn which is supposed to do a forward pass with a bleurt model
					with patch('bleurt.score._create_predictor'  ) as mock_create_predictor:
										_snake_case													=			MockedPredictor()
										yield





@LocalMetricTest.register_intensive_calls_patcher('bertscore'  )
def   lowerCamelCase__       (       UpperCamelCase__     :    List[Any]  )     ->	str:



					'''simple docstring'''




					import torch

					def bert_cos_score_idf(UpperCamelCase__     :    Tuple    ,      UpperCamelCase__     :    str    ,      *UpperCamelCase__     :    Optional[int]    ,      **UpperCamelCase__     :    Union[str, Any]  ):
										return torch.tensor([[1.0, 1.0, 1.0]] * len(__SCREAMING_SNAKE_CASE  )  )

					# mock get_model which is supposed to do download a bert model
					# mock bert_cos_score_idf which is supposed to do a forward pass with a bert model
					with patch('bert_score.scorer.get_model'  ), patch(
					    'bert_score.scorer.bert_cos_score_idf'  ) as mock_bert_cos_score_idf:
										_snake_case													=			bert_cos_score_idf
										yield





@LocalMetricTest.register_intensive_calls_patcher('comet'  )
def   lowerCamelCase__       (       UpperCamelCase__     :    Optional[Any]  )     ->	List[str]:



					'''simple docstring'''




					def load_from_checkpoint(UpperCamelCase__     :    int  ):
										class      UpperCamelCase_						:




															def 		lowerCAmelCase     (						self			,  lowerCAmelCase_			,  *lowerCAmelCase_			,  **lowerCAmelCase_					)						->							int:
																				assert len(UpperCamelCase__					) == 2
																				_snake_case													=			[0.19, 0.92]
																				return scores, sum(UpperCamelCase__					) / len(UpperCamelCase__					)





										return Model()

					# mock load_from_checkpoint which is supposed to do download a bert model
					# mock load_from_checkpoint which is supposed to do download a bert model
					with patch('comet.download_model'  ) as mock_download_model:
										_snake_case													=			None
										with patch('comet.load_from_checkpoint'  ) as mock_load_from_checkpoint:
															_snake_case													=			load_from_checkpoint
															yield





def   lowerCamelCase__       (       )     ->	Tuple:



					'''simple docstring'''




					_snake_case													=			load_metric(os.path.join('metrics'    ,      'seqeval'  )  )
					_snake_case													=			"ERROR"
					_snake_case													=			F'''Scheme should be one of [IOB1, IOB2, IOE1, IOE2, IOBES, BILOU], got {wrong_scheme}'''
					with pytest.raises(__SCREAMING_SNAKE_CASE    ,      match=re.escape(__SCREAMING_SNAKE_CASE  )  ):
										metric.compute(predictions=[]    ,      references=[]    ,      scheme=__SCREAMING_SNAKE_CASE  )










def   lowerCamelCase__       (       )     ->	int:



					'''simple docstring'''




					return 1





def   lowerCamelCase__       (       UpperCamelCase__     :    int  )     ->	int:



					'''simple docstring'''




					return 0 if x < 0 else two_pence(x - 2  ) + one_pence()





def   lowerCamelCase__       (       UpperCamelCase__     :    int  )     ->	int:



					'''simple docstring'''




					return 0 if x < 0 else five_pence(x - 5  ) + two_pence(UpperCamelCase__  )





def   lowerCamelCase__       (       UpperCamelCase__     :    int  )     ->	int:



					'''simple docstring'''




					return 0 if x < 0 else ten_pence(x - 10  ) + five_pence(UpperCamelCase__  )





def   lowerCamelCase__       (       UpperCamelCase__     :    int  )     ->	int:



					'''simple docstring'''




					return 0 if x < 0 else twenty_pence(x - 20  ) + ten_pence(UpperCamelCase__  )





def   lowerCamelCase__       (       UpperCamelCase__     :    int  )     ->	int:



					'''simple docstring'''




					return 0 if x < 0 else fifty_pence(x - 50  ) + twenty_pence(UpperCamelCase__  )





def   lowerCamelCase__       (       UpperCamelCase__     :    int  )     ->	int:



					'''simple docstring'''




					return 0 if x < 0 else one_pound(x - 100  ) + fifty_pence(UpperCamelCase__  )





def   lowerCamelCase__       (       UpperCamelCase__     :    int  )     ->	int:



					'''simple docstring'''




					return 0 if x < 0 else two_pound(x - 200  ) + one_pound(UpperCamelCase__  )





def   lowerCamelCase__       (       UpperCamelCase__     :    int = 200  )     ->	int:



					'''simple docstring'''




					return two_pound(UpperCamelCase__  )


if __name__ == "__main__":
					print(solution(int(input().strip())))



