

"""simple docstring"""


import os
import unittest

from transformers.models.cpmant.tokenization_cpmant import VOCAB_FILES_NAMES, CpmAntTokenizer
from transformers.testing_utils import require_jieba, tooslow

from ...test_tokenization_common import TokenizerTesterMixin





@require_jieba
class lowerCamelCase__   (				SCREAMING_SNAKE_CASE     ,   unittest.TestCase    ):



    '''simple docstring'''




    _lowerCamelCase					=   CpmAntTokenizer
    _lowerCamelCase					=   False




    def UpperCamelCase__		( self    )    ->      List[Any]:
          super().setUp()

          A				  =		[
              """<d>""",
              """</d>""",
              """<s>""",
              """</s>""",
              """</_>""",
              """<unk>""",
              """<pad>""",
              """</n>""",
              """我""",
              """是""",
              """C""",
              """P""",
              """M""",
              """A""",
              """n""",
              """t""",
          ]
          A				  =		os.path.join(self.tmpdirname ,VOCAB_FILES_NAMES["""vocab_file"""]    )
          with open(self.vocab_file ,"""w""" ,encoding="""utf-8"""    ) as vocab_writer:
                vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]    )    )




    @tooslow
    def UpperCamelCase__		( self    )    ->      List[Any]:
          A				  =		CpmAntTokenizer.from_pretrained("""openbmb/cpm-ant-10b"""    )
          A				  =		"""今天天气真好！"""
          A				  =		["""今天""", """天气""", """真""", """好""", """！"""]
          A				  =		tokenizer.tokenize(lowerCamelCase_    )
          self.assertListEqual(lowerCamelCase_ ,lowerCamelCase_    )
          A				  =		"""今天天气真好！"""
          A				  =		[tokenizer.bos_token] + tokens

          A				  =		[6, 9_8_0_2, 1_4_9_6_2, 2_0_8_2, 8_3_1, 2_4_4]
          self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase_    ) ,lowerCamelCase_    )

          A				  =		tokenizer.decode(lowerCamelCase_    )
          self.assertEqual(lowerCamelCase_ ,lowerCamelCase_    )







"""simple docstring"""


import unittest

from knapsack import greedy_knapsack as kp





class lowerCamelCase__   (				unittest.TestCase    ):



    '''simple docstring'''




    def UpperCamelCase__		( self    )    ->      Any:
          A				  =		[1_0, 2_0, 3_0, 4_0, 5_0, 6_0]
          A				  =		[2, 4, 6, 8, 1_0, 1_2]
          A				  =		1_0_0
          self.assertEqual(kp.calc_profit(lowerCamelCase_ ,lowerCamelCase_ ,lowerCamelCase_    ) ,2_1_0    )




    def UpperCamelCase__		( self    )    ->      List[Any]:
          self.assertRaisesRegex(lowerCamelCase_ ,"""max_weight must greater than zero."""    )




    def UpperCamelCase__		( self    )    ->      Any:
          self.assertRaisesRegex(lowerCamelCase_ ,"""Weight can not be negative."""    )




    def UpperCamelCase__		( self    )    ->      str:
          self.assertRaisesRegex(lowerCamelCase_ ,"""Profit can not be negative."""    )




    def UpperCamelCase__		( self    )    ->      Optional[int]:
          self.assertRaisesRegex(lowerCamelCase_ ,"""max_weight must greater than zero."""    )




    def UpperCamelCase__		( self    )    ->      str:
          self.assertRaisesRegex(
              lowerCamelCase_ ,"""The length of profit and weight must be same."""    )


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




