

import unittest

from cer import CER


UpperCamelCase__     :					Optional[Any]								=			CER()



class 					__snake_case     (			unittest.TestCase				):

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

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

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

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

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

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

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

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

  def   lowerCAmelCase__   (    self):
      SCREAMING_SNAKE_CASE_													=  ['werewolf']
      SCREAMING_SNAKE_CASE_													=  cer.compute(predictions=_A  ,						references=_A)
      self.assertEqual(_A  ,						0.0)

  def   lowerCAmelCase__   (    self):
      SCREAMING_SNAKE_CASE_													=  ['werewolf', 'I am your father']
      SCREAMING_SNAKE_CASE_													=  cer.compute(predictions=_A  ,						references=_A)
      self.assertEqual(_A  ,						0.0)

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

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

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

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

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


  def   lowerCAmelCase__   (    self):
      SCREAMING_SNAKE_CASE_													=  ['']
      SCREAMING_SNAKE_CASE_													=  ['Hypothesis']
      with self.assertRaises(_A):
          cer.compute(predictions=_A  ,						references=_A)


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





def     _UpperCAmelCase				(     _SCREAMING_SNAKE_CASE    :						str				):





    """simple docstring"""


    return "".join(chr(ord(_SCREAMING_SNAKE_CASE				) + 32				) if 'A' <= char <= 'Z' else char for char in word				)


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

       testmod()


