code: 
  
  
  
  
  
  
  import unittest
  
  from cer import CER
  
  
  SCREAMING_SNAKE_CASE__		:       Optional[int]   							=							CER()
  
  
  
  
  
  
  
  class 							UpperCAmelCase_     (		unittest.TestCase		):
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Tuple										= ["""White House"""]
            UpperCAmelCase__			:     int										= ["""white house"""]
            # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
            UpperCAmelCase__			:     Optional[int]										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.1_8_1_8_1_8_1_8_1_8		) < 1e-6		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     List[str]										= ["""were wolf"""]
            UpperCAmelCase__			:     List[str]										= ["""werewolf"""]
            # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
            UpperCAmelCase__			:     int										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.1_1_1_1_1_1_1		) < 1e-6		)
  
            UpperCAmelCase__			:     Any										= ["""werewolf"""]
            UpperCAmelCase__			:     str										= ["""weae     wolf"""]
            # S = 1, D = 1, I = 0, N = 8, CER = 0.25
            UpperCAmelCase__			:     List[Any]										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.2_5		) < 1e-6		)
  
            # consecutive whitespaces case 1
            UpperCAmelCase__			:     Dict										= ["""were wolf"""]
            UpperCAmelCase__			:     int										= ["""were               wolf"""]
            # S = 0, D = 0, I = 0, N = 9, CER = 0
            UpperCAmelCase__			:     Dict										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.0		) < 1e-6		)
  
            # consecutive whitespaces case 2
            UpperCAmelCase__			:     str										= ["""were   wolf"""]
            UpperCAmelCase__			:     Union[str, Any]										= ["""were               wolf"""]
            # S = 0, D = 0, I = 0, N = 9, CER = 0
            UpperCAmelCase__			:     Tuple										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.0		) < 1e-6		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     int										= ["""werewolf"""]
            UpperCAmelCase__			:     Tuple										= ["""weaewolf"""]
            # S = 1, D = 0, I = 0, N = 8, CER = 0.125
            UpperCAmelCase__			:     Optional[int]										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.1_2_5		) < 1e-6		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Optional[int]										= ["""werewolf"""]
            UpperCAmelCase__			:     List[str]										= ["""wereawolf"""]
            # S = 0, D = 1, I = 0, N = 8, CER = 0.125
            UpperCAmelCase__			:     Optional[Any]										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.1_2_5		) < 1e-6		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Union[str, Any]										= ["""werewolf"""]
            UpperCAmelCase__			:     Optional[int]										= ["""wereolf"""]
            # S = 0, D = 0, I = 1, N = 8, CER = 0.125
            UpperCAmelCase__			:     Optional[int]										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.1_2_5		) < 1e-6		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Dict										= ["""werewolf"""]
            UpperCAmelCase__			:     Union[str, Any]										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertEqual(_lowerCAmelCase  ,	0.0		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Dict										= ["""werewolf""", """I am your father"""]
            UpperCAmelCase__			:     Tuple										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertEqual(_lowerCAmelCase  ,	0.0		)
  
            UpperCAmelCase__			:     int										= ["""werewolf""", """I am your father""", """doge"""]
            UpperCAmelCase__			:     Optional[int]										= ["""werxwolf""", """I       am your father""", """doge"""]
            # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
            UpperCAmelCase__			:     Dict										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.0_3_5_7_1_4_2_8		) < 1e-6		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Dict										= ["""My hovercraft""", """is full of eels"""]
            UpperCAmelCase__			:     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
            UpperCAmelCase__			:     Optional[Any]										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase  ,	concatenate_texts=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.0_7_1_4_2_8		) < 1e-6		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Optional[Any]										= ["""我能吞下玻璃而不伤身体"""]
            UpperCAmelCase__			:     List[str]										= [""" 能吞虾玻璃而 不霜身体啦"""]
            # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
            UpperCAmelCase__			:     Dict										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5		) < 1e-6		)
  
            UpperCAmelCase__			:     Optional[Any]										= ["""我能吞下玻璃""", """而不伤身体"""]
            UpperCAmelCase__			:     Any										= ["""我    能 吞 下 玻 璃""", """而不伤身体"""]
            # S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
            UpperCAmelCase__			:     Dict										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5_4_5		) < 1e-6		)
  
            UpperCAmelCase__			:     int										= ["""我能吞下玻璃而不伤身体"""]
            UpperCAmelCase__			:     Optional[int]										= cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
            self.assertFalse(_lowerCAmelCase  ,	0.0		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Optional[int]										= [""""""]
            UpperCAmelCase__			:     str										= ["""Hypothesis"""]
            with self.assertRaises(_lowerCAmelCase		):
                 cer.compute(predictions=_lowerCAmelCase  ,	references=_lowerCAmelCase		)
  
  
  if __name__ == "__main__":
        unittest.main()
  
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  import math
  import os
  
  import cva
  import numpy as np
  
  SCREAMING_SNAKE_CASE__		:       Optional[Any]   							=							255.0
  
  
  
  
  
  def    _lowerCamelCase	(	__lowerCamelCase   ,       __lowerCamelCase					)   -> float:
  
       '''simple docstring'''
       UpperCAmelCase__			:     List[Any]										= np.mean((original - contrast) ** 2					)
       if mse == 0:
            return 100
  
       return 20 * math.logaa(PIXEL_MAX / math.sqrt(__lowerCamelCase					)					)
  
  
  
  
  
  def    _lowerCamelCase	(	)   -> None:
  
       '''simple docstring'''
       UpperCAmelCase__			:     Union[str, Any]										= os.path.dirname(os.path.realpath(__lowerCamelCase					)					)
       # Loading images (original image and compressed image)
       UpperCAmelCase__			:     List[Any]										= cva.imread(os.path.join(__lowerCamelCase   ,       """image_data/original_image.png"""					)					)
       UpperCAmelCase__			:     Dict										= cva.imread(os.path.join(__lowerCamelCase   ,       """image_data/compressed_image.png"""					)   ,       1					)
  
       UpperCAmelCase__			:     Tuple										= cva.imread(os.path.join(__lowerCamelCase   ,       """image_data/PSNR-example-base.png"""					)					)
       UpperCAmelCase__			:     int										= cva.imread(
           os.path.join(__lowerCamelCase   ,       """image_data/PSNR-example-comp-10.jpg"""					)   ,       1					)
  
       # Value expected: 29.73dB
       print("""-- First Test --"""					)
       print(F"PSNR value is {peak_signal_to_noise_ratio(__lowerCamelCase   ,       __lowerCamelCase					)} dB"					)
  
       # # Value expected: 31.53dB (Wikipedia Example)
       print("""\n-- Second Test --"""					)
       print(F"PSNR value is {peak_signal_to_noise_ratio(__lowerCamelCase   ,       __lowerCamelCase					)} dB"					)
  
  
  if __name__ == "__main__":
        main()
  
  
  
  
  
  
  