

import unittest

from cer import CER


a_         =      CER()






class _UpperCamelCase							(							unittest.TestCase				):
			'''simple docstring'''







			def 							__UpperCamelCase	(     self							:	Any		)							->    Optional[int]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE				: Tuple			       =    ["White House"]
				SCREAMING_SNAKE_CASE				: Optional[int]			       =    ["white house"]
				# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
				SCREAMING_SNAKE_CASE				: Optional[Any]			       =    cer.compute(predictions=a , references=a		)
				self.assertTrue(abs(char_error_rate - 0.18_1818_1818		) < 1e-6		)
			def 							__UpperCamelCase	(     self							:	str		)							->    Union[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE				: Dict			       =    ["were wolf"]
				SCREAMING_SNAKE_CASE				: int			       =    ["werewolf"]
				# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
				SCREAMING_SNAKE_CASE				: Dict			       =    cer.compute(predictions=a , references=a		)
				self.assertTrue(abs(char_error_rate - 0.111_1111		) < 1e-6		)

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

				# consecutive whitespaces case 1
				SCREAMING_SNAKE_CASE				: List[str]			       =    ["were wolf"]
				SCREAMING_SNAKE_CASE				: str			       =    ["were               wolf"]
				# S = 0, D = 0, I = 0, N = 9, CER = 0
				SCREAMING_SNAKE_CASE				: Union[str, Any]			       =    cer.compute(predictions=a , references=a		)
				self.assertTrue(abs(char_error_rate - 0.0		) < 1e-6		)

				# consecutive whitespaces case 2
				SCREAMING_SNAKE_CASE				: int			       =    ["were   wolf"]
				SCREAMING_SNAKE_CASE				: Any			       =    ["were               wolf"]
				# S = 0, D = 0, I = 0, N = 9, CER = 0
				SCREAMING_SNAKE_CASE				: List[str]			       =    cer.compute(predictions=a , references=a		)
				self.assertTrue(abs(char_error_rate - 0.0		) < 1e-6		)
			def 							__UpperCamelCase	(     self							:	Union[str, Any]		)							->    Tuple:

				"""simple docstring"""

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

				"""simple docstring"""

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

				"""simple docstring"""

				SCREAMING_SNAKE_CASE				: Optional[int]			       =    ["werewolf"]
				SCREAMING_SNAKE_CASE				: List[Any]			       =    ["wereolf"]
				# S = 0, D = 0, I = 1, N = 8, CER = 0.125
				SCREAMING_SNAKE_CASE				: Tuple			       =    cer.compute(predictions=a , references=a		)
				self.assertTrue(abs(char_error_rate - 0.125		) < 1e-6		)
			def 							__UpperCamelCase	(     self							:	Dict		)							->    Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE				: int			       =    ["werewolf"]
				SCREAMING_SNAKE_CASE				: Dict			       =    cer.compute(predictions=a , references=a		)
				self.assertEqual(a , 0.0		)
			def 							__UpperCamelCase	(     self							:	List[Any]		)							->    Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE				: str			       =    ["werewolf", "I am your father"]
				SCREAMING_SNAKE_CASE				: Tuple			       =    cer.compute(predictions=a , references=a		)
				self.assertEqual(a , 0.0		)

				SCREAMING_SNAKE_CASE				: List[Any]			       =    ["werewolf", "I am your father", "doge"]
				SCREAMING_SNAKE_CASE				: Optional[int]			       =    ["werxwolf", "I       am your father", "doge"]
				# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
				SCREAMING_SNAKE_CASE				: Optional[Any]			       =    cer.compute(predictions=a , references=a		)
				self.assertTrue(abs(char_error_rate - 0.0357_1428		) < 1e-6		)
			def 							__UpperCamelCase	(     self							:	Tuple		)							->    Optional[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE				: List[Any]			       =    ["My hovercraft", "is full of eels"]
				SCREAMING_SNAKE_CASE				: Optional[Any]			       =    ["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
				SCREAMING_SNAKE_CASE				: Union[str, Any]			       =    cer.compute(predictions=a , references=a , concatenate_texts=a		)
				self.assertTrue(abs(char_error_rate - 0.07_1428		) < 1e-6		)
			def 							__UpperCamelCase	(     self							:	Any		)							->    Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE				: Optional[Any]			       =    ["我能吞下玻璃而不伤身体"]
				SCREAMING_SNAKE_CASE				: Union[str, Any]			       =    [" 能吞虾玻璃而 不霜身体啦"]
				# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
				SCREAMING_SNAKE_CASE				: Dict			       =    cer.compute(predictions=a , references=a		)
				self.assertTrue(abs(char_error_rate - 0.45_4545_4545		) < 1e-6		)

				SCREAMING_SNAKE_CASE				: str			       =    ["我能吞下玻璃", "而不伤身体"]
				SCREAMING_SNAKE_CASE				: List[Any]			       =    ["我    能 吞 下 玻 璃", "而不伤身体"]
				# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
				SCREAMING_SNAKE_CASE				: str			       =    cer.compute(predictions=a , references=a		)
				self.assertTrue(abs(char_error_rate - 0.4545_4545_4545		) < 1e-6		)

				SCREAMING_SNAKE_CASE				: str			       =    ["我能吞下玻璃而不伤身体"]
				SCREAMING_SNAKE_CASE				: Tuple			       =    cer.compute(predictions=a , references=a		)
				self.assertFalse(a , 0.0		)






			def 							__UpperCamelCase	(     self							:	Any		)							->    Union[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE				: List[str]			       =    [""]
				SCREAMING_SNAKE_CASE				: int			       =    ["Hypothesis"]
				with self.assertRaises(a		):
					cer.compute(predictions=a , references=a		)


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


from __future__ import annotations

from typing import Any






class _UpperCamelCase							:
			'''simple docstring'''







			def __init__(     self							:	Dict , a							:	Any , a							:	Any		)							->    None:  # noqa: A002

				"""simple docstring"""

				SCREAMING_SNAKE_CASE				: str			       =    item
				SCREAMING_SNAKE_CASE				: List[Any]			       =    next






class _UpperCamelCase							:
			'''simple docstring'''







			def __init__(     self							:	Optional[int]		)							->    None:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE				: Node | None			       =    None
				SCREAMING_SNAKE_CASE				: List[Any]			       =    0
			def 							__UpperCamelCase	(     self							:	Union[str, Any] , a							:	Any		)							->    None:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE				: Any			       =    Node(a , self.head		)
				self.size += 1
			def 							__UpperCamelCase	(     self							:	Dict		)							->    Any:

				"""simple docstring"""

				if self.head is None:
					return None
				else:
					SCREAMING_SNAKE_CASE				: Optional[int]			       =    self.head.item
					SCREAMING_SNAKE_CASE				: Dict			       =    self.head.next
					self.size -= 1
					return item
			def 							__UpperCamelCase	(     self							:	Any		)							->    bool:

				"""simple docstring"""

				return self.head is None
			def __str__(     self							:	Union[str, Any]		)							->    str:

				"""simple docstring"""

				if self.is_empty():
					return ""
				else:
					SCREAMING_SNAKE_CASE				: Union[str, Any]			       =    self.head
					SCREAMING_SNAKE_CASE				: str			       =    ""
					SCREAMING_SNAKE_CASE				: list[str]			       =    []
					while iterate:
						item_list.append(str(iterate.item		)		)
						SCREAMING_SNAKE_CASE				: str			       =    iterate.next

					SCREAMING_SNAKE_CASE				: List[str]			       =    " --> ".join(a		)

					return item_str






			def __len__(     self							:	List[Any]		)							->    int:

				"""simple docstring"""

				return self.size