
"""simple docstring"""




import unittest

from transformers.testing_utils import CaptureStdout
from transformers.tools.python_interpreter import evaluate



def 							a__ (				lowerCAmelCase	:       str		):






     '''simple docstring'''
     return x + 2







class   _lowercase						(       unittest.TestCase				):


     '''simple docstring'''





     def  lowerCAmelCase__       (      self  )->					str:
          UpperCAmelCase__							: Dict 							=						"x = 3"
          UpperCAmelCase__							: Optional[Any] 							=						{}
          UpperCAmelCase__							: int 							=						evaluate(__UpperCamelCase ,			{} ,			state=__UpperCamelCase  )
          assert result == 3
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3}  )

          UpperCAmelCase__							: Optional[Any] 							=						"x = y"
          UpperCAmelCase__							: Optional[int] 							=						{"y": 5}
          UpperCAmelCase__							: Any 							=						evaluate(__UpperCamelCase ,			{} ,			state=__UpperCamelCase  )
          # evaluate returns the value of the last assignment.
          assert result == 5
          self.assertDictEqual(__UpperCamelCase ,			{"x": 5, "y": 5}  )



     def  lowerCAmelCase__       (      self  )->					Optional[Any]:
          UpperCAmelCase__							: Optional[Any] 							=						"y = add_two(x)"
          UpperCAmelCase__							: List[str] 							=						{"x": 3}
          UpperCAmelCase__							: Tuple 							=						evaluate(__UpperCamelCase ,			{"add_two": add_two} ,			state=__UpperCamelCase  )
          assert result == 5
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3, "y": 5}  )

          # Won't work without the tool
          with CaptureStdout() as out:
               UpperCAmelCase__							: Any 							=						evaluate(__UpperCamelCase ,			{} ,			state=__UpperCamelCase  )
          assert result is None
          assert "tried to execute add_two" in out.out



     def  lowerCAmelCase__       (      self  )->					Union[str, Any]:
          UpperCAmelCase__							: Optional[Any] 							=						"x = 3"
          UpperCAmelCase__							: List[str] 							=						{}
          UpperCAmelCase__							: Dict 							=						evaluate(__UpperCamelCase ,			{} ,			state=__UpperCamelCase  )
          assert result == 3
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3}  )



     def  lowerCAmelCase__       (      self  )->					List[str]:
          UpperCAmelCase__							: List[str] 							=						"test_dict = {'x': x, 'y': add_two(x)}"
          UpperCAmelCase__							: Optional[Any] 							=						{"x": 3}
          UpperCAmelCase__							: int 							=						evaluate(__UpperCamelCase ,			{"add_two": add_two} ,			state=__UpperCamelCase  )
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3, "y": 5}  )
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3, "test_dict": {"x": 3, "y": 5}}  )



     def  lowerCAmelCase__       (      self  )->					Tuple:
          UpperCAmelCase__							: Optional[int] 							=						"x = 3\ny = 5"
          UpperCAmelCase__							: Optional[int] 							=						{}
          UpperCAmelCase__							: List[str] 							=						evaluate(__UpperCamelCase ,			{} ,			state=__UpperCamelCase  )
          # evaluate returns the value of the last assignment.
          assert result == 5
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3, "y": 5}  )



     def  lowerCAmelCase__       (      self  )->					Optional[int]:
          UpperCAmelCase__							: Union[str, Any] 							=						"text = f'This is x: {x}.'"
          UpperCAmelCase__							: Any 							=						{"x": 3}
          UpperCAmelCase__							: Union[str, Any] 							=						evaluate(__UpperCamelCase ,			{} ,			state=__UpperCamelCase  )
          # evaluate returns the value of the last assignment.
          assert result == "This is x: 3."
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3, "text": "This is x: 3."}  )



     def  lowerCAmelCase__       (      self  )->					Optional[Any]:
          UpperCAmelCase__							: Union[str, Any] 							=						"if x <= 3:\n    y = 2\nelse:\n    y = 5"
          UpperCAmelCase__							: str 							=						{"x": 3}
          UpperCAmelCase__							: Union[str, Any] 							=						evaluate(__UpperCamelCase ,			{} ,			state=__UpperCamelCase  )
          # evaluate returns the value of the last assignment.
          assert result == 2
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3, "y": 2}  )

          UpperCAmelCase__							: Tuple 							=						{"x": 8}
          UpperCAmelCase__							: str 							=						evaluate(__UpperCamelCase ,			{} ,			state=__UpperCamelCase  )
          # evaluate returns the value of the last assignment.
          assert result == 5
          self.assertDictEqual(__UpperCamelCase ,			{"x": 8, "y": 5}  )



     def  lowerCAmelCase__       (      self  )->					List[str]:
          UpperCAmelCase__							: Optional[int] 							=						"test_list = [x, add_two(x)]"
          UpperCAmelCase__							: str 							=						{"x": 3}
          UpperCAmelCase__							: Tuple 							=						evaluate(__UpperCamelCase ,			{"add_two": add_two} ,			state=__UpperCamelCase  )
          self.assertListEqual(__UpperCamelCase ,			[3, 5]  )
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3, "test_list": [3, 5]}  )



     def  lowerCAmelCase__       (      self  )->					Optional[Any]:
          UpperCAmelCase__							: int 							=						"y = x"
          UpperCAmelCase__							: Optional[int] 							=						{"x": 3}
          UpperCAmelCase__							: Optional[int] 							=						evaluate(__UpperCamelCase ,			{} ,			state=__UpperCamelCase  )
          assert result == 3
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3, "y": 3}  )



     def  lowerCAmelCase__       (      self  )->					List[str]:
          UpperCAmelCase__							: Any 							=						"test_list = [x, add_two(x)]\ntest_list[1]"
          UpperCAmelCase__							: Tuple 							=						{"x": 3}
          UpperCAmelCase__							: str 							=						evaluate(__UpperCamelCase ,			{"add_two": add_two} ,			state=__UpperCamelCase  )
          assert result == 5
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3, "test_list": [3, 5]}  )

          UpperCAmelCase__							: List[Any] 							=						"test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"
          UpperCAmelCase__							: Union[str, Any] 							=						{"x": 3}
          UpperCAmelCase__							: Optional[int] 							=						evaluate(__UpperCamelCase ,			{"add_two": add_two} ,			state=__UpperCamelCase  )
          assert result == 5
          self.assertDictEqual(__UpperCamelCase ,			{"x": 3, "test_dict": {"x": 3, "y": 5}}  )



     def  lowerCAmelCase__       (      self  )->					Any:
          UpperCAmelCase__							: Any 							=						"x = 0\nfor i in range(3):\n    x = i"
          UpperCAmelCase__							: Optional[Any] 							=						{}
          UpperCAmelCase__							: str 							=						evaluate(__UpperCamelCase ,			{"range": range} ,			state=__UpperCamelCase  )
          assert result == 2
          self.assertDictEqual(__UpperCamelCase ,			{"x": 2, "i": 2}  )





