diff --git "a/ClassEval_data.json" "b/ClassEval_data.json" --- "a/ClassEval_data.json" +++ "b/ClassEval_data.json" @@ -496,7 +496,7 @@ }, { "task_id": "ClassEval_5", - "skeleton": "\nclass AutomaticGuitarSimulator:\n \"\"\"\n This class is an automatic guitar simulator that can interpret and play based on the input guitar sheet music.\n \"\"\"\n\n def __init__(self, text) -> None:\n \"\"\"\n Initialize the score to be played\n :param text:str, score to be played\n \"\"\"\n self.play_text = text\n\n def interpret(self, display=False):\n \"\"\"\n Interpret the music score to be played\n :param display:Bool, representing whether to print the interpreted score\n :return:list of dict, The dict includes two fields, Chore and Tune, which are letters and numbers, respectively\n >>> context = AutomaticGuitarSimulator(\"C53231323 Em43231323 F43231323 G63231323\")\n >>> play_list = context.interpret(display = False)\n [{'Chord': 'C', 'Tune': '53231323'}, {'Chord': 'Em', 'Tune': '43231323'}, {'Chord': 'F', 'Tune': '43231323'}, {'Chord': 'G', 'Tune': '63231323'}]\n\n \"\"\"\n\n\n def display(self, key, value):\n \"\"\"\n Print out chord and play tune with following format: Normal Guitar Playing -- Chord: %s, Play Tune: %s\n :param key:str, chord\n :param value:str, play tune\n :return:None\n >>> context = AutomaticGuitarSimulator(\"C53231323 Em43231323 F43231323 G63231323\")\n >>> context.display(\"C\", \"53231323\")\n Normal Guitar Playing -- Chord: C, Play Tune: 53231323\n\n \"\"\"", + "skeleton": "\nclass AutomaticGuitarSimulator:\n \"\"\"\n This class is an automatic guitar simulator that can interpret and play based on the input guitar sheet music.\n \"\"\"\n\n def __init__(self, text) -> None:\n \"\"\"\n Initialize the score to be played\n :param text:str, score to be played\n \"\"\"\n self.play_text = text\n\n def interpret(self, display=False):\n \"\"\"\n Interpret the music score to be played\n :param display:Bool, representing whether to print the interpreted score\n :return:list of dict, The dict includes two fields, Chore and Tune, which are letters and numbers, respectively\n >>> context = AutomaticGuitarSimulator(\"C53231323 Em43231323 F43231323 G63231323\")\n >>> play_list = context.interpret(display = False)\n [{'Chord': 'C', 'Tune': '53231323'}, {'Chord': 'Em', 'Tune': '43231323'}, {'Chord': 'F', 'Tune': '43231323'}, {'Chord': 'G', 'Tune': '63231323'}]\n\n \"\"\"\n\n\n def display(self, key, value):\n \"\"\"\n Print out chord and play tune with following format: Normal Guitar Playing -- Chord: %s, Play Tune: %s\n :param key:str, chord\n :param value:str, play tune\n :return: str\n >>> context = AutomaticGuitarSimulator(\"C53231323 Em43231323 F43231323 G63231323\")\n >>> context.display(\"C\", \"53231323\")\n Normal Guitar Playing -- Chord: C, Play Tune: 53231323\n\n \"\"\"", "test": "import unittest\n\n\nclass AutomaticGuitarSimulatorTestInterpret(unittest.TestCase):\n def test_interpret_1(self):\n context = AutomaticGuitarSimulator(\"C53231323\")\n play_list = context.interpret()\n self.assertEqual(play_list, [{'Chord': 'C', 'Tune': '53231323'}])\n\n def test_interpret_2(self):\n context = AutomaticGuitarSimulator(\"F43231323\")\n play_list = context.interpret()\n self.assertEqual(play_list, [{'Chord': 'F', 'Tune': '43231323'}])\n\n def test_interpret_3(self):\n context = AutomaticGuitarSimulator(\"Em43231323\")\n play_list = context.interpret()\n self.assertEqual(play_list, [{'Chord': 'Em', 'Tune': '43231323'}])\n\n def test_interpret_4(self):\n context = AutomaticGuitarSimulator(\"G63231323\")\n play_list = context.interpret()\n self.assertEqual(play_list, [{'Chord': 'G', 'Tune': '63231323'}])\n\n def test_interpret_5(self):\n context = AutomaticGuitarSimulator(\"F43231323 G63231323\")\n play_list = context.interpret()\n self.assertEqual(play_list, [{'Chord': 'F', 'Tune': '43231323'}, {'Chord': 'G', 'Tune': '63231323'}])\n\n def test_interpret_6(self):\n context = AutomaticGuitarSimulator(\" \")\n play_list = context.interpret()\n self.assertEqual(play_list, [{'Chord': '', 'Tune': ''}, {'Chord': '', 'Tune': ''}])\n\n def test_interpret_7(self):\n context = AutomaticGuitarSimulator(\"ABC43231323 DEF63231323\")\n play_list = context.interpret()\n self.assertEqual(play_list, [{'Chord': 'ABC', 'Tune': '43231323'}, {'Chord': 'DEF', 'Tune': '63231323'}])\n\n def test_interpret_8(self):\n context = AutomaticGuitarSimulator(\"C53231323\")\n play_list = context.interpret(display=True)\n self.assertEqual(play_list, [{'Chord': 'C', 'Tune': '53231323'}])\n\n def test_interpret_9(self):\n context = AutomaticGuitarSimulator(\"\")\n play_list = context.interpret()\n self.assertIsNone(play_list)\n\n\nclass AutomaticGuitarSimulatorTestDisplay(unittest.TestCase):\n def test_display_1(self):\n context = AutomaticGuitarSimulator(\"C53231323 Em43231323\")\n play_list = context.interpret()\n str = context.display(play_list[0]['Chord'], play_list[0]['Tune'])\n self.assertEqual(str, \"Normal Guitar Playing -- Chord: C, Play Tune: 53231323\")\n\n def test_display_2(self):\n context = AutomaticGuitarSimulator(\"C53231323 Em43231323\")\n play_list = context.interpret()\n str = context.display(play_list[1]['Chord'], play_list[1]['Tune'])\n self.assertEqual(str, \"Normal Guitar Playing -- Chord: Em, Play Tune: 43231323\")\n\n def test_display_3(self):\n context = AutomaticGuitarSimulator(\"F43231323 G63231323\")\n play_list = context.interpret()\n str = context.display(play_list[0]['Chord'], play_list[0]['Tune'])\n self.assertEqual(str, \"Normal Guitar Playing -- Chord: F, Play Tune: 43231323\")\n\n def test_display_4(self):\n context = AutomaticGuitarSimulator(\"F43231323 G63231323\")\n play_list = context.interpret()\n str = context.display(play_list[1]['Chord'], play_list[1]['Tune'])\n self.assertEqual(str, \"Normal Guitar Playing -- Chord: G, Play Tune: 63231323\")\n\n def test_display_5(self):\n context = AutomaticGuitarSimulator(\"\")\n str = context.display('', '')\n self.assertEqual(str, \"Normal Guitar Playing -- Chord: , Play Tune: \")\n\n\nclass AutomaticGuitarSimulatorTest(unittest.TestCase):\n def test_AutomaticGuitarSimulator(self):\n context = AutomaticGuitarSimulator(\"C53231323\")\n play_list = context.interpret()\n self.assertEqual(play_list, [{'Chord': 'C', 'Tune': '53231323'}])\n\n context = AutomaticGuitarSimulator(\"C53231323 Em43231323\")\n play_list = context.interpret()\n str = context.display(play_list[0]['Chord'], play_list[0]['Tune'])\n self.assertEqual(str, \"Normal Guitar Playing -- Chord: C, Play Tune: 53231323\")", "solution_code": "class AutomaticGuitarSimulator:\n def __init__(self, text) -> None:\n self.play_text = text\n\n def interpret(self, display=False):\n if len(self.play_text) == 0:\n return\n else:\n play_list = []\n play_segs = self.play_text.split(\" \")\n for play_seg in play_segs:\n pos = 0\n for ele in play_seg:\n if ele.isalpha():\n pos += 1\n continue\n break\n play_chord = play_seg[0:pos]\n play_value = play_seg[pos:]\n play_list.append({'Chord': play_chord, 'Tune': play_value})\n if display:\n self.display(play_chord, play_value)\n return play_list\n\n def display(self, key, value):\n return \"Normal Guitar Playing -- Chord: %s, Play Tune: %s\" % (key, value)", "import_statement": [], @@ -531,7 +531,7 @@ }, { "method_name": "display", - "method_description": "def display(self, key, value):\n \"\"\"\n Print out chord and play tune with following format: Normal Guitar Playing -- Chord: %s, Play Tune: %s\n :param key:str, chord\n :param value:str, play tune\n :return:None\n >>> context = AutomaticGuitarSimulator(\"C53231323 Em43231323 F43231323 G63231323\")\n >>> context.display(\"C\", \"53231323\")\n Normal Guitar Playing -- Chord: C, Play Tune: 53231323\n\n \"\"\"", + "method_description": "def display(self, key, value):\n \"\"\"\n Print out chord and play tune with following format: Normal Guitar Playing -- Chord: %s, Play Tune: %s\n :param key:str, chord\n :param value:str, play tune\n :return: str\n >>> context = AutomaticGuitarSimulator(\"C53231323 Em43231323 F43231323 G63231323\")\n >>> context.display(\"C\", \"53231323\")\n Normal Guitar Playing -- Chord: C, Play Tune: 53231323\n\n \"\"\"", "test_class": "AutomaticGuitarSimulatorTestDisplay", "test_code": "class AutomaticGuitarSimulatorTestDisplay(unittest.TestCase):\n def test_display_1(self):\n context = AutomaticGuitarSimulator(\"C53231323 Em43231323\")\n play_list = context.interpret()\n str = context.display(play_list[0]['Chord'], play_list[0]['Tune'])\n self.assertEqual(str, \"Normal Guitar Playing -- Chord: C, Play Tune: 53231323\")\n\n def test_display_2(self):\n context = AutomaticGuitarSimulator(\"C53231323 Em43231323\")\n play_list = context.interpret()\n str = context.display(play_list[1]['Chord'], play_list[1]['Tune'])\n self.assertEqual(str, \"Normal Guitar Playing -- Chord: Em, Play Tune: 43231323\")\n\n def test_display_3(self):\n context = AutomaticGuitarSimulator(\"F43231323 G63231323\")\n play_list = context.interpret()\n str = context.display(play_list[0]['Chord'], play_list[0]['Tune'])\n self.assertEqual(str, \"Normal Guitar Playing -- Chord: F, Play Tune: 43231323\")\n\n def test_display_4(self):\n context = AutomaticGuitarSimulator(\"F43231323 G63231323\")\n play_list = context.interpret()\n str = context.display(play_list[1]['Chord'], play_list[1]['Tune'])\n self.assertEqual(str, \"Normal Guitar Playing -- Chord: G, Play Tune: 63231323\")\n\n def test_display_5(self):\n context = AutomaticGuitarSimulator(\"\")\n str = context.display('', '')\n self.assertEqual(str, \"Normal Guitar Playing -- Chord: , Play Tune: \")", "solution_code": "def display(self, key, value):\n return \"Normal Guitar Playing -- Chord: %s, Play Tune: %s\" % (key, value)", @@ -3775,7 +3775,7 @@ { "task_id": "ClassEval_44", "skeleton": "\nimport re\nimport string\nimport gensim\nfrom bs4 import BeautifulSoup\n\nclass HtmlUtil:\n \"\"\"\n This is a class as util for html, supporting for formatting and extracting code from HTML text, including cleaning up the text and converting certain elements into specific marks.\n \"\"\"\n\n def __init__(self):\n \"\"\"\n Initialize a series of labels\n \"\"\"\n self.SPACE_MARK = '-SPACE-'\n self.JSON_MARK = '-JSON-'\n self.MARKUP_LANGUAGE_MARK = '-MARKUP_LANGUAGE-'\n self.URL_MARK = '-URL-'\n self.NUMBER_MARK = '-NUMBER-'\n self.TRACE_MARK = '-TRACE-'\n self.COMMAND_MARK = '-COMMAND-'\n self.COMMENT_MARK = '-COMMENT-'\n self.CODE_MARK = '-CODE-'\n\n @staticmethod\n def __format_line_feed(text):\n \"\"\"\n Replace consecutive line breaks with a single line break\n :param text: string with consecutive line breaks\n :return:string, replaced text with single line break\n \"\"\"\n\n def format_line_html_text(self, html_text):\n \"\"\"\n get the html text without the code, and add the code tag -CODE- where the code is\n :param html_text:string\n :return:string\n >>>htmlutil = HtmlUtil()\n >>>htmlutil.format_line_html_text(\n >>>
\n >>>This is a paragraph.
\n >>>print('Hello, world!')\n >>>
Another paragraph.
\n >>>for i in range(5):\n >>> print(i)
\n >>> \n >>> )\n Title\n This is a paragraph.\n -CODE-\n Another paragraph.\n -CODE-\n \"\"\"\n\n def extract_code_from_html_text(self, html_text):\n \"\"\"\n extract codes from the html body\n :param html_text: string, html text\n :return: the list of code\n >>>htmlutil = HtmlUtil()\n >>>htmlutil.extract_code_from_html_text(\n >>> \n >>> This is a paragraph.
\n >>>print('Hello, world!')\n >>>
Another paragraph.
\n >>>for i in range(5):\n >>> print(i)
\n >>> \n >>> )\n [\"print('Hello, world!')\", 'for i in range(5):\\n print(i)']\n \"\"\"",
- "test": "import unittest\nimport sys\nsys.path.append(r'C:\\Users\\86181\\Desktop\\forgit\\SE-Eval-Benchmark')\nfrom benchmark_code.HtmlUtil import HtmlUtil\n\nclass HtmlUtilTestFormatLineFeed(unittest.TestCase):\n def test_format_line_feed_1(self):\n self.assertEqual(HtmlUtil._HtmlUtil__format_line_feed('aaa\\n\\n\\n'), 'aaa\\n')\n\n def test_format_line_feed_2(self):\n self.assertEqual(HtmlUtil._HtmlUtil__format_line_feed('aaa\\n\\n\\n\\n'), 'aaa\\n')\n\n def test_format_line_feed_3(self):\n self.assertEqual(HtmlUtil._HtmlUtil__format_line_feed('aaa\\n\\n\\nbbb\\n\\n'), 'aaa\\nbbb\\n')\n\n def test_format_line_feed_4(self):\n self.assertEqual(HtmlUtil._HtmlUtil__format_line_feed('ccc\\n\\n\\n'), 'ccc\\n')\n\n def test_format_line_feed_5(self):\n self.assertEqual(HtmlUtil._HtmlUtil__format_line_feed(''), '')\n\n\nclass HtmlUtilTestFormatLineHtmlText(unittest.TestCase):\n def test_format_line_html_text_1(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n\n def test_format_line_html_text_2(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle2\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n\n def test_format_line_html_text_3(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle3\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n\n def test_format_line_html_text_4(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle4\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n\n def test_format_line_html_text_5(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle5\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n def test_format_line_html_text_6(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('')\n self.assertEqual(res, '')\n\n def test_format_line_html_text_7(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''Some sentence here.
''')\n self.assertEqual(res, 'Some sentence here.')\n\n def test_format_line_html_text_10(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''Some paragraph here
Code block
''')\n self.assertEqual(res, '''Some paragraph here.Code block''')\n\n def test_format_line_html_text_11(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''Some paragraph here
This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, [\"print('Hello, world!')\", 'for i in range(5):\\n print(i)'])\n\n def test_extract_code_from_html_text_2(self):\n htmlutil = HtmlUtil()\n res = htmlutil.extract_code_from_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(4):\n print(i)
\n \n \n ''')\n self.assertEqual(res, [\"print('Hello, world!')\", 'for i in range(4):\\n print(i)'])\n\n def test_extract_code_from_html_text_3(self):\n htmlutil = HtmlUtil()\n res = htmlutil.extract_code_from_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(3):\n print(i)
\n \n \n ''')\n self.assertEqual(res, [\"print('Hello, world!')\", 'for i in range(3):\\n print(i)'])\n\n def test_extract_code_from_html_text_4(self):\n htmlutil = HtmlUtil()\n res = htmlutil.extract_code_from_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(2):\n print(i)
\n \n \n ''')\n self.assertEqual(res, [\"print('Hello, world!')\", 'for i in range(2):\\n print(i)'])\n\n def test_extract_code_from_html_text_5(self):\n htmlutil = HtmlUtil()\n htmlutil.CODE_MARK = 'abcdefg'\n res = htmlutil.extract_code_from_html_text(\"\")\n self.assertEqual(res, [])\n\n\nclass HtmlUtilTest(unittest.TestCase):\n def test_htmlutil(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n res = htmlutil.extract_code_from_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, [\"print('Hello, world!')\", 'for i in range(5):\\n print(i)'])\n\nif __name__ == '__main__':\n unittest.main()",
+ "test": "import unittest\nimport sys\n\nclass HtmlUtilTestFormatLineFeed(unittest.TestCase):\n def test_format_line_feed_1(self):\n self.assertEqual(HtmlUtil._HtmlUtil__format_line_feed('aaa\\n\\n\\n'), 'aaa\\n')\n\n def test_format_line_feed_2(self):\n self.assertEqual(HtmlUtil._HtmlUtil__format_line_feed('aaa\\n\\n\\n\\n'), 'aaa\\n')\n\n def test_format_line_feed_3(self):\n self.assertEqual(HtmlUtil._HtmlUtil__format_line_feed('aaa\\n\\n\\nbbb\\n\\n'), 'aaa\\nbbb\\n')\n\n def test_format_line_feed_4(self):\n self.assertEqual(HtmlUtil._HtmlUtil__format_line_feed('ccc\\n\\n\\n'), 'ccc\\n')\n\n def test_format_line_feed_5(self):\n self.assertEqual(HtmlUtil._HtmlUtil__format_line_feed(''), '')\n\n\nclass HtmlUtilTestFormatLineHtmlText(unittest.TestCase):\n def test_format_line_html_text_1(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n\n def test_format_line_html_text_2(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle2\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n\n def test_format_line_html_text_3(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle3\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n\n def test_format_line_html_text_4(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle4\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n\n def test_format_line_html_text_5(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle5\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n def test_format_line_html_text_6(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('')\n self.assertEqual(res, '')\n\n def test_format_line_html_text_7(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''Some sentence here.
''')\n self.assertEqual(res, 'Some sentence here.')\n\n def test_format_line_html_text_10(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''Some paragraph here
Code block
''')\n self.assertEqual(res, '''Some paragraph here.Code block''')\n\n def test_format_line_html_text_11(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''Some paragraph here
This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, [\"print('Hello, world!')\", 'for i in range(5):\\n print(i)'])\n\n def test_extract_code_from_html_text_2(self):\n htmlutil = HtmlUtil()\n res = htmlutil.extract_code_from_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(4):\n print(i)
\n \n \n ''')\n self.assertEqual(res, [\"print('Hello, world!')\", 'for i in range(4):\\n print(i)'])\n\n def test_extract_code_from_html_text_3(self):\n htmlutil = HtmlUtil()\n res = htmlutil.extract_code_from_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(3):\n print(i)
\n \n \n ''')\n self.assertEqual(res, [\"print('Hello, world!')\", 'for i in range(3):\\n print(i)'])\n\n def test_extract_code_from_html_text_4(self):\n htmlutil = HtmlUtil()\n res = htmlutil.extract_code_from_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(2):\n print(i)
\n \n \n ''')\n self.assertEqual(res, [\"print('Hello, world!')\", 'for i in range(2):\\n print(i)'])\n\n def test_extract_code_from_html_text_5(self):\n htmlutil = HtmlUtil()\n htmlutil.CODE_MARK = 'abcdefg'\n res = htmlutil.extract_code_from_html_text(\"\")\n self.assertEqual(res, [])\n\n\nclass HtmlUtilTest(unittest.TestCase):\n def test_htmlutil(self):\n htmlutil = HtmlUtil()\n res = htmlutil.format_line_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, '''\nTitle\nThis is a paragraph.\n-CODE-\nAnother paragraph.\n-CODE-\n''')\n res = htmlutil.extract_code_from_html_text('''\n \n \n This is a paragraph.
\nprint('Hello, world!')\n
Another paragraph.
\nfor i in range(5):\n print(i)
\n \n \n ''')\n self.assertEqual(res, [\"print('Hello, world!')\", 'for i in range(5):\\n print(i)'])\n\nif __name__ == '__main__':\n unittest.main()",
"solution_code": "import re\nimport string\nimport gensim\nfrom bs4 import BeautifulSoup\n\n\nclass HtmlUtil:\n\n def __init__(self):\n self.SPACE_MARK = '-SPACE-'\n self.JSON_MARK = '-JSON-'\n self.MARKUP_LANGUAGE_MARK = '-MARKUP_LANGUAGE-'\n self.URL_MARK = '-URL-'\n self.NUMBER_MARK = '-NUMBER-'\n self.TRACE_MARK = '-TRACE-'\n self.COMMAND_MARK = '-COMMAND-'\n self.COMMENT_MARK = '-COMMENT-'\n self.CODE_MARK = '-CODE-'\n\n @staticmethod\n def __format_line_feed(text):\n return re.sub(re.compile(r'\\n+'), '\\n', text)\n\n def format_line_html_text(self, html_text):\n if html_text is None or len(html_text) == 0:\n return ''\n soup = BeautifulSoup(html_text, 'lxml')\n\n code_tag = soup.find_all(name=['pre', 'blockquote'])\n for tag in code_tag:\n tag.string = self.CODE_MARK\n\n ul_ol_group = soup.find_all(name=['ul', 'ol'])\n for ul_ol_item in ul_ol_group:\n li_group = ul_ol_item.find_all('li')\n for li_item in li_group:\n li_item_text = li_item.get_text().strip()\n if len(li_item_text) == 0:\n continue\n if li_item_text[-1] in string.punctuation:\n li_item.string = '[{0}]{1}'.format('-', li_item_text)\n continue\n li_item.string = '[{0}]{1}.'.format('-', li_item_text)\n\n p_group = soup.find_all(name=['p'])\n for p_item in p_group:\n p_item_text = p_item.get_text().strip()\n if p_item_text:\n if p_item_text[-1] in string.punctuation:\n p_item.string = p_item_text\n continue\n next_sibling = p_item.find_next_sibling()\n if next_sibling and self.CODE_MARK in next_sibling.get_text():\n p_item.string = p_item_text + ':'\n continue\n p_item.string = p_item_text + '.'\n\n clean_text = gensim.utils.decode_htmlentities(soup.get_text())\n return self.__format_line_feed(clean_text)\n\n def extract_code_from_html_text(self, html_text):\n text_with_code_tag = self.format_line_html_text(html_text)\n\n if self.CODE_MARK not in text_with_code_tag:\n return []\n\n code_index_start = 0\n soup = BeautifulSoup(html_text, 'lxml')\n code_tag = soup.find_all(name=['pre', 'blockquote'])\n code_count = text_with_code_tag.count(self.CODE_MARK)\n code_list = []\n for code_index in range(code_index_start, code_index_start + code_count):\n code = code_tag[code_index].get_text()\n if code:\n code_list.append(code)\n return code_list",
"import_statement": [
"import re",
@@ -4142,7 +4142,7 @@
},
{
"task_id": "ClassEval_49",
- "skeleton": "\nclass JobMarketplace:\n \"\"\"\n This is a class that provides functionalities to publish positions, remove positions, submit resumes, withdraw resumes, search for positions, and obtain candidate information.\n \"\"\"\n\n def __init__(self):\n self.job_listings = []\n self.resumes = []\n\n def post_job(self, job_title, company, requirements):\n \"\"\"\n This function is used to publish positions,and add the position information to the job_listings list.\n :param job_title: The title of the position,str.\n :param company: The company of the position,str.\n :param requirements: The requirements of the position,list.\n :return: None\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.post_job(\"Software Engineer\", \"ABC Company\", ['requirement1', 'requirement2'])\n >>> jobMarketplace.job_listings\n [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['requirement1', 'requirement2']}]\n\n \"\"\"\n\n def remove_job(self, job):\n \"\"\"\n This function is used to remove positions,and remove the position information from the job_listings list.\n :param job: The position information to be removed,dict.\n :return: None\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['requirement1', 'requirement2']}]\n >>> jobMarketplace.remove_job(jobMarketplace.job_listings[0])\n >>> jobMarketplace.job_listings\n []\n\n \"\"\"\n\n def submit_resume(self, name, skills, experience):\n \"\"\"\n This function is used to submit resumes,and add the resume information to the resumes list.\n :param name: The name of the resume,str.\n :param skills: The skills of the resume,list.\n :param experience: The experience of the resume,str.\n :return: None\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n >>> jobMarketplace.resumes\n [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}]\n\n \"\"\"\n\n def withdraw_resume(self, resume):\n \"\"\"\n This function is used to withdraw resumes,and remove the resume information from the resumes list.\n :param resume: The resume information to be removed,dict.\n :return: None\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}]\n >>> jobMarketplace.withdraw_resume(jobMarketplace.resumes[0])\n >>> jobMarketplace.resumes\n []\n\n \"\"\"\n\n def search_jobs(self, criteria):\n \"\"\"\n This function is used to search for positions,and return the position information that meets the requirements.\n :param criteria: The requirements of the position,list.\n :return: The position information that meets the requirements,list.\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}]\n >>> jobMarketplace.search_jobs(\"skill1\")\n [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill1', 'skill2']}]\n\n \"\"\"\n\n def get_job_applicants(self, job):\n \"\"\"\n This function is used to obtain candidate information,and return the candidate information that meets the requirements by calling the matches_requirements function.\n :param job: The position information,dict.\n :return: The candidate information that meets the requirements,list.\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}]\n >>> jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}]\n >>> jobMarketplace.get_job_applicants(jobMarketplace.job_listings[0])\n [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}]\n\n \"\"\"",
+ "skeleton": "\nclass JobMarketplace:\n \"\"\"\n This is a class that provides functionalities to publish positions, remove positions, submit resumes, withdraw resumes, search for positions, and obtain candidate information.\n \"\"\"\n\n def __init__(self):\n self.job_listings = []\n self.resumes = []\n\n def post_job(self, job_title, company, requirements):\n \"\"\"\n This function is used to publish positions,and add the position information to the job_listings list.\n :param job_title: The title of the position,str.\n :param company: The company of the position,str.\n :param requirements: The requirements of the position,list.\n :return: None\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.post_job(\"Software Engineer\", \"ABC Company\", ['requirement1', 'requirement2'])\n >>> jobMarketplace.job_listings\n [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['requirement1', 'requirement2']}]\n\n \"\"\"\n\n def remove_job(self, job):\n \"\"\"\n This function is used to remove positions,and remove the position information from the job_listings list.\n :param job: The position information to be removed,dict.\n :return: None\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['requirement1', 'requirement2']}]\n >>> jobMarketplace.remove_job(jobMarketplace.job_listings[0])\n >>> jobMarketplace.job_listings\n []\n\n \"\"\"\n\n def submit_resume(self, name, skills, experience):\n \"\"\"\n This function is used to submit resumes,and add the resume information to the resumes list.\n :param name: The name of the resume,str.\n :param skills: The skills of the resume,list.\n :param experience: The experience of the resume,str.\n :return: None\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n >>> jobMarketplace.resumes\n [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}]\n\n \"\"\"\n\n def withdraw_resume(self, resume):\n \"\"\"\n This function is used to withdraw resumes,and remove the resume information from the resumes list.\n :param resume: The resume information to be removed,dict.\n :return: None\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}]\n >>> jobMarketplace.withdraw_resume(jobMarketplace.resumes[0])\n >>> jobMarketplace.resumes\n []\n\n \"\"\"\n\n def search_jobs(self, criteria):\n \"\"\"\n This function is used to search for positions,and return the position information that meets the requirements.\n :param criteria: The requirements of the position,str.\n :return: The position information that meets the requirements,list.\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}]\n >>> jobMarketplace.search_jobs(\"skill1\")\n [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill1', 'skill2']}]\n\n \"\"\"\n\n def get_job_applicants(self, job):\n \"\"\"\n This function is used to obtain candidate information,and return the candidate information that meets the requirements by calling the matches_requirements function.\n :param job: The position information,dict.\n :return: The candidate information that meets the requirements,list.\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}]\n >>> jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}]\n >>> jobMarketplace.get_job_applicants(jobMarketplace.job_listings[0])\n [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}]\n\n \"\"\"",
"test": "import unittest\nclass JobMarketplaceTestPostJob(unittest.TestCase):\n def test_post_job(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.post_job(\"Software Engineer\", \"ABC Company\", ['requirement1', 'requirement2'])\n self.assertEqual(jobMarketplace.job_listings, [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['requirement1', 'requirement2']}])\n\n def test_post_job_2(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.post_job(\"Mechanical Engineer\", \"XYZ Company\", ['requirement3', 'requirement4'])\n self.assertEqual(jobMarketplace.job_listings, [{'job_title': 'Mechanical Engineer', 'company': 'XYZ Company', 'requirements': ['requirement3', 'requirement4']}])\n\n def test_post_job_3(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.post_job(\"Software Engineer\", \"ABC Company\", ['requirement1', 'requirement2'])\n jobMarketplace.post_job(\"Mechanical Engineer\", \"XYZ Company\", ['requirement3', 'requirement4'])\n self.assertEqual(jobMarketplace.job_listings, [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['requirement1', 'requirement2']}, {'job_title': 'Mechanical Engineer', 'company': 'XYZ Company', 'requirements': ['requirement3', 'requirement4']}])\n\n def test_post_job_4(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.post_job(\"Software Engineer\", \"ABC Company\", ['requirement1', 'requirement2'])\n jobMarketplace.post_job(\"Mechanical Engineer\", \"XYZ Company\", ['requirement3', 'requirement4'])\n jobMarketplace.post_job(\"Software Engineer\", \"ABC Company\", ['requirement1', 'requirement2'])\n self.assertEqual(jobMarketplace.job_listings, [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['requirement1', 'requirement2']}, {'job_title': 'Mechanical Engineer', 'company': 'XYZ Company', 'requirements': ['requirement3', 'requirement4']}, {'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['requirement1', 'requirement2']}])\n\n def test_post_job_5(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.post_job(\"Software Engineer\", \"ABC Company\", ['requirement1', 'requirement2'])\n jobMarketplace.post_job(\"Mechanical Engineer\", \"XYZ Company\", ['requirement3', 'requirement4'])\n jobMarketplace.post_job(\"Software Engineer\", \"ABC Company\", ['requirement1', 'requirement2'])\n jobMarketplace.post_job(\"Mechanical Engineer\", \"XYZ Company\", ['requirement3', 'requirement4'])\n self.assertEqual(jobMarketplace.job_listings, [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['requirement1', 'requirement2']}, {'job_title': 'Mechanical Engineer', 'company': 'XYZ Company', 'requirements': ['requirement3', 'requirement4']}, {'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['requirement1', 'requirement2']}, {'job_title': 'Mechanical Engineer', 'company': 'XYZ Company', 'requirements': ['requirement3', 'requirement4']}])\n\nclass JobMarketplaceTestRemoveJob(unittest.TestCase):\n def test_remove_job(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['requirement1', 'requirement2']}]\n jobMarketplace.remove_job(jobMarketplace.job_listings[0])\n self.assertEqual(jobMarketplace.job_listings, [])\n\n def test_remove_job_2(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['requirement1', 'requirement2']}, {\"job_title\": \"Mechanical Engineer\", \"company\": \"XYZ Company\", \"requirements\": ['requirement3', 'requirement4']}]\n jobMarketplace.remove_job(jobMarketplace.job_listings[0])\n self.assertEqual(jobMarketplace.job_listings, [{'job_title': 'Mechanical Engineer', 'company': 'XYZ Company', 'requirements': ['requirement3', 'requirement4']}])\n\n def test_remove_job_3(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['requirement1', 'requirement2']}, {\"job_title\": \"Mechanical Engineer\", \"company\": \"XYZ Company\", \"requirements\": ['requirement3', 'requirement4']}]\n jobMarketplace.remove_job(jobMarketplace.job_listings[0])\n jobMarketplace.remove_job(jobMarketplace.job_listings[0])\n self.assertEqual(jobMarketplace.job_listings, [])\n\n def test_remove_job_4(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['requirement1', 'requirement2']}, {\"job_title\": \"Mechanical Engineer\", \"company\": \"XYZ Company\", \"requirements\": ['requirement3', 'requirement4']}, {\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['requirement1', 'requirement2']}]\n jobMarketplace.remove_job(jobMarketplace.job_listings[0])\n jobMarketplace.remove_job(jobMarketplace.job_listings[0])\n self.assertEqual(jobMarketplace.job_listings, [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['requirement1', 'requirement2']}])\n\n def test_remove_job_5(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\",\n \"requirements\": ['requirement1', 'requirement2']},\n {\"job_title\": \"Mechanical Engineer\", \"company\": \"XYZ Company\",\n \"requirements\": ['requirement3', 'requirement4']},\n {\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\",\n \"requirements\": ['requirement1', 'requirement2']}]\n jobMarketplace.remove_job(jobMarketplace.job_listings[0])\n self.assertEqual(jobMarketplace.job_listings, [{'job_title': 'Mechanical Engineer', 'company': 'XYZ Company', 'requirements': ['requirement3', 'requirement4']}, {'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['requirement1', 'requirement2']}])\n\nclass JobMarketplaceTestSubmitResume(unittest.TestCase):\n def test_submit_resume(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n self.assertEqual(jobMarketplace.resumes, [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}])\n\n def test_submit_resume_2(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n jobMarketplace.submit_resume(\"John\", ['skill3', 'skill4'], \"experience\")\n self.assertEqual(jobMarketplace.resumes, [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}, {'name': 'John', 'skills': ['skill3', 'skill4'], 'experience': 'experience'}])\n\n def test_submit_resume_3(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n jobMarketplace.submit_resume(\"John\", ['skill3', 'skill4'], \"experience\")\n jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n self.assertEqual(jobMarketplace.resumes, [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}, {'name': 'John', 'skills': ['skill3', 'skill4'], 'experience': 'experience'}, {'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}])\n\n def test_submit_resume_4(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n jobMarketplace.submit_resume(\"John\", ['skill3', 'skill4'], \"experience\")\n jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n jobMarketplace.submit_resume(\"John\", ['skill3', 'skill4'], \"experience\")\n self.assertEqual(jobMarketplace.resumes, [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}, {'name': 'John', 'skills': ['skill3', 'skill4'], 'experience': 'experience'}, {'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}, {'name': 'John', 'skills': ['skill3', 'skill4'], 'experience': 'experience'}])\n\n def test_submit_resume_5(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n jobMarketplace.submit_resume(\"John\", ['skill3', 'skill4'], \"experience\")\n jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n jobMarketplace.submit_resume(\"John\", ['skill3', 'skill4'], \"experience\")\n jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n self.assertEqual(jobMarketplace.resumes, [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}, {'name': 'John', 'skills': ['skill3', 'skill4'], 'experience': 'experience'}, {'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}, {'name': 'John', 'skills': ['skill3', 'skill4'], 'experience': 'experience'}, {'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}])\n\n\nclass JobMarketplaceTestWithdrawResume(unittest.TestCase):\n def test_withdraw_resume(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}]\n jobMarketplace.withdraw_resume(jobMarketplace.resumes[0])\n self.assertEqual(jobMarketplace.resumes, [])\n\n def test_withdraw_resume_2(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, {\"name\": \"John\", \"skills\": ['skill3', 'skill4'], \"experience\": \"experience\"}]\n jobMarketplace.withdraw_resume(jobMarketplace.resumes[0])\n self.assertEqual(jobMarketplace.resumes, [{'name': 'John', 'skills': ['skill3', 'skill4'], 'experience': 'experience'}])\n\n def test_withdraw_resume_3(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, {\"name\": \"John\", \"skills\": ['skill3', 'skill4'], \"experience\": \"experience\"}]\n jobMarketplace.withdraw_resume(jobMarketplace.resumes[0])\n jobMarketplace.withdraw_resume(jobMarketplace.resumes[0])\n self.assertEqual(jobMarketplace.resumes, [])\n \n def test_withdraw_resume_4(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.resumes = [{\"name\": \"Amy\", \"skills\": ['skill3', 'skill2'], \"experience\": \"experience\"}, {\"name\": \"John\", \"skills\": ['skill3', 'skill4'], \"experience\": \"experience\"}]\n jobMarketplace.withdraw_resume(jobMarketplace.resumes[0])\n jobMarketplace.withdraw_resume(jobMarketplace.resumes[0])\n self.assertEqual(jobMarketplace.resumes, [])\n\n def test_withdraw_resume_5(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.resumes = [{\"name\": \"Amy\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, {\"name\": \"John\", \"skills\": ['skill3', 'skill4'], \"experience\": \"experience\"}]\n jobMarketplace.withdraw_resume(jobMarketplace.resumes[0])\n self.assertEqual(jobMarketplace.resumes, [{'experience': 'experience', 'name': 'John', 'skills': ['skill3', 'skill4']}])\n\nclass JobMarketplaceTestSearchJobs(unittest.TestCase):\n def test_search_jobs(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}]\n self.assertEqual(jobMarketplace.search_jobs(\"skill1\"), [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill1', 'skill2']}])\n\n def test_search_jobs_2(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}, {\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill3', 'skill4']}]\n self.assertEqual(jobMarketplace.search_jobs(\"skill1\"), [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill1', 'skill2']}])\n\n def test_search_jobs_3(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}, {\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill3', 'skill4']}]\n self.assertEqual(jobMarketplace.search_jobs(\"skill3\"), [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill3', 'skill4']}])\n\n def test_search_jobs_4(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}, {\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill3', 'skill4']}]\n self.assertEqual(jobMarketplace.search_jobs(\"skill5\"), [])\n\n def test_search_jobs_5(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}, {\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill3', 'skill4']}]\n self.assertEqual(jobMarketplace.search_jobs(\"skill6\"), [])\n\nclass JobMarketplaceTestGetJobApplicants(unittest.TestCase):\n def test_get_job_applicants(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}]\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}]\n self.assertEqual(jobMarketplace.get_job_applicants(jobMarketplace.job_listings[0]), [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}])\n\n def test_get_job_applicants_2(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, {\"name\": \"John\", \"skills\": ['skill3', 'skill4'], \"experience\": \"experience\"}]\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}]\n self.assertEqual(jobMarketplace.get_job_applicants(jobMarketplace.job_listings[0]), [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}])\n\n def test_get_job_applicants_3(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, {\"name\": \"John\", \"skills\": ['skill3', 'skill4'], \"experience\": \"experience\"}]\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill3', 'skill4']}]\n self.assertEqual(jobMarketplace.get_job_applicants(jobMarketplace.job_listings[0]), [{'name': 'John', 'skills': ['skill3', 'skill4'], 'experience': 'experience'}])\n\n def test_get_job_applicants_4(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, {\"name\": \"John\", \"skills\": ['skill3', 'skill4'], \"experience\": \"experience\"}]\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill5', 'skill6']}]\n self.assertEqual(jobMarketplace.get_job_applicants(jobMarketplace.job_listings[0]), [])\n\n def test_get_job_applicants_5(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, {\"name\": \"John\", \"skills\": ['skill3', 'skill4'], \"experience\": \"experience\"}]\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill6', 'skill7']}]\n self.assertEqual(jobMarketplace.get_job_applicants(jobMarketplace.job_listings[0]), [])\n\nclass JobMarketplaceTestMatchesRequirements(unittest.TestCase):\n def test_matches_requirements(self):\n jobMarketplace = JobMarketplace()\n self.assertEqual(jobMarketplace.matches_requirements({\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, ['skill1', 'skill2']), True)\n\n def test_matches_requirements_2(self):\n jobMarketplace = JobMarketplace()\n self.assertEqual(jobMarketplace.matches_requirements({\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, ['skill3', 'skill4']), False)\n\n def test_matches_requirements_3(self):\n jobMarketplace = JobMarketplace()\n self.assertEqual(jobMarketplace.matches_requirements({\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, ['skill5', 'skill6']), False)\n\n def test_matches_requirements_4(self):\n jobMarketplace = JobMarketplace()\n self.assertEqual(jobMarketplace.matches_requirements({\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, ['skill1', 'skill3']), False)\n\n def test_matches_requirements_5(self):\n jobMarketplace = JobMarketplace()\n self.assertEqual(jobMarketplace.matches_requirements({\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, ['skill1']), False)\n\nclass JobMarketplaceTestMain(unittest.TestCase):\n def test_main(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.post_job(\"Software Engineer\", \"ABC Company\", ['skill1', 'skill2'])\n jobMarketplace.post_job(\"Mechanical Engineer\", \"XYZ Company\", ['skill3', 'skill4'])\n self.assertEqual(jobMarketplace.job_listings, [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill1', 'skill2']}, {'job_title': 'Mechanical Engineer', 'company': 'XYZ Company', 'requirements': ['skill3', 'skill4']}])\n jobMarketplace.remove_job(jobMarketplace.job_listings[1])\n self.assertEqual(jobMarketplace.job_listings, [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill1', 'skill2']}])\n jobMarketplace.submit_resume(\"Tom\", ['skill1', 'skill2'], \"experience\")\n self.assertEqual(jobMarketplace.resumes, [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}])\n jobMarketplace.withdraw_resume(jobMarketplace.resumes[0])\n self.assertEqual(jobMarketplace.resumes, [])\n self.assertEqual(jobMarketplace.search_jobs(\"skill1\"), [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill1', 'skill2']}])\n jobMarketplace.resumes = [{\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}]\n self.assertEqual(jobMarketplace.get_job_applicants(jobMarketplace.job_listings[0]), [{'name': 'Tom', 'skills': ['skill1', 'skill2'], 'experience': 'experience'}])\n self.assertEqual(jobMarketplace.matches_requirements({\"name\": \"Tom\", \"skills\": ['skill1', 'skill2'], \"experience\": \"experience\"}, ['skill1', 'skill2']), True)",
"solution_code": "class JobMarketplace:\n def __init__(self):\n self.job_listings = []\n self.resumes = []\n\n def post_job(self, job_title, company, requirements):\n # requirements = ['requirement1', 'requirement2']\n job = {\"job_title\": job_title, \"company\": company, \"requirements\": requirements}\n self.job_listings.append(job)\n\n def remove_job(self, job):\n self.job_listings.remove(job)\n\n def submit_resume(self, name, skills, experience):\n resume = {\"name\": name, \"skills\": skills, \"experience\": experience}\n self.resumes.append(resume)\n\n def withdraw_resume(self, resume):\n self.resumes.remove(resume)\n\n def search_jobs(self, criteria):\n matching_jobs = []\n for job_listing in self.job_listings:\n if criteria.lower() in job_listing[\"job_title\"].lower() or criteria.lower() in [r.lower() for r in job_listing[\"requirements\"]]:\n matching_jobs.append(job_listing)\n return matching_jobs\n\n def get_job_applicants(self, job):\n applicants = []\n for resume in self.resumes:\n if self.matches_requirements(resume, job[\"requirements\"]):\n applicants.append(resume)\n return applicants\n\n @staticmethod\n def matches_requirements(resume, requirements):\n for skill in resume[\"skills\"]:\n if skill not in requirements:\n return False\n return True",
"import_statement": [],
@@ -4226,7 +4226,7 @@
},
{
"method_name": "search_jobs",
- "method_description": "def search_jobs(self, criteria):\n \"\"\"\n This function is used to search for positions,and return the position information that meets the requirements.\n :param criteria: The requirements of the position,list.\n :return: The position information that meets the requirements,list.\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}]\n >>> jobMarketplace.search_jobs(\"skill1\")\n [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill1', 'skill2']}]\n\n \"\"\"",
+ "method_description": "def search_jobs(self, criteria):\n \"\"\"\n This function is used to search for positions,and return the position information that meets the requirements.\n :param criteria: The requirements of the position,str.\n :return: The position information that meets the requirements,list.\n >>> jobMarketplace = JobMarketplace()\n >>> jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}]\n >>> jobMarketplace.search_jobs(\"skill1\")\n [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill1', 'skill2']}]\n\n \"\"\"",
"test_class": "JobMarketplaceTestSearchJobs",
"test_code": "class JobMarketplaceTestSearchJobs(unittest.TestCase):\n def test_search_jobs(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}]\n self.assertEqual(jobMarketplace.search_jobs(\"skill1\"), [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill1', 'skill2']}])\n\n def test_search_jobs_2(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}, {\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill3', 'skill4']}]\n self.assertEqual(jobMarketplace.search_jobs(\"skill1\"), [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill1', 'skill2']}])\n\n def test_search_jobs_3(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}, {\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill3', 'skill4']}]\n self.assertEqual(jobMarketplace.search_jobs(\"skill3\"), [{'job_title': 'Software Engineer', 'company': 'ABC Company', 'requirements': ['skill3', 'skill4']}])\n\n def test_search_jobs_4(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}, {\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill3', 'skill4']}]\n self.assertEqual(jobMarketplace.search_jobs(\"skill5\"), [])\n\n def test_search_jobs_5(self):\n jobMarketplace = JobMarketplace()\n jobMarketplace.job_listings = [{\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill1', 'skill2']}, {\"job_title\": \"Software Engineer\", \"company\": \"ABC Company\", \"requirements\": ['skill3', 'skill4']}]\n self.assertEqual(jobMarketplace.search_jobs(\"skill6\"), [])",
"solution_code": "def search_jobs(self, criteria):\n matching_jobs = []\n for job_listing in self.job_listings:\n if criteria.lower() in job_listing[\"job_title\"].lower() or criteria.lower() in [r.lower() for r in job_listing[\"requirements\"]]:\n matching_jobs.append(job_listing)\n return matching_jobs",
@@ -4375,9 +4375,9 @@
},
{
"task_id": "ClassEval_52",
- "skeleton": "\nimport nltk\nfrom nltk.stem import WordNetLemmatizer\nfrom nltk import pos_tag, word_tokenize\nimport string\n\nnltk.download('averaged_perceptron_tagger')\nnltk.download('punkt')\n\n\nclass Lemmatization:\n \"\"\"\n This is a class about Lemmatization, which utilizes the nltk library to perform lemmatization and part-of-speech tagging on sentences, as well as remove punctuation.\n \"\"\"\n\n def __init__(self):\n \"\"\"\n creates a WordNetLemmatizer object and stores it in the self.lemmatizer member variable.\n \"\"\"\n self.lemmatizer = WordNetLemmatizer()\n\n def lemmatize_sentence(self, sentence):\n \"\"\"\n Remove punctuations of the sentence and tokenizes the input sentence, mark the part of speech tag of each word,\n lemmatizes the words with different parameters based on their parts of speech, and stores in a list.\n :param sentence: a sentence str\n :return: a list of words which have been lemmatized.\n >>> lemmatization = Lemmatization()\n >>> lemmatization.lemmatize_sentence(\"I am running in a race.\")\n ['I', 'be', 'run', 'in', 'a', 'race']\n \"\"\"\n\n def get_pos_tag(self, sentence):\n \"\"\"\n Remove punctuations of the sentence and tokenizes the input sentence, mark the part of speech tag of each word.\n :param sentence: a sentence str\n :return: list, part of speech tag of each word in the sentence.\n >>> lemmatization = Lemmatization()\n >>> lemmatization.get_pos_tag(\"I am running in a race.\")\n ['PRP', 'VBP', 'VBG', 'IN', 'DT', 'NN']\n \"\"\"\n\n def remove_punctuation(self, sentence):\n \"\"\"\n Removes punctuation from the input text.\n :param sentence: a sentence str\n :return: str, sentence without any punctuation\n >>> lemmatization = Lemmatization()\n >>> lemmatization.remove_punctuation(\"I am running in a race.\")\n 'I am running in a race'\n \"\"\"",
- "test": "import unittest\n\n\nclass LemmatizationTestLemmatizeSentence(unittest.TestCase):\n def test_lemmatize_sentence_1(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"I am running in a race.\")\n expected = ['I', 'be', 'run', 'in', 'a', 'race']\n self.assertEqual(result, expected)\n\n def test_lemmatize_sentence_2(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"Until the beating, Cantanco's eyesight had been weak, but adequate.\")\n expected = ['Until', 'the', 'beating', 'Cantancos', 'eyesight', 'have', 'be', 'weak', 'but', 'adequate']\n self.assertEqual(result, expected)\n\n def test_lammatize_sentence_3(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"The dog's barked at the mailman.\")\n expected = ['The', 'dog', 'bark', 'at', 'the', 'mailman']\n self.assertEqual(result, expected)\n\n def test_lemmatize_sentence_4(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"He was running and eating at same time. \")\n expected = ['He', 'be', 'run', 'and', 'eat', 'at', 'same', 'time']\n self.assertEqual(result, expected)\n\n def test_lemmatize_sentence_5(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"I was taking a ride in the car.\")\n expected = ['I', 'be', 'take', 'a', 'ride', 'in', 'the', 'car']\n self.assertEqual(result, expected)\n\nclass LemmatizationTestGetPosTag(unittest.TestCase):\n def test_get_pos_tag_1(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"I am running in a race.\")\n expected = ['PRP', 'VBP', 'VBG', 'IN', 'DT', 'NN']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_2(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"Cantanco's eyesight had been weak, but adequate.\")\n expected = ['NNP', 'NN', 'VBD', 'VBN', 'JJ', 'CC', 'JJ']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_3(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"The dog's barked at the mailman.\")\n expected = ['DT', 'NNS', 'VBD', 'IN', 'DT', 'NN']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_4(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"He was running and eating at same time. \")\n expected = ['PRP', 'VBD', 'VBG', 'CC', 'VBG', 'IN', 'JJ', 'NN']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_5(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"I was taking a ride in the car.\")\n expected = ['PRP', 'VBD', 'VBG', 'DT', 'NN', 'IN', 'DT', 'NN']\n self.assertEqual(result, expected)\n\n\nclass LemmatizationTestRemovePunctuation(unittest.TestCase):\n def test_remove_punctuation_1(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"I am running in a race.\")\n expected = \"I am running in a race\"\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_2(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"Until the beating, Cantanco's eyesight had been weak, but adequate.\")\n expected = 'Until the beating Cantancos eyesight had been weak but adequate'\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_3(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"The dog's barked at the mailman!!!\")\n expected = 'The dogs barked at the mailman'\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_4(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"He was running and eating at same time... \")\n expected = 'He was running and eating at same time '\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_5(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"Is this a test? I hope it is...\")\n expected = 'Is this a test I hope it is'\n self.assertEqual(result, expected)\n\nclass LemmatizationTestMain(unittest.TestCase):\n def test_main(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"Until the beating, Cantanco's eyesight had been weak, but adequate.\")\n expected = ['Until', 'the', 'beating', 'Cantancos', 'eyesight', 'have', 'be', 'weak', 'but', 'adequate']\n self.assertEqual(result, expected)\n\n result = lemmatization.get_pos_tag(\"Cantanco's eyesight had been weak, but adequate.\")\n expected = ['NNP', 'NN', 'VBD', 'VBN', 'JJ', 'CC', 'JJ']\n self.assertEqual(result, expected)",
- "solution_code": "import nltk\nfrom nltk.stem import WordNetLemmatizer\nfrom nltk import pos_tag, word_tokenize\nimport string\n\nnltk.download('averaged_perceptron_tagger')\nnltk.download('punkt')\n\n\nclass Lemmatization:\n def __init__(self):\n self.lemmatizer = WordNetLemmatizer()\n\n def lemmatize_sentence(self, sentence):\n lemmatized_words = []\n sentence = self.remove_punctuation(sentence)\n words = word_tokenize(sentence)\n tagged_words = pos_tag(words)\n for word, tag in tagged_words:\n if tag.startswith('V'):\n lemmatized_word = self.lemmatizer.lemmatize(word, pos='v')\n elif tag.startswith('J'):\n lemmatized_word = self.lemmatizer.lemmatize(word, pos='a')\n elif tag.startswith('R'):\n lemmatized_word = self.lemmatizer.lemmatize(word, pos='r')\n else:\n lemmatized_word = self.lemmatizer.lemmatize(word)\n lemmatized_words.append(lemmatized_word)\n return lemmatized_words\n\n def get_pos_tag(self, sentence):\n pos_tags = []\n sentence = self.remove_punctuation(sentence)\n words = word_tokenize(sentence)\n tagged_words = pos_tag(words)\n for tagged_word in tagged_words:\n pos_tags.append(tagged_word[1])\n return pos_tags\n\n def remove_punctuation(self, sentence):\n return sentence.translate(str.maketrans('', '', string.punctuation))",
+ "skeleton": "\nimport nltk\nfrom nltk.stem import WordNetLemmatizer\nfrom nltk import pos_tag, word_tokenize\nimport string\n\n\nnltk.download('averaged_perceptron_tagger')\nnltk.download('punkt')\nnltk.download('wordnet')\n\nclass Lemmatization:\n \"\"\"\n This is a class about Lemmatization, which utilizes the nltk library to perform lemmatization and part-of-speech tagging on sentences, as well as remove punctuation.\n \"\"\"\n\n def __init__(self):\n \"\"\"\n creates a WordNetLemmatizer object and stores it in the self.lemmatizer member variable.\n \"\"\"\n self.lemmatizer = WordNetLemmatizer()\n\n def lemmatize_sentence(self, sentence):\n \"\"\"\n Remove punctuations of the sentence and tokenizes the input sentence, mark the part of speech tag of each word,\n lemmatizes the words with different parameters based on their parts of speech, and stores in a list.\n :param sentence: a sentence str\n :return: a list of words which have been lemmatized.\n >>> lemmatization = Lemmatization()\n >>> lemmatization.lemmatize_sentence(\"I am running in a race.\")\n ['I', 'be', 'run', 'in', 'a', 'race']\n\n \"\"\"\n\n def get_pos_tag(self, sentence):\n \"\"\"\n Remove punctuations of the sentence and tokenizes the input sentence, mark the part of speech tag of each word.\n :param sentence: a sentence str\n :return: list, part of speech tag of each word in the sentence.\n >>> lemmatization = Lemmatization()\n >>> lemmatization.get_pos_tag(\"I am running in a race.\")\n ['PRP', 'VBP', 'VBG', 'IN', 'DT', 'NN']\n\n \"\"\"\n\n def remove_punctuation(self, sentence):\n \"\"\"\n Removes punctuation from the input text.\n :param sentence: a sentence str\n :return: str, sentence without any punctuation\n >>> lemmatization = Lemmatization()\n >>> lemmatization.remove_punctuation(\"I am running in a race.\")\n 'I am running in a race'\n\n \"\"\"",
+ "test": "import unittest\n\nclass LemmatizationTestLemmatizeSentence(unittest.TestCase):\n def test_lemmatize_sentence_1(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"I am running in a race.\")\n expected = ['I', 'be', 'run', 'in', 'a', 'race']\n self.assertEqual(result, expected)\n\n def test_lemmatize_sentence_2(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"Until the beating, Cantanco's eyesight had been weak, but adequate.\")\n expected = ['Until', 'the', 'beating', 'Cantancos', 'eyesight', 'have', 'be', 'weak', 'but', 'adequate']\n self.assertEqual(result, expected)\n\n def test_lammatize_sentence_3(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"The dog's barked at the mailman.\")\n expected = ['The', 'dog', 'bark', 'at', 'the', 'mailman']\n self.assertEqual(result, expected)\n\n def test_lemmatize_sentence_4(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"He was running and eating at same time. \")\n expected = ['He', 'be', 'run', 'and', 'eat', 'at', 'same', 'time']\n self.assertEqual(result, expected)\n\n def test_lemmatize_sentence_5(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"I was taking a ride in the car.\")\n expected = ['I', 'be', 'take', 'a', 'ride', 'in', 'the', 'car']\n self.assertEqual(result, expected)\n\nclass LemmatizationTestGetPosTag(unittest.TestCase):\n def test_get_pos_tag_1(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"I am running in a race.\")\n expected = ['PRP', 'VBP', 'VBG', 'IN', 'DT', 'NN']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_2(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"Cantanco's eyesight had been weak, but adequate.\")\n expected = ['NNP', 'NN', 'VBD', 'VBN', 'JJ', 'CC', 'JJ']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_3(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"The dog's barked at the mailman.\")\n expected = ['DT', 'NNS', 'VBD', 'IN', 'DT', 'NN']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_4(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"He was running and eating at same time. \")\n expected = ['PRP', 'VBD', 'VBG', 'CC', 'VBG', 'IN', 'JJ', 'NN']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_5(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"I was taking a ride in the car.\")\n expected = ['PRP', 'VBD', 'VBG', 'DT', 'NN', 'IN', 'DT', 'NN']\n self.assertEqual(result, expected)\n\n\nclass LemmatizationTestRemovePunctuation(unittest.TestCase):\n def test_remove_punctuation_1(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"I am running in a race.\")\n expected = \"I am running in a race\"\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_2(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"Until the beating, Cantanco's eyesight had been weak, but adequate.\")\n expected = 'Until the beating Cantancos eyesight had been weak but adequate'\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_3(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"The dog's barked at the mailman!!!\")\n expected = 'The dogs barked at the mailman'\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_4(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"He was running and eating at same time... \")\n expected = 'He was running and eating at same time '\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_5(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"Is this a test? I hope it is...\")\n expected = 'Is this a test I hope it is'\n self.assertEqual(result, expected)\n\nclass LemmatizationTestMain(unittest.TestCase):\n def test_main(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"Until the beating, Cantanco's eyesight had been weak, but adequate.\")\n expected = ['Until', 'the', 'beating', 'Cantancos', 'eyesight', 'have', 'be', 'weak', 'but', 'adequate']\n self.assertEqual(result, expected)\n\n result = lemmatization.get_pos_tag(\"Cantanco's eyesight had been weak, but adequate.\")\n expected = ['NNP', 'NN', 'VBD', 'VBN', 'JJ', 'CC', 'JJ']\n self.assertEqual(result, expected)",
+ "solution_code": "import nltk\nfrom nltk.stem import WordNetLemmatizer\nfrom nltk import pos_tag, word_tokenize\nimport string\n\nnltk.download('averaged_perceptron_tagger')\nnltk.download('punkt')\nnltk.download('wordnet')\n\n\nclass Lemmatization:\n def __init__(self):\n self.lemmatizer = WordNetLemmatizer()\n\n def lemmatize_sentence(self, sentence):\n lemmatized_words = []\n sentence = self.remove_punctuation(sentence)\n words = word_tokenize(sentence)\n tagged_words = pos_tag(words)\n for word, tag in tagged_words:\n if tag.startswith('V'):\n lemmatized_word = self.lemmatizer.lemmatize(word, pos='v')\n elif tag.startswith('J'):\n lemmatized_word = self.lemmatizer.lemmatize(word, pos='a')\n elif tag.startswith('R'):\n lemmatized_word = self.lemmatizer.lemmatize(word, pos='r')\n else:\n lemmatized_word = self.lemmatizer.lemmatize(word)\n lemmatized_words.append(lemmatized_word)\n return lemmatized_words\n\n def get_pos_tag(self, sentence):\n pos_tags = []\n sentence = self.remove_punctuation(sentence)\n words = word_tokenize(sentence)\n tagged_words = pos_tag(words)\n for tagged_word in tagged_words:\n pos_tags.append(tagged_word[1])\n return pos_tags\n\n def remove_punctuation(self, sentence):\n return sentence.translate(str.maketrans('', '', string.punctuation))",
"import_statement": [
"import nltk",
"from nltk.stem import WordNetLemmatizer",
@@ -4399,7 +4399,7 @@
"methods_info": [
{
"method_name": "lemmatize_sentence",
- "method_description": "def lemmatize_sentence(self, sentence):\n \"\"\"\n Remove punctuations of the sentence and tokenizes the input sentence, mark the part of speech tag of each word,\n lemmatizes the words with different parameters based on their parts of speech, and stores in a list.\n :param sentence: a sentence str\n :return: a list of words which have been lemmatized.\n >>> lemmatization = Lemmatization()\n >>> lemmatization.lemmatize_sentence(\"I am running in a race.\")\n ['I', 'be', 'run', 'in', 'a', 'race']\n \"\"\"",
+ "method_description": "def lemmatize_sentence(self, sentence):\n \"\"\"\n Remove punctuations of the sentence and tokenizes the input sentence, mark the part of speech tag of each word,\n lemmatizes the words with different parameters based on their parts of speech, and stores in a list.\n :param sentence: a sentence str\n :return: a list of words which have been lemmatized.\n >>> lemmatization = Lemmatization()\n >>> lemmatization.lemmatize_sentence(\"I am running in a race.\")\n ['I', 'be', 'run', 'in', 'a', 'race']\n\n \"\"\"",
"test_class": "LemmatizationTestLemmatizeSentence",
"test_code": "class LemmatizationTestLemmatizeSentence(unittest.TestCase):\n def test_lemmatize_sentence_1(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"I am running in a race.\")\n expected = ['I', 'be', 'run', 'in', 'a', 'race']\n self.assertEqual(result, expected)\n\n def test_lemmatize_sentence_2(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"Until the beating, Cantanco's eyesight had been weak, but adequate.\")\n expected = ['Until', 'the', 'beating', 'Cantancos', 'eyesight', 'have', 'be', 'weak', 'but', 'adequate']\n self.assertEqual(result, expected)\n\n def test_lammatize_sentence_3(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"The dog's barked at the mailman.\")\n expected = ['The', 'dog', 'bark', 'at', 'the', 'mailman']\n self.assertEqual(result, expected)\n\n def test_lemmatize_sentence_4(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"He was running and eating at same time. \")\n expected = ['He', 'be', 'run', 'and', 'eat', 'at', 'same', 'time']\n self.assertEqual(result, expected)\n\n def test_lemmatize_sentence_5(self):\n lemmatization = Lemmatization()\n result = lemmatization.lemmatize_sentence(\"I was taking a ride in the car.\")\n expected = ['I', 'be', 'take', 'a', 'ride', 'in', 'the', 'car']\n self.assertEqual(result, expected)",
"solution_code": "def lemmatize_sentence(self, sentence):\n lemmatized_words = []\n sentence = self.remove_punctuation(sentence)\n words = word_tokenize(sentence)\n tagged_words = pos_tag(words)\n for word, tag in tagged_words:\n if tag.startswith('V'):\n lemmatized_word = self.lemmatizer.lemmatize(word, pos='v')\n elif tag.startswith('J'):\n lemmatized_word = self.lemmatizer.lemmatize(word, pos='a')\n elif tag.startswith('R'):\n lemmatized_word = self.lemmatizer.lemmatize(word, pos='r')\n else:\n lemmatized_word = self.lemmatizer.lemmatize(word)\n lemmatized_words.append(lemmatized_word)\n return lemmatized_words",
@@ -4416,7 +4416,7 @@
},
{
"method_name": "get_pos_tag",
- "method_description": "def get_pos_tag(self, sentence):\n \"\"\"\n Remove punctuations of the sentence and tokenizes the input sentence, mark the part of speech tag of each word.\n :param sentence: a sentence str\n :return: list, part of speech tag of each word in the sentence.\n >>> lemmatization = Lemmatization()\n >>> lemmatization.get_pos_tag(\"I am running in a race.\")\n ['PRP', 'VBP', 'VBG', 'IN', 'DT', 'NN']\n \"\"\"",
+ "method_description": "def get_pos_tag(self, sentence):\n \"\"\"\n Remove punctuations of the sentence and tokenizes the input sentence, mark the part of speech tag of each word.\n :param sentence: a sentence str\n :return: list, part of speech tag of each word in the sentence.\n >>> lemmatization = Lemmatization()\n >>> lemmatization.get_pos_tag(\"I am running in a race.\")\n ['PRP', 'VBP', 'VBG', 'IN', 'DT', 'NN']\n\n \"\"\"",
"test_class": "LemmatizationTestGetPosTag",
"test_code": "class LemmatizationTestGetPosTag(unittest.TestCase):\n def test_get_pos_tag_1(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"I am running in a race.\")\n expected = ['PRP', 'VBP', 'VBG', 'IN', 'DT', 'NN']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_2(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"Cantanco's eyesight had been weak, but adequate.\")\n expected = ['NNP', 'NN', 'VBD', 'VBN', 'JJ', 'CC', 'JJ']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_3(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"The dog's barked at the mailman.\")\n expected = ['DT', 'NNS', 'VBD', 'IN', 'DT', 'NN']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_4(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"He was running and eating at same time. \")\n expected = ['PRP', 'VBD', 'VBG', 'CC', 'VBG', 'IN', 'JJ', 'NN']\n self.assertEqual(result, expected)\n\n def test_get_pos_tag_5(self):\n lemmatization = Lemmatization()\n result = lemmatization.get_pos_tag(\"I was taking a ride in the car.\")\n expected = ['PRP', 'VBD', 'VBG', 'DT', 'NN', 'IN', 'DT', 'NN']\n self.assertEqual(result, expected)",
"solution_code": "def get_pos_tag(self, sentence):\n pos_tags = []\n sentence = self.remove_punctuation(sentence)\n words = word_tokenize(sentence)\n tagged_words = pos_tag(words)\n for tagged_word in tagged_words:\n pos_tags.append(tagged_word[1])\n return pos_tags",
@@ -4431,7 +4431,7 @@
},
{
"method_name": "remove_punctuation",
- "method_description": "def remove_punctuation(self, sentence):\n \"\"\"\n Removes punctuation from the input text.\n :param sentence: a sentence str\n :return: str, sentence without any punctuation\n >>> lemmatization = Lemmatization()\n >>> lemmatization.remove_punctuation(\"I am running in a race.\")\n 'I am running in a race'\n \"\"\"",
+ "method_description": "def remove_punctuation(self, sentence):\n \"\"\"\n Removes punctuation from the input text.\n :param sentence: a sentence str\n :return: str, sentence without any punctuation\n >>> lemmatization = Lemmatization()\n >>> lemmatization.remove_punctuation(\"I am running in a race.\")\n 'I am running in a race'\n\n \"\"\"",
"test_class": "LemmatizationTestRemovePunctuation",
"test_code": "class LemmatizationTestRemovePunctuation(unittest.TestCase):\n def test_remove_punctuation_1(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"I am running in a race.\")\n expected = \"I am running in a race\"\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_2(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"Until the beating, Cantanco's eyesight had been weak, but adequate.\")\n expected = 'Until the beating Cantancos eyesight had been weak but adequate'\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_3(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"The dog's barked at the mailman!!!\")\n expected = 'The dogs barked at the mailman'\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_4(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"He was running and eating at same time... \")\n expected = 'He was running and eating at same time '\n self.assertEqual(result, expected)\n\n def test_remove_punctuation_5(self):\n lemmatization = Lemmatization()\n result = lemmatization.remove_punctuation(\"Is this a test? I hope it is...\")\n expected = 'Is this a test I hope it is'\n self.assertEqual(result, expected)",
"solution_code": "def remove_punctuation(self, sentence):\n return sentence.translate(str.maketrans('', '', string.punctuation))",
@@ -4996,7 +4996,7 @@
},
{
"task_id": "ClassEval_60",
- "skeleton": "\nimport sqlite3\n\nclass MovieTicketDB:\n \"\"\"\n This is a class for movie database operations, which allows for inserting movie information, searching for movie information by name, and deleting movie information by name.\n \"\"\"\n\n def __init__(self, db_name):\n \"\"\"\n Initializes the MovieTicketDB object with the specified database name.\n :param db_name: str, the name of the SQLite database.\n \"\"\"\n self.connection = sqlite3.connect(db_name)\n self.cursor = self.connection.cursor()\n self.create_table()\n\n\n def create_table(self):\n \"\"\"\n Creates a \"tickets\" table in the database if it does not exist already.Fields include ID of type int, movie name of type str, author name of type str, seat number of type str, and customer name of type str\n :return: None\n \"\"\"\n\n def insert_ticket(self, movie_name, theater_name, seat_number, customer_name):\n \"\"\"\n Inserts a new ticket into the \"tickets\" table.\n :param movie_name: str, the name of the movie.\n :param theater_name: str, the name of the theater.\n :param seat_number: str, the seat number.\n :param customer_name: str, the name of the customer.\n :return: None\n \"\"\"\n\n def search_tickets_by_customer(self, customer_name):\n \"\"\"\n Searches for tickets in the \"tickets\" table by customer name.\n :param customer_name: str, the name of the customer to search for.\n :return: list of tuples, the rows from the \"tickets\" table that match the search criteria.\n >>> ticket_db = MovieTicketDB(\"ticket_database.db\")\n >>> ticket_db.create_table()\n >>> ticket_db.insert_ticket(\"Movie A\", \"Theater 1\", \"A1\", \"John Doe\")\n >>> result = ticket_db.search_tickets_by_customer(\"John Doe\")\n len(result) = 1\n \"\"\"\n\n def delete_ticket(self, ticket_id):\n \"\"\"\n Deletes a ticket from the \"tickets\" table by ticket ID.\n :param ticket_id: int, the ID of the ticket to delete.\n :return: None\n \"\"\"",
+ "skeleton": "\nimport sqlite3\n\nclass MovieTicketDB:\n \"\"\"\n This is a class for movie database operations, which allows for inserting movie information, searching for movie information by name, and deleting movie information by name.\n \"\"\"\n\n def __init__(self, db_name):\n \"\"\"\n Initializes the MovieTicketDB object with the specified database name.\n :param db_name: str, the name of the SQLite database.\n \"\"\"\n self.connection = sqlite3.connect(db_name)\n self.cursor = self.connection.cursor()\n self.create_table()\n\n\n def create_table(self):\n \"\"\"\n Creates a \"tickets\" table in the database if it does not exist already.Fields include ID of type int, movie name of type str, theater name of type str, seat number of type str, and customer name of type str\n :return: None\n \"\"\"\n\n def insert_ticket(self, movie_name, theater_name, seat_number, customer_name):\n \"\"\"\n Inserts a new ticket into the \"tickets\" table.\n :param movie_name: str, the name of the movie.\n :param theater_name: str, the name of the theater.\n :param seat_number: str, the seat number.\n :param customer_name: str, the name of the customer.\n :return: None\n \"\"\"\n\n def search_tickets_by_customer(self, customer_name):\n \"\"\"\n Searches for tickets in the \"tickets\" table by customer name.\n :param customer_name: str, the name of the customer to search for.\n :return: list of tuples, the rows from the \"tickets\" table that match the search criteria.\n >>> ticket_db = MovieTicketDB(\"ticket_database.db\")\n >>> ticket_db.create_table()\n >>> ticket_db.insert_ticket(\"Movie A\", \"Theater 1\", \"A1\", \"John Doe\")\n >>> result = ticket_db.search_tickets_by_customer(\"John Doe\")\n len(result) = 1\n \"\"\"\n\n def delete_ticket(self, ticket_id):\n \"\"\"\n Deletes a ticket from the \"tickets\" table by ticket ID.\n :param ticket_id: int, the ID of the ticket to delete.\n :return: None\n \"\"\"",
"test": "import unittest\nimport os\n\n\nclass MovieTicketDBTestInsertTicket(unittest.TestCase):\n def setUp(self):\n self.db_name = 'test_database.db'\n self.db = MovieTicketDB(self.db_name)\n\n def tearDown(self):\n self.db.connection.close()\n os.remove(self.db_name)\n\n def test_insert_ticket_1(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'John Doe')\n tickets = self.db.search_tickets_by_customer('John Doe')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'John Doe')\n\n def test_insert_ticket_2(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'aaa')\n tickets = self.db.search_tickets_by_customer('aaa')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'aaa')\n\n def test_insert_ticket_3(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'bbb')\n tickets = self.db.search_tickets_by_customer('bbb')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'bbb')\n\n def test_insert_ticket_4(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'ccc')\n tickets = self.db.search_tickets_by_customer('ccc')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'ccc')\n\n def test_insert_ticket_5(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'ddd')\n tickets = self.db.search_tickets_by_customer('ddd')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'ddd')\n\n\nclass MovieTicketDBTestSearchTicketsByCustomer(unittest.TestCase):\n def setUp(self):\n self.db_name = 'test_database.db'\n self.db = MovieTicketDB(self.db_name)\n\n def tearDown(self):\n self.db.connection.close()\n os.remove(self.db_name)\n\n def test_search_tickets_by_customer_1(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'John Doe')\n tickets = self.db.search_tickets_by_customer('John Doe')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'John Doe')\n\n def test_search_tickets_by_customer_2(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'aaa')\n tickets = self.db.search_tickets_by_customer('aaa')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'aaa')\n\n def test_search_tickets_by_customer_3(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'bbb')\n tickets = self.db.search_tickets_by_customer('bbb')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'bbb')\n\n def test_search_tickets_by_customer_4(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'ccc')\n tickets = self.db.search_tickets_by_customer('ccc')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'ccc')\n\n def test_search_tickets_by_customer_5(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'ddd')\n tickets = self.db.search_tickets_by_customer('ddd')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'ddd')\n\n\nclass MovieTicketDBTestDeleteTicket(unittest.TestCase):\n def setUp(self):\n self.db_name = 'test_database.db'\n self.db = MovieTicketDB(self.db_name)\n\n def tearDown(self):\n self.db.connection.close()\n os.remove(self.db_name)\n\n def test_delete_ticket_1(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'John Doe')\n tickets = self.db.search_tickets_by_customer('John Doe')\n self.assertEqual(len(tickets), 1)\n ticket_id = tickets[0][0]\n self.db.delete_ticket(ticket_id)\n tickets = self.db.search_tickets_by_customer('John Doe')\n self.assertEqual(len(tickets), 0)\n\n def test_delete_ticket_2(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'aaa')\n tickets = self.db.search_tickets_by_customer('aaa')\n self.assertEqual(len(tickets), 1)\n ticket_id = tickets[0][0]\n self.db.delete_ticket(ticket_id)\n tickets = self.db.search_tickets_by_customer('aaa')\n self.assertEqual(len(tickets), 0)\n\n def test_delete_ticket_3(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'bbb')\n tickets = self.db.search_tickets_by_customer('bbb')\n self.assertEqual(len(tickets), 1)\n ticket_id = tickets[0][0]\n self.db.delete_ticket(ticket_id)\n tickets = self.db.search_tickets_by_customer('bbb')\n self.assertEqual(len(tickets), 0)\n\n def test_delete_ticket_4(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'ccc')\n tickets = self.db.search_tickets_by_customer('ccc')\n self.assertEqual(len(tickets), 1)\n ticket_id = tickets[0][0]\n self.db.delete_ticket(ticket_id)\n tickets = self.db.search_tickets_by_customer('ccc')\n self.assertEqual(len(tickets), 0)\n\n def test_delete_ticket_5(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'ddd')\n tickets = self.db.search_tickets_by_customer('ddd')\n self.assertEqual(len(tickets), 1)\n ticket_id = tickets[0][0]\n self.db.delete_ticket(ticket_id)\n tickets = self.db.search_tickets_by_customer('ddd')\n self.assertEqual(len(tickets), 0)\n\n\nclass MovieTicketDBTest(unittest.TestCase):\n def setUp(self):\n self.db_name = 'test_database.db'\n self.db = MovieTicketDB(self.db_name)\n\n def tearDown(self):\n self.db.connection.close()\n os.remove(self.db_name)\n\n def test_MovieTicketDB(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'John Doe')\n tickets = self.db.search_tickets_by_customer('John Doe')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'John Doe')\n ticket_id = tickets[0][0]\n self.db.delete_ticket(ticket_id)\n tickets = self.db.search_tickets_by_customer('John Doe')\n self.assertEqual(len(tickets), 0)",
"solution_code": "import sqlite3\n\n\nclass MovieTicketDB:\n def __init__(self, db_name):\n self.connection = sqlite3.connect(db_name)\n self.cursor = self.connection.cursor()\n self.create_table()\n\n def create_table(self):\n self.cursor.execute('''\n CREATE TABLE IF NOT EXISTS tickets (\n id INTEGER PRIMARY KEY,\n movie_name TEXT,\n theater_name TEXT,\n seat_number TEXT,\n customer_name TEXT\n )\n ''')\n self.connection.commit()\n\n def insert_ticket(self, movie_name, theater_name, seat_number, customer_name):\n self.cursor.execute('''\n INSERT INTO tickets (movie_name, theater_name, seat_number, customer_name)\n VALUES (?, ?, ?, ?)\n ''', (movie_name, theater_name, seat_number, customer_name))\n self.connection.commit()\n\n def search_tickets_by_customer(self, customer_name):\n self.cursor.execute('''\n SELECT * FROM tickets WHERE customer_name = ?\n ''', (customer_name,))\n tickets = self.cursor.fetchall()\n return tickets\n\n def delete_ticket(self, ticket_id):\n self.cursor.execute('''\n DELETE FROM tickets WHERE id = ?\n ''', (ticket_id,))\n self.connection.commit()",
"import_statement": [
@@ -5018,7 +5018,7 @@
"methods_info": [
{
"method_name": "create_table",
- "method_description": "def create_table(self):\n \"\"\"\n Creates a \"tickets\" table in the database if it does not exist already.Fields include ID of type int, movie name of type str, author name of type str, seat number of type str, and customer name of type str\n :return: None\n \"\"\"",
+ "method_description": "def create_table(self):\n \"\"\"\n Creates a \"tickets\" table in the database if it does not exist already.Fields include ID of type int, movie name of type str, theater name of type str, seat number of type str, and customer name of type str\n :return: None\n \"\"\"",
"test_class": "MovieTicketDBTestInsertTicket",
"test_code": "class MovieTicketDBTestInsertTicket(unittest.TestCase):\n def setUp(self):\n self.db_name = 'test_database.db'\n self.db = MovieTicketDB(self.db_name)\n\n def tearDown(self):\n self.db.connection.close()\n os.remove(self.db_name)\n\n def test_insert_ticket_1(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'John Doe')\n tickets = self.db.search_tickets_by_customer('John Doe')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'John Doe')\n\n def test_insert_ticket_2(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'aaa')\n tickets = self.db.search_tickets_by_customer('aaa')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'aaa')\n\n def test_insert_ticket_3(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'bbb')\n tickets = self.db.search_tickets_by_customer('bbb')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'bbb')\n\n def test_insert_ticket_4(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'ccc')\n tickets = self.db.search_tickets_by_customer('ccc')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'ccc')\n\n def test_insert_ticket_5(self):\n self.db.insert_ticket('Avengers: Endgame', 'Cinema 1', 'A1', 'ddd')\n tickets = self.db.search_tickets_by_customer('ddd')\n self.assertEqual(len(tickets), 1)\n ticket = tickets[0]\n self.assertEqual(ticket[1], 'Avengers: Endgame')\n self.assertEqual(ticket[2], 'Cinema 1')\n self.assertEqual(ticket[3], 'A1')\n self.assertEqual(ticket[4], 'ddd')",
"solution_code": "def create_table(self):\n self.cursor.execute('''\n CREATE TABLE IF NOT EXISTS tickets (\n id INTEGER PRIMARY KEY,\n movie_name TEXT,\n theater_name TEXT,\n seat_number TEXT,\n customer_name TEXT\n )\n ''')\n self.connection.commit()",
@@ -8248,7 +8248,7 @@
},
{
"task_id": "ClassEval_94",
- "skeleton": "\nclass VendingMachine:\n \"\"\"\n This is a class to simulate a vending machine, including adding products, inserting coins, purchasing products, viewing balance, replenishing product inventory, and displaying product information.\n \"\"\"\n\n def __init__(self):\n \"\"\"\n Initializes the vending machine's inventory and balance.\n \"\"\"\n self.inventory = {}\n self.balance = 0\n\n def add_item(self, item_name, price, quantity):\n \"\"\"\n Adds a product to the vending machine's inventory.\n :param item_name: The name of the product to be added, str.\n :param price: The price of the product to be added, float.\n :param quantity: The quantity of the product to be added, int.\n :return: None\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.add_item('Coke', 1.25, 10)\n >>> vendingMachine.inventory\n {'Coke': {'price': 1.25, 'quantity': 10}}\n\n \"\"\"\n\n def insert_coin(self, amount):\n \"\"\"\n Inserts coins into the vending machine.\n :param amount: The amount of coins to be inserted, float.\n :return: The balance of the vending machine after the coins are inserted, float.\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.insert_coin(1.25)\n 1.25\n\n \"\"\"\n\n def purchase_item(self, item_name):\n \"\"\"\n Purchases a product from the vending machine and returns the balance after the purchase and display purchase unsuccessful if the product is out of stock.\n :param item_name: The name of the product to be purchased, str.\n :return: If successful, returns the balance of the vending machine after the product is purchased, float,otherwise,returns False.\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}}\n >>> vendingMachine.balance = 1.25\n >>> vendingMachine.purchase_item('Coke')\n 0.0\n >>> vendingMachine.purchase_item('Pizza')\n False\n\n \"\"\"\n\n def restock_item(self, item_name, quantity):\n \"\"\"\n Replenishes the inventory of a product already in the vending machine.\n :param item_name: The name of the product to be replenished, str.\n :param quantity: The quantity of the product to be replenished, int.\n :return: If the product is already in the vending machine, returns True, otherwise, returns False.\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}}\n >>> vendingMachine.restock_item('Coke', 10)\n True\n >>> vendingMachine.restock_item('Pizza', 10)\n False\n\n \"\"\"\n\n def display_items(self):\n \"\"\"\n Displays the products in the vending machine.\n :return: If the vending machine is empty, returns False, otherwise, returns a list of the products in the vending machine, list.\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.display_items()\n False\n >>> vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10} }\n >>> vendingMachine.display_items()\n 'Coke - $1.25 [10]'\n\n \"\"\"",
+ "skeleton": "\nclass VendingMachine:\n \"\"\"\n This is a class to simulate a vending machine, including adding products, inserting coins, purchasing products, viewing balance, replenishing product inventory, and displaying product information.\n \"\"\"\n\n def __init__(self):\n \"\"\"\n Initializes the vending machine's inventory and balance.\n \"\"\"\n self.inventory = {}\n self.balance = 0\n\n def add_item(self, item_name, price, quantity):\n \"\"\"\n Adds a product to the vending machine's inventory.\n :param item_name: The name of the product to be added, str.\n :param price: The price of the product to be added, float.\n :param quantity: The quantity of the product to be added, int.\n :return: None\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.add_item('Coke', 1.25, 10)\n >>> vendingMachine.inventory\n {'Coke': {'price': 1.25, 'quantity': 10}}\n\n \"\"\"\n\n def insert_coin(self, amount):\n \"\"\"\n Inserts coins into the vending machine.\n :param amount: The amount of coins to be inserted, float.\n :return: The balance of the vending machine after the coins are inserted, float.\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.insert_coin(1.25)\n 1.25\n\n \"\"\"\n\n def purchase_item(self, item_name):\n \"\"\"\n Purchases a product from the vending machine and returns the balance after the purchase and display purchase unsuccessful if the product is out of stock.\n :param item_name: The name of the product to be purchased, str.\n :return: If successful, returns the balance of the vending machine after the product is purchased, float,otherwise,returns False.\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}}\n >>> vendingMachine.balance = 1.25\n >>> vendingMachine.purchase_item('Coke')\n 0.0\n >>> vendingMachine.purchase_item('Pizza')\n False\n\n \"\"\"\n\n def restock_item(self, item_name, quantity):\n \"\"\"\n Replenishes the inventory of a product already in the vending machine.\n :param item_name: The name of the product to be replenished, str.\n :param quantity: The quantity of the product to be replenished, int.\n :return: If the product is already in the vending machine, returns True, otherwise, returns False.\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}}\n >>> vendingMachine.restock_item('Coke', 10)\n True\n >>> vendingMachine.restock_item('Pizza', 10)\n False\n\n \"\"\"\n\n def display_items(self):\n \"\"\"\n Displays the products in the vending machine.\n :return: If the vending machine is empty, returns False, otherwise, returns a list of the products in the vending machine, str.\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.display_items()\n False\n >>> vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10} }\n >>> vendingMachine.display_items()\n 'Coke - $1.25 [10]'\n\n \"\"\"",
"test": "import unittest\nclass VendingMachineTestAddItem(unittest.TestCase):\n def test_add_item(self):\n vendingMachine = VendingMachine()\n vendingMachine.add_item('Coke', 1.25, 10)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}})\n\n def test_add_item_2(self):\n vendingMachine = VendingMachine()\n vendingMachine.add_item('Coke', 1.25, 10)\n vendingMachine.add_item('Coke', 1.25, 10)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 20}})\n\n def test_add_item_3(self):\n vendingMachine = VendingMachine()\n vendingMachine.add_item('Coke', 1.25, 10)\n vendingMachine.add_item('Pizza', 1.25, 10)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}, 'Pizza': {'price': 1.25, 'quantity': 10}})\n\n def test_add_item_4(self):\n vendingMachine = VendingMachine()\n vendingMachine.add_item('Coke', 1.25, 10)\n vendingMachine.add_item('Pizza', 1.25, 10)\n vendingMachine.add_item('Pizza', 1.25, 10)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}, 'Pizza': {'price': 1.25, 'quantity': 20}})\n\n def test_add_item_5(self):\n vendingMachine = VendingMachine()\n vendingMachine.add_item('Coke', 1.25, 10)\n vendingMachine.add_item('Pizza', 1.25, 10)\n vendingMachine.add_item('Pizza', 1.25, 10)\n vendingMachine.add_item('Coke', 1.25, 10)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 20}, 'Pizza': {'price': 1.25, 'quantity': 20}})\n\nclass VendingMachineTestInsertCoin(unittest.TestCase):\n def test_insert_coin(self):\n vendingMachine = VendingMachine()\n self.assertEqual(vendingMachine.insert_coin(1.25), 1.25)\n\n def test_insert_coin_2(self):\n vendingMachine = VendingMachine()\n self.assertEqual(vendingMachine.insert_coin(2.5), 2.5)\n\n def test_insert_coin_3(self):\n vendingMachine = VendingMachine()\n vendingMachine.insert_coin(1.25)\n vendingMachine.insert_coin(1.25)\n self.assertEqual(vendingMachine.balance, 2.50)\n\n def test_insert_coin_4(self):\n vendingMachine = VendingMachine()\n vendingMachine.balance = 1.25\n vendingMachine.insert_coin(1.25)\n vendingMachine.insert_coin(1.25)\n vendingMachine.insert_coin(1.25)\n self.assertEqual(vendingMachine.balance, 5.0)\n\n def test_insert_coin_5(self):\n vendingMachine = VendingMachine()\n vendingMachine.balance = 1.25\n vendingMachine.insert_coin(1.25)\n vendingMachine.insert_coin(1.25)\n vendingMachine.insert_coin(1.25)\n vendingMachine.insert_coin(1.25)\n self.assertEqual(vendingMachine.balance, 6.25)\n\nclass VendingMachineTestPurchaseItem(unittest.TestCase):\n def test_purchase_item(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}}\n vendingMachine.balance = 1.25\n self.assertEqual(vendingMachine.purchase_item('Coke'), 0.0)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 9}})\n\n def test_purchase_item_2(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}}\n vendingMachine.balance = 1.25\n self.assertEqual(vendingMachine.purchase_item('Pizza'), False)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}})\n\n def test_purchase_item_3(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}}\n vendingMachine.balance = 0\n self.assertEqual(vendingMachine.purchase_item('Coke'), False)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}})\n\n def test_purchase_item_4(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 0}}\n vendingMachine.balance = 1.25\n self.assertEqual(vendingMachine.purchase_item('Coke'), False)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 0}})\n\n def test_purchase_item_5(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}, 'Pizza': {'price': 1.25, 'quantity': 10}}\n vendingMachine.balance = 1.25\n self.assertEqual(vendingMachine.purchase_item('Pizza'), 0.0)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}, 'Pizza': {'price': 1.25, 'quantity': 9}})\n\nclass VendingMachineTestRestockItem(unittest.TestCase):\n def test_restock_item(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}}\n self.assertEqual(vendingMachine.restock_item('Coke', 10), True)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 20}})\n\n def test_restock_item_2(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}}\n self.assertEqual(vendingMachine.restock_item('Pizza', 10), False)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}})\n\n def test_restock_item_3(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 0}}\n self.assertEqual(vendingMachine.restock_item('Coke', 10), True)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}})\n\n def test_restock_item_4(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}, 'Pizza': {'price': 1.25, 'quantity': 10}}\n self.assertEqual(vendingMachine.restock_item('Pizza', 10), True)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}, 'Pizza': {'price': 1.25, 'quantity': 20}})\n\n def test_restock_item_5(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}, 'Pizza': {'price': 1.25, 'quantity': 10}}\n self.assertEqual(vendingMachine.restock_item('Pizza', 0), True)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}, 'Pizza': {'price': 1.25, 'quantity': 10}})\nclass VendingMachineTestDisplayItems(unittest.TestCase):\n def test_display_items(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}}\n self.assertEqual(vendingMachine.display_items(), 'Coke - $1.25 [10]')\n\n def test_display_items_2(self):\n vendingMachine = VendingMachine()\n self.assertEqual(vendingMachine.display_items(), False)\n\n def test_display_items_3(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}, 'Pizza': {'price': 1.25, 'quantity': 10}}\n self.assertEqual(vendingMachine.display_items(),\"Coke - $1.25 [10]\\nPizza - $1.25 [10]\")\n\n def test_display_items_4(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 0}}\n self.assertEqual(vendingMachine.display_items(), 'Coke - $1.25 [0]')\n\n def test_display_items_5(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 0}, 'Pizza': {'price': 1.25, 'quantity': 10}}\n self.assertEqual(vendingMachine.display_items(), 'Coke - $1.25 [0]\\nPizza - $1.25 [10]')\n\nclass VendingMachineTestMain(unittest.TestCase):\n def test_main(self):\n vendingMachine = VendingMachine()\n self.assertEqual(vendingMachine.display_items(), False)\n vendingMachine.add_item('Coke', 1.25, 10)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}})\n self.assertEqual(vendingMachine.insert_coin(1.25), 1.25)\n self.assertEqual(vendingMachine.purchase_item('Coke'), 0.0)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 9}})\n self.assertEqual(vendingMachine.purchase_item('Pizza'), False)\n self.assertEqual(vendingMachine.restock_item('Coke', 10), True)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 19}})\n self.assertEqual(vendingMachine.restock_item('Pizza', 10), False)\n self.assertEqual(vendingMachine.display_items(), 'Coke - $1.25 [19]')\n\n def test_main_2(self):\n vendingMachine = VendingMachine()\n self.assertEqual(vendingMachine.purchase_item('Coke'), False)\n vendingMachine.add_item('Coke', 1.25, 10)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}})\n self.assertEqual(vendingMachine.restock_item('Pizza', 10), False)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 10}})\n self.assertEqual(vendingMachine.insert_coin(1.25), 1.25)\n self.assertEqual(vendingMachine.purchase_item('Coke'), 0.0)\n self.assertEqual(vendingMachine.inventory, {'Coke': {'price': 1.25, 'quantity': 9}})\n self.assertEqual(vendingMachine.display_items(), 'Coke - $1.25 [9]')",
"solution_code": "class VendingMachine:\n def __init__(self):\n self.inventory = {}\n self.balance = 0\n\n def add_item(self, item_name, price, quantity):\n if not self.restock_item(item_name, quantity):\n self.inventory[item_name] = {'price': price, 'quantity': quantity}\n\n def insert_coin(self, amount):\n self.balance += amount\n return self.balance\n\n def purchase_item(self, item_name):\n if item_name in self.inventory:\n item = self.inventory[item_name]\n if item['quantity'] > 0 and self.balance >= item['price']:\n self.balance -= item['price']\n item['quantity'] -= 1\n return self.balance\n else:\n return False\n else:\n return False\n\n def restock_item(self, item_name, quantity):\n if item_name in self.inventory:\n self.inventory[item_name]['quantity'] += quantity\n return True\n else:\n return False\n\n def display_items(self):\n if not self.inventory:\n return False\n else:\n items = []\n for item_name, item_info in self.inventory.items():\n items.append(f\"{item_name} - ${item_info['price']} [{item_info['quantity']}]\")\n return \"\\n\".join(items)",
"import_statement": [],
@@ -8333,7 +8333,7 @@
},
{
"method_name": "display_items",
- "method_description": "def display_items(self):\n \"\"\"\n Displays the products in the vending machine.\n :return: If the vending machine is empty, returns False, otherwise, returns a list of the products in the vending machine, list.\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.display_items()\n False\n >>> vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10} }\n >>> vendingMachine.display_items()\n 'Coke - $1.25 [10]'\n\n \"\"\"",
+ "method_description": "def display_items(self):\n \"\"\"\n Displays the products in the vending machine.\n :return: If the vending machine is empty, returns False, otherwise, returns a list of the products in the vending machine, str.\n >>> vendingMachine = VendingMachine()\n >>> vendingMachine.display_items()\n False\n >>> vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10} }\n >>> vendingMachine.display_items()\n 'Coke - $1.25 [10]'\n\n \"\"\"",
"test_class": "VendingMachineTestDisplayItems",
"test_code": "class VendingMachineTestDisplayItems(unittest.TestCase):\n def test_display_items(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}}\n self.assertEqual(vendingMachine.display_items(), 'Coke - $1.25 [10]')\n\n def test_display_items_2(self):\n vendingMachine = VendingMachine()\n self.assertEqual(vendingMachine.display_items(), False)\n\n def test_display_items_3(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 10}, 'Pizza': {'price': 1.25, 'quantity': 10}}\n self.assertEqual(vendingMachine.display_items(),\"Coke - $1.25 [10]\\nPizza - $1.25 [10]\")\n\n def test_display_items_4(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 0}}\n self.assertEqual(vendingMachine.display_items(), 'Coke - $1.25 [0]')\n\n def test_display_items_5(self):\n vendingMachine = VendingMachine()\n vendingMachine.inventory = {'Coke': {'price': 1.25, 'quantity': 0}, 'Pizza': {'price': 1.25, 'quantity': 10}}\n self.assertEqual(vendingMachine.display_items(), 'Coke - $1.25 [0]\\nPizza - $1.25 [10]')",
"solution_code": "def display_items(self):\n if not self.inventory:\n return False\n else:\n items = []\n for item_name, item_info in self.inventory.items():\n items.append(f\"{item_name} - ${item_info['price']} [{item_info['quantity']}]\")\n return \"\\n\".join(items)",