





import unittest

from cer import CER


UpperCAmelCase__  :	str     =CER()

class 					__A   (  unittest.TestCase			):


				def _snake_case				(						self							):
								lowerCamelCase		       =["""White House"""]
								lowerCamelCase		       =["""white house"""]
								# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
								lowerCamelCase		       =cer.compute(predictions=UpperCAmelCase_      ,       references=UpperCAmelCase_							)
								self.assertTrue(abs(char_error_rate - 0.1_8_1_8_1_8_1_8_1_8							) < 1E-6							)


				def _snake_case				(						self							):
								lowerCamelCase		       =["""were wolf"""]
								lowerCamelCase		       =["""werewolf"""]
								# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
								lowerCamelCase		       =cer.compute(predictions=UpperCAmelCase_      ,       references=UpperCAmelCase_							)
								self.assertTrue(abs(char_error_rate - 0.1_1_1_1_1_1_1							) < 1E-6							)

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

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

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


				def _snake_case				(						self							):
								lowerCamelCase		       =["""werewolf"""]
								lowerCamelCase		       =["""weaewolf"""]
								# S = 1, D = 0, I = 0, N = 8, CER = 0.125
								lowerCamelCase		       =cer.compute(predictions=UpperCAmelCase_      ,       references=UpperCAmelCase_							)
								self.assertTrue(abs(char_error_rate - 0.1_2_5							) < 1E-6							)


				def _snake_case				(						self							):
								lowerCamelCase		       =["""werewolf"""]
								lowerCamelCase		       =["""wereawolf"""]
								# S = 0, D = 1, I = 0, N = 8, CER = 0.125
								lowerCamelCase		       =cer.compute(predictions=UpperCAmelCase_      ,       references=UpperCAmelCase_							)
								self.assertTrue(abs(char_error_rate - 0.1_2_5							) < 1E-6							)


				def _snake_case				(						self							):
								lowerCamelCase		       =["""werewolf"""]
								lowerCamelCase		       =["""wereolf"""]
								# S = 0, D = 0, I = 1, N = 8, CER = 0.125
								lowerCamelCase		       =cer.compute(predictions=UpperCAmelCase_      ,       references=UpperCAmelCase_							)
								self.assertTrue(abs(char_error_rate - 0.1_2_5							) < 1E-6							)


				def _snake_case				(						self							):
								lowerCamelCase		       =["""werewolf"""]
								lowerCamelCase		       =cer.compute(predictions=UpperCAmelCase_      ,       references=UpperCAmelCase_							)
								self.assertEqual(UpperCAmelCase_      ,       0.0							)


				def _snake_case				(						self							):
								lowerCamelCase		       =["""werewolf""", """I am your father"""]
								lowerCamelCase		       =cer.compute(predictions=UpperCAmelCase_      ,       references=UpperCAmelCase_							)
								self.assertEqual(UpperCAmelCase_      ,       0.0							)

								lowerCamelCase		       =["""werewolf""", """I am your father""", """doge"""]
								lowerCamelCase		       =["""werxwolf""", """I       am your father""", """doge"""]
								# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
								lowerCamelCase		       =cer.compute(predictions=UpperCAmelCase_      ,       references=UpperCAmelCase_							)
								self.assertTrue(abs(char_error_rate - 0.0_3_5_7_1_4_2_8							) < 1E-6							)


				def _snake_case				(						self							):
								lowerCamelCase		       =["""My hovercraft""", """is full of eels"""]
								lowerCamelCase		       =["""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
								lowerCamelCase		       =cer.compute(predictions=UpperCAmelCase_      ,       references=UpperCAmelCase_      ,       concatenate_texts=UpperCAmelCase_							)
								self.assertTrue(abs(char_error_rate - 0.0_7_1_4_2_8							) < 1E-6							)


				def _snake_case				(						self							):
								lowerCamelCase		       =["""我能吞下玻璃而不伤身体"""]
								lowerCamelCase		       =[""" 能吞虾玻璃而 不霜身体啦"""]
								# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
								lowerCamelCase		       =cer.compute(predictions=UpperCAmelCase_      ,       references=UpperCAmelCase_							)
								self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5							) < 1E-6							)

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

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


				def _snake_case				(						self							):
								lowerCamelCase		       =[""""""]
								lowerCamelCase		       =["""Hypothesis"""]
								with self.assertRaises(UpperCAmelCase_							):
												cer.compute(predictions=UpperCAmelCase_      ,       references=UpperCAmelCase_							)


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







"""simple docstring"""

from __future__ import annotations
def 		UpperCAmelCase					(		a_			):





		'''simple docstring'''


		assert (
		    isinstance(a_,						a_			) and mask > 0
		), F"""mask needs to be positive integer, your input {mask}"""
		lowerCamelCase     :			Tuple		=    []
		lowerCamelCase     :			Tuple		=    mask

		while submask:
				all_submasks.append(a_			)
				lowerCamelCase     :			Optional[int]		=    (submask - 1) & mask

		return all_submasks


if __name__ == "__main__":
					import doctest

					doctest.testmod()