"""simple docstring"""




from timeit import timeit



def 							a__ (				lowerCAmelCase	:       int		):






     '''simple docstring'''
     if number < 0:
          raise ValueError("the value of input must not be negative"		)
     UpperCAmelCase__							: Tuple 							=						0
     while number:
          number &= number - 1
          result += 1
     return result



def 							a__ (				lowerCAmelCase	:       int		):






     '''simple docstring'''
     if number < 0:
          raise ValueError("the value of input must not be negative"		)
     UpperCAmelCase__							: Union[str, Any] 							=						0
     while number:
          if number % 2 == 1:
               result += 1
          number >>= 1
     return result



def 							a__ (				):






     '''simple docstring'''

     def do_benchmark(lowerCAmelCase	:       int		) -> None:
          UpperCAmelCase__							: Dict 							=						"import __main__ as z"
          print(F"Benchmark when {number = }:"		)
          print(F"{get_set_bits_count_using_modulo_operator(lowerCAmelCase		) = }"		)
          UpperCAmelCase__							: Tuple 							=						timeit("z.get_set_bits_count_using_modulo_operator(25)"       ,    setup=lowerCAmelCase		)
          print(F"timeit() runs in {timing} seconds"		)
          print(F"{get_set_bits_count_using_brian_kernighans_algorithm(lowerCAmelCase		) = }"		)
          UpperCAmelCase__							: Any 							=						timeit(
              "z.get_set_bits_count_using_brian_kernighans_algorithm(25)"       ,    setup=lowerCAmelCase       ,    )
          print(F"timeit() runs in {timing} seconds"		)

     for number in (25, 37, 58, 0):
          do_benchmark(lowerCAmelCase		)
          print()


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    benchmark()



