





"""simple docstring"""





import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
  import torch

  from transformers.generation import DisjunctiveConstraint






@require_torch
class 					_lowerCAmelCase   (     unittest.TestCase       ):
       """simple docstring"""




       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Union[str, Any]											=							[[1, 2, 4], [1, 2, 3, 4]]
         lowerCAmelCase__			:Any											=							DisjunctiveConstraint(__UpperCAmelCase      )
         self.assertTrue(isinstance(dc.token_ids    , __UpperCAmelCase      )      )

         with self.assertRaises(__UpperCAmelCase      ):
           DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]      )      )

         with self.assertRaises(__UpperCAmelCase      ):
           DisjunctiveConstraint([torch.LongTensor([1, 2, 4]      ), torch.LongTensor([1, 2, 3, 4, 5]      )]      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:int											=							[[1, 2], [1, 2, 3, 4]]

         with self.assertRaises(__UpperCAmelCase      ):
           DisjunctiveConstraint(__UpperCAmelCase      )  # fails here






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Any											=							[[1, 2, 3], [1, 2, 4]]

         lowerCAmelCase__			:Optional[Any]											=							DisjunctiveConstraint(__UpperCAmelCase      )

         lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:List[Any]											=							dc.update(1      )
         lowerCAmelCase__			:Dict											=							stepped is True and completed is False and reset is False
         self.assertTrue(__UpperCAmelCase      )
         self.assertTrue(not dc.completed      )
         self.assertTrue(dc.current_seq == [1]      )

         lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:Any											=							dc.update(2      )
         lowerCAmelCase__			:Union[str, Any]											=							stepped is True and completed is False and reset is False
         self.assertTrue(__UpperCAmelCase      )
         self.assertTrue(not dc.completed      )
         self.assertTrue(dc.current_seq == [1, 2]      )

         lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:Optional[Any]											=							dc.update(3      )
         lowerCAmelCase__			:Any											=							stepped is True and completed is True and reset is False
         self.assertTrue(__UpperCAmelCase      )
         self.assertTrue(dc.completed      )  # Completed!
         self.assertTrue(dc.current_seq == [1, 2, 3]      )






       def      snake_case						(    self      ):



         '''simple docstring'''

         lowerCAmelCase__			:Any											=							[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

         lowerCAmelCase__			:str											=							DisjunctiveConstraint(__UpperCAmelCase      )

         lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:Dict											=							dc.update(1      )
         self.assertTrue(not dc.completed      )
         self.assertTrue(dc.current_seq == [1]      )

         lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:Any											=							dc.update(2      )
         self.assertTrue(not dc.completed      )
         self.assertTrue(dc.current_seq == [1, 2]      )

         lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:Dict											=							dc.update(4      )
         self.assertTrue(not dc.completed      )
         self.assertTrue(dc.current_seq == [1, 2, 4]      )

         lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:int											=							dc.update(5      )
         self.assertTrue(dc.completed      )  # Completed!
         self.assertTrue(dc.current_seq == [1, 2, 4, 5]      )

         dc.reset()

         lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:Tuple											=							dc.update(1      )
         self.assertTrue(not dc.completed      )
         self.assertTrue(dc.remaining() == 3      )
         self.assertTrue(dc.current_seq == [1]      )

         lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:Union[str, Any]											=							dc.update(2      )
         self.assertTrue(not dc.completed      )
         self.assertTrue(dc.remaining() == 2      )
         self.assertTrue(dc.current_seq == [1, 2]      )

         lowerCAmelCase__							,				lowerCAmelCase__							,				lowerCAmelCase__			:Optional[Any]											=							dc.update(5      )
         self.assertTrue(dc.completed      )  # Completed!
         self.assertTrue(dc.remaining() == 0      )
         self.assertTrue(dc.current_seq == [1, 2, 5]      )







"""simple docstring"""





def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE			)					->float:





  """simple docstring"""


  if discount_rate < 0:
    raise ValueError('Discount rate cannot be negative'			)
  if not cash_flows:
    raise ValueError('Cash flows list cannot be empty'			)
  lowerCAmelCase__			:Union[str, Any]											=							sum(
      cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_SCREAMING_SNAKE_CASE			)			)
  return round(_SCREAMING_SNAKE_CASE     ,   ndigits=2			)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
