






import unittest

from cer import CER


__snake_case     :     Union[str, Any]       =  CER()


class      __SCREAMING_SNAKE_CASE       ( unittest.TestCase):






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    ['White House']
												lowerCAmelCase__         =    ['white house']
												# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
												lowerCAmelCase__         =    cer.compute(predictions=_lowercase  ,    references=_lowercase )
												self.assertTrue(abs(char_error_rate - 0.18_18_18_18_18 ) < 1E-6 )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    ['were wolf']
												lowerCAmelCase__         =    ['werewolf']
												# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
												lowerCAmelCase__         =    cer.compute(predictions=_lowercase  ,    references=_lowercase )
												self.assertTrue(abs(char_error_rate - 0.1_11_11_11 ) < 1E-6 )

												lowerCAmelCase__         =    ['werewolf']
												lowerCAmelCase__         =    ['weae     wolf']
												# S = 1, D = 1, I = 0, N = 8, CER = 0.25
												lowerCAmelCase__         =    cer.compute(predictions=_lowercase  ,    references=_lowercase )
												self.assertTrue(abs(char_error_rate - 0.25 ) < 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=_lowercase  ,    references=_lowercase )
												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=_lowercase  ,    references=_lowercase )
												self.assertTrue(abs(char_error_rate - 0.0 ) < 1E-6 )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    ['werewolf']
												lowerCAmelCase__         =    ['weaewolf']
												# S = 1, D = 0, I = 0, N = 8, CER = 0.125
												lowerCAmelCase__         =    cer.compute(predictions=_lowercase  ,    references=_lowercase )
												self.assertTrue(abs(char_error_rate - 0.1_25 ) < 1E-6 )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    ['werewolf']
												lowerCAmelCase__         =    ['wereawolf']
												# S = 0, D = 1, I = 0, N = 8, CER = 0.125
												lowerCAmelCase__         =    cer.compute(predictions=_lowercase  ,    references=_lowercase )
												self.assertTrue(abs(char_error_rate - 0.1_25 ) < 1E-6 )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    ['werewolf']
												lowerCAmelCase__         =    ['wereolf']
												# S = 0, D = 0, I = 1, N = 8, CER = 0.125
												lowerCAmelCase__         =    cer.compute(predictions=_lowercase  ,    references=_lowercase )
												self.assertTrue(abs(char_error_rate - 0.1_25 ) < 1E-6 )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    ['werewolf']
												lowerCAmelCase__         =    cer.compute(predictions=_lowercase  ,    references=_lowercase )
												self.assertEqual(_lowercase  ,    0.0 )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    ['werewolf', 'I am your father']
												lowerCAmelCase__         =    cer.compute(predictions=_lowercase  ,    references=_lowercase )
												self.assertEqual(_lowercase  ,    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=_lowercase  ,    references=_lowercase )
												self.assertTrue(abs(char_error_rate - 0.03_57_14_28 ) < 1E-6 )






						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												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=_lowercase  ,    references=_lowercase  ,    concatenate_texts=_lowercase )
												self.assertTrue(abs(char_error_rate - 0.07_14_28 ) < 1E-6 )






						def    UpperCamelCase__   (						self ):






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

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

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







						def    UpperCamelCase__   (						self ):






												"""simple docstring"""
												lowerCAmelCase__         =    ['']
												lowerCAmelCase__         =    ['Hypothesis']
												with self.assertRaises(_lowercase ):
																		cer.compute(predictions=_lowercase  ,    references=_lowercase )


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






import unittest

import torch

from diffusers import DDIMScheduler, TextToVideoZeroPipeline
from diffusers.utils import load_pt, require_torch_gpu, slow

from ..test_pipelines_common import assert_mean_pixel_difference







@slow
@require_torch_gpu
class __snake_case							(		unittest.TestCase						):




   def       __a		(       self     :							List[Any] ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= """runwayml/stable-diffusion-v1-5"""
     SCREAMING_SNAKE_CASE__     				= TextToVideoZeroPipeline.from_pretrained(_lowercase			,      torch_dtype=torch.floataa ).to("""cuda""" )
     SCREAMING_SNAKE_CASE__     				= DDIMScheduler.from_config(pipe.scheduler.config )
     SCREAMING_SNAKE_CASE__     				= torch.Generator(device="""cuda""" ).manual_seed(0 )

     SCREAMING_SNAKE_CASE__     				= """A bear is playing a guitar on Times Square"""
     SCREAMING_SNAKE_CASE__     				= pipe(prompt=_lowercase			,      generator=_lowercase ).images

     SCREAMING_SNAKE_CASE__     				= load_pt(
         """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/text-to-video/A bear is playing a guitar on Times Square.pt""" )

     assert_mean_pixel_difference(_lowercase			,      _lowercase )
