



import unittest

from cer import CER


UpperCAmelCase								=   CER()

class 	__snake_case (				unittest.TestCase):







							'''simple docstring'''






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


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

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

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

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


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


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


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


							def _a (							self						):
											a__			 =						["""werewolf"""]
											a__			 =						cer.compute(predictions=a_					,					references=a_						)
											self.assertEqual(a_					,					0.0						)


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

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


							def _a (							self						):
											a__			 =						["""My hovercraft""", """is full of eels"""]
											a__			 =						["""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
											a__			 =						cer.compute(predictions=a_					,					references=a_					,					concatenate_texts=a_						)
											self.assertTrue(abs(char_error_rate - 0.071_428						) < 1E-6						)


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

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

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







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


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






def      A_ (		__a       :			float						):

				"""simple docstring"""
				return int(__a						) if x - int(__a						) >= 0 else int(__a						) - 1


if __name__ == "__main__":
	import doctest

	doctest.testmod()

