
"""simple docstring"""
import unittest

from cer import CER


__magic_name__		       =				CER()


class    _lowerCAmelCase						(						unittest.TestCase						):



							def       _a   (      self   )							->							Optional[Any]:
								_UpperCAmelCase =						["White House"]
								_UpperCAmelCase =						["white house"]
								# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertTrue(abs(char_error_rate - 0.1818181818   ) < 1e-6   )



							def       _a   (      self   )							->							int:
								_UpperCAmelCase =						["were wolf"]
								_UpperCAmelCase =						["werewolf"]
								# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertTrue(abs(char_error_rate - 0.1111111   ) < 1e-6   )

								_UpperCAmelCase =						["werewolf"]
								_UpperCAmelCase =						["weae     wolf"]
								# S = 1, D = 1, I = 0, N = 8, CER = 0.25
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertTrue(abs(char_error_rate - 0.25   ) < 1e-6   )

								# consecutive whitespaces case 1
								_UpperCAmelCase =						["were wolf"]
								_UpperCAmelCase =						["were               wolf"]
								# S = 0, D = 0, I = 0, N = 9, CER = 0
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertTrue(abs(char_error_rate - 0.0   ) < 1e-6   )

								# consecutive whitespaces case 2
								_UpperCAmelCase =						["were   wolf"]
								_UpperCAmelCase =						["were               wolf"]
								# S = 0, D = 0, I = 0, N = 9, CER = 0
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertTrue(abs(char_error_rate - 0.0   ) < 1e-6   )



							def       _a   (      self   )							->							List[Any]:
								_UpperCAmelCase =						["werewolf"]
								_UpperCAmelCase =						["weaewolf"]
								# S = 1, D = 0, I = 0, N = 8, CER = 0.125
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertTrue(abs(char_error_rate - 0.125   ) < 1e-6   )



							def       _a   (      self   )							->							List[Any]:
								_UpperCAmelCase =						["werewolf"]
								_UpperCAmelCase =						["wereawolf"]
								# S = 0, D = 1, I = 0, N = 8, CER = 0.125
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertTrue(abs(char_error_rate - 0.125   ) < 1e-6   )



							def       _a   (      self   )							->							Optional[int]:
								_UpperCAmelCase =						["werewolf"]
								_UpperCAmelCase =						["wereolf"]
								# S = 0, D = 0, I = 1, N = 8, CER = 0.125
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertTrue(abs(char_error_rate - 0.125   ) < 1e-6   )



							def       _a   (      self   )							->							Optional[int]:
								_UpperCAmelCase =						["werewolf"]
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertEqual(a_ ,						0.0   )



							def       _a   (      self   )							->							List[str]:
								_UpperCAmelCase =						["werewolf", "I am your father"]
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertEqual(a_ ,						0.0   )

								_UpperCAmelCase =						["werewolf", "I am your father", "doge"]
								_UpperCAmelCase =						["werxwolf", "I       am your father", "doge"]
								# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertTrue(abs(char_error_rate - 0.03571428   ) < 1e-6   )



							def       _a   (      self   )							->							List[Any]:
								_UpperCAmelCase =						["My hovercraft", "is full of eels"]
								_UpperCAmelCase =						["My hovercraft is full", " of eels"]
								# S = 0, D = 0, I = 2, N = 28, CER = 2 / 28
								# whitespace at the front of " of eels" will be strip during preporcessing
								# so need to insert 2 whitespaces
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_ ,						concatenate_texts=a_   )
								self.assertTrue(abs(char_error_rate - 0.071428   ) < 1e-6   )



							def       _a   (      self   )							->							Optional[int]:
								_UpperCAmelCase =						["我能吞下玻璃而不伤身体"]
								_UpperCAmelCase =						[" 能吞虾玻璃而 不霜身体啦"]
								# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertTrue(abs(char_error_rate - 0.4545454545   ) < 1e-6   )

								_UpperCAmelCase =						["我能吞下玻璃", "而不伤身体"]
								_UpperCAmelCase =						["我    能 吞 下 玻 璃", "而不伤身体"]
								# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertTrue(abs(char_error_rate - 0.454545454545   ) < 1e-6   )

								_UpperCAmelCase =						["我能吞下玻璃而不伤身体"]
								_UpperCAmelCase =						cer.compute(predictions=a_ ,						references=a_   )
								self.assertFalse(a_ ,						0.0   )



							def       _a   (      self   )							->							Dict:
								_UpperCAmelCase =						[""]
								_UpperCAmelCase =						["Hypothesis"]
								with self.assertRaises(a_   ):
									cer.compute(predictions=a_ ,						references=a_   )


if __name__ == "__main__":
			unittest.main()






"""simple docstring"""
from .stack import Stack




def     __lowerCamelCase  (		UpperCamelCase__      ):


	"""simple docstring"""






	_UpperCAmelCase =						Stack()
	_UpperCAmelCase =						{"(": ")", "[": "]", "{": "}"}
	for bracket in parentheses:
		if bracket in bracket_pairs:
			stack.push(UpperCamelCase__      )
		elif bracket in (")", "]", "}"):
			if stack.is_empty() or bracket_pairs[stack.pop()] != bracket:
				return False
	return stack.is_empty()


if __name__ == "__main__":
			from doctest import testmod

			testmod()

			__magic_name__		       =				['''((()))''', '''((())''', '''(()))''']
			print('''Balanced parentheses demonstration:\n''')
			for example in examples:
						__magic_name__		       =				'''''' if balanced_parentheses(example) else '''not '''
						print(f'''{example} is {not_str}balanced''')




