ClassEval: A Manually-Crafted Benchmark for Evaluating LLMs on Class-level Code Generation
Paper • 2308.01861 • Published • 2
task_id string | source string | source_id string | solution_code string | test string | methods_info_json string | num_functions int64 | num_cross_deps int64 | difficulty_split string | nondeterminism_flags list | class_name string | variant int64 | instruction string | prompt_text string | target_text string | prompt_parse_ok bool | prompt_parse_error string |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ClassEval_0 | FudanSELab/ClassEval | ClassEval_0 | import logging
import datetime
class AccessGatewayFilter:
def __init__(self):
pass
def filter(self, request):
request_uri = request['path']
method = request['method']
if self.is_start_with(request_uri):
return True
try:
token = self.get_jwt_u... | import unittest
class AccessGatewayFilterTestFilter(unittest.TestCase):
def test_filter_1(self):
agf = AccessGatewayFilter()
request = {'path': '/api/data', 'method': 'GET'}
res = agf.filter(request)
self.assertTrue(res)
def test_filter_2(self):
agf = AccessGatewayFilte... | [{"method_name": "filter", "method_description": "def filter(self, request):\n \"\"\"\n Filter the incoming request based on certain rules and conditions.\n :param request: dict, the incoming request details\n :return: bool, True if the request is allowed, False otherwise\n >>> filter... | 4 | 3 | mixed | [
"datetime.now"
] | AccessGatewayFilter | 1 | Complete all missing function or method bodies. Return the complete Python file. | """This class is a filter used for accessing gateway filtering, primarily for authentication and access log recording."""
import logging
import datetime
class AccessGatewayFilter:
"""
This class is a filter used for accessing gateway filtering, primarily for authentication and access log recording.
"""
... | true | ||
ClassEval_0 | FudanSELab/ClassEval | ClassEval_0 | import logging
import datetime
class AccessGatewayFilter:
def __init__(self):
pass
def filter(self, request):
request_uri = request['path']
method = request['method']
if self.is_start_with(request_uri):
return True
try:
token = self.get_jwt_u... | import unittest
class AccessGatewayFilterTestFilter(unittest.TestCase):
def test_filter_1(self):
agf = AccessGatewayFilter()
request = {'path': '/api/data', 'method': 'GET'}
res = agf.filter(request)
self.assertTrue(res)
def test_filter_2(self):
agf = AccessGatewayFilte... | [{"method_name": "filter", "method_description": "def filter(self, request):\n \"\"\"\n Filter the incoming request based on certain rules and conditions.\n :param request: dict, the incoming request details\n :return: bool, True if the request is allowed, False otherwise\n >>> filter... | 4 | 3 | mixed | [
"datetime.now"
] | AccessGatewayFilter | 2 | Complete all missing function or method bodies. Return the complete Python file. | import logging
import datetime
class AccessGatewayFilter:
def __init__(self):
pass
def filter(self, request):
request_uri = request['path']
...
def is_start_with(self, request_uri):
start_with = ['/api', '/login']
...
def get_jwt_user(self, request):
... | true | ||
ClassEval_0 | FudanSELab/ClassEval | ClassEval_0 | import logging
import datetime
class AccessGatewayFilter:
def __init__(self):
pass
def filter(self, request):
request_uri = request['path']
method = request['method']
if self.is_start_with(request_uri):
return True
try:
token = self.get_jwt_u... | import unittest
class AccessGatewayFilterTestFilter(unittest.TestCase):
def test_filter_1(self):
agf = AccessGatewayFilter()
request = {'path': '/api/data', 'method': 'GET'}
res = agf.filter(request)
self.assertTrue(res)
def test_filter_2(self):
agf = AccessGatewayFilte... | [{"method_name": "filter", "method_description": "def filter(self, request):\n \"\"\"\n Filter the incoming request based on certain rules and conditions.\n :param request: dict, the incoming request details\n :return: bool, True if the request is allowed, False otherwise\n >>> filter... | 4 | 3 | mixed | [
"datetime.now"
] | AccessGatewayFilter | 3 | Implement the complete class. Return the complete Python file. | """This class is a filter used for accessing gateway filtering, primarily for authentication and access log recording.
Required methods (implement on the class; order is not specified):
- `__init__(self)`
- `filter(self, request)`: Filter the incoming request based on certain rules and conditions.
- `is_start_with(sel... |
def __init__(self):
pass
def filter(self, request):
request_uri = request['path']
method = request['method']
if self.is_start_with(request_uri):
return True
try:
token = self.get_jwt_user(request)
user = token['user']
if u... | true | |
ClassEval_1 | FudanSELab/ClassEval | ClassEval_1 | import math
class AreaCalculator:
def __init__(self, radius):
self.radius = radius
def calculate_circle_area(self):
return math.pi * self.radius ** 2
def calculate_sphere_area(self):
return 4 * math.pi * self.radius ** 2
def calculate_cylinder_area(self, height):
re... | import unittest
class AreaCalculatorTestCalculateCircleArea(unittest.TestCase):
def test_calculate_circle_area(self):
areaCalculator = AreaCalculator(2)
self.assertAlmostEqual(12.56, areaCalculator.calculate_circle_area(), delta=0.01)
def test_calculate_circle_area_2(self):
areaCalculat... | [{"method_name": "calculate_circle_area", "method_description": "def calculate_circle_area(self):\n \"\"\"\n calculate the area of circle based on self.radius\n :return: area of circle, float\n >>> areaCalculator = AreaCalculator(2)\n >>> areaCalculator.calculate_circle_area()\n ... | 5 | 4 | sequential | [] | AreaCalculator | 1 | Complete all missing function or method bodies. Return the complete Python file. | """This is a class for calculating the area of different shapes, including circle, sphere, cylinder, sector and annulus."""
import math
class AreaCalculator:
"""
This is a class for calculating the area of different shapes, including circle, sphere, cylinder, sector and annulus.
"""
def __init__(self,... | true | ||
ClassEval_1 | FudanSELab/ClassEval | ClassEval_1 | import math
class AreaCalculator:
def __init__(self, radius):
self.radius = radius
def calculate_circle_area(self):
return math.pi * self.radius ** 2
def calculate_sphere_area(self):
return 4 * math.pi * self.radius ** 2
def calculate_cylinder_area(self, height):
re... | import unittest
class AreaCalculatorTestCalculateCircleArea(unittest.TestCase):
def test_calculate_circle_area(self):
areaCalculator = AreaCalculator(2)
self.assertAlmostEqual(12.56, areaCalculator.calculate_circle_area(), delta=0.01)
def test_calculate_circle_area_2(self):
areaCalculat... | [{"method_name": "calculate_circle_area", "method_description": "def calculate_circle_area(self):\n \"\"\"\n calculate the area of circle based on self.radius\n :return: area of circle, float\n >>> areaCalculator = AreaCalculator(2)\n >>> areaCalculator.calculate_circle_area()\n ... | 5 | 4 | sequential | [] | AreaCalculator | 2 | Complete all missing function or method bodies. Return the complete Python file. | import math
class AreaCalculator:
def __init__(self, radius):
self.radius = radius
def calculate_circle_area(self):
return math.pi * self.radius ** 2
def calculate_sphere_area(self):
return 4 * math.pi * self.radius ** 2
def calculate_cylinder_area(self, height):
ret... | true | ||
ClassEval_1 | FudanSELab/ClassEval | ClassEval_1 | import math
class AreaCalculator:
def __init__(self, radius):
self.radius = radius
def calculate_circle_area(self):
return math.pi * self.radius ** 2
def calculate_sphere_area(self):
return 4 * math.pi * self.radius ** 2
def calculate_cylinder_area(self, height):
re... | import unittest
class AreaCalculatorTestCalculateCircleArea(unittest.TestCase):
def test_calculate_circle_area(self):
areaCalculator = AreaCalculator(2)
self.assertAlmostEqual(12.56, areaCalculator.calculate_circle_area(), delta=0.01)
def test_calculate_circle_area_2(self):
areaCalculat... | [{"method_name": "calculate_circle_area", "method_description": "def calculate_circle_area(self):\n \"\"\"\n calculate the area of circle based on self.radius\n :return: area of circle, float\n >>> areaCalculator = AreaCalculator(2)\n >>> areaCalculator.calculate_circle_area()\n ... | 5 | 4 | sequential | [] | AreaCalculator | 3 | Implement the complete class. Return the complete Python file. | """This is a class for calculating the area of different shapes, including circle, sphere, cylinder, sector and annulus.
Required methods (implement on the class; order is not specified):
- `__init__(self, radius)`
- `calculate_circle_area(self)`: calculate the area of circle based on self.radius
- `calculate_sphere_a... |
def __init__(self, radius):
self.radius = radius
def calculate_circle_area(self):
return math.pi * self.radius ** 2
def calculate_sphere_area(self):
return 4 * math.pi * self.radius ** 2
def calculate_cylinder_area(self, height):
return 2 * math.pi * self.radius * (se... | true | |
ClassEval_2 | FudanSELab/ClassEval | ClassEval_2 | class ArgumentParser:
def __init__(self):
self.arguments = {}
self.required = set()
self.types = {}
def parse_arguments(self, command_string):
args = command_string.split()[1:]
for i in range(len(args)):
arg = args[i]
if arg.startswith('--'):
... | import unittest
class ArgumentParserTestParseArguments(unittest.TestCase):
def setUp(self):
self.parser = ArgumentParser()
# key value arguments
def test_parse_arguments_1(self):
command_str = "script --name=John --age=25"
self.parser.add_argument("name")
self.parser.add_a... | [{"method_name": "parse_arguments", "method_description": "def parse_arguments(self, command_string):\n \"\"\"\n Parses the given command line argument string and invoke _convert_type to stores the parsed result in specific type in the arguments dictionary.\n Checks for missing required arguments, ... | 4 | 7 | sequential | [] | ArgumentParser | 1 | Complete all missing function or method bodies. Return the complete Python file. | """This is a class for parsing command line arguments to a dictionary."""
class ArgumentParser:
"""
This is a class for parsing command line arguments to a dictionary.
"""
def __init__(self):
"""Initialize the fields.
self.arguments is a dict that stores the args in a command line
self.requrie... | true | ||
ClassEval_2 | FudanSELab/ClassEval | ClassEval_2 | class ArgumentParser:
def __init__(self):
self.arguments = {}
self.required = set()
self.types = {}
def parse_arguments(self, command_string):
args = command_string.split()[1:]
for i in range(len(args)):
arg = args[i]
if arg.startswith('--'):
... | import unittest
class ArgumentParserTestParseArguments(unittest.TestCase):
def setUp(self):
self.parser = ArgumentParser()
# key value arguments
def test_parse_arguments_1(self):
command_str = "script --name=John --age=25"
self.parser.add_argument("name")
self.parser.add_a... | [{"method_name": "parse_arguments", "method_description": "def parse_arguments(self, command_string):\n \"\"\"\n Parses the given command line argument string and invoke _convert_type to stores the parsed result in specific type in the arguments dictionary.\n Checks for missing required arguments, ... | 4 | 7 | sequential | [] | ArgumentParser | 2 | Complete all missing function or method bodies. Return the complete Python file. | class ArgumentParser:
def __init__(self):
self.arguments = {}
self.required = set()
self.types = {}
def parse_arguments(self, command_string):
args = command_string.split()[1:]
...
def get_argument(self, key):
return self.arguments.get(key)
def add_arg... | true | ||
ClassEval_2 | FudanSELab/ClassEval | ClassEval_2 | class ArgumentParser:
def __init__(self):
self.arguments = {}
self.required = set()
self.types = {}
def parse_arguments(self, command_string):
args = command_string.split()[1:]
for i in range(len(args)):
arg = args[i]
if arg.startswith('--'):
... | import unittest
class ArgumentParserTestParseArguments(unittest.TestCase):
def setUp(self):
self.parser = ArgumentParser()
# key value arguments
def test_parse_arguments_1(self):
command_str = "script --name=John --age=25"
self.parser.add_argument("name")
self.parser.add_a... | [{"method_name": "parse_arguments", "method_description": "def parse_arguments(self, command_string):\n \"\"\"\n Parses the given command line argument string and invoke _convert_type to stores the parsed result in specific type in the arguments dictionary.\n Checks for missing required arguments, ... | 4 | 7 | sequential | [] | ArgumentParser | 3 | Implement the complete class. Return the complete Python file. | """This is a class for parsing command line arguments to a dictionary.
Required methods (implement on the class; order is not specified):
- `__init__(self)`
- `parse_arguments(self, command_string)`: Parses the given command line argument string and invoke _convert_type to stores the parsed result in specific type in ... |
def __init__(self):
self.arguments = {}
self.required = set()
self.types = {}
def parse_arguments(self, command_string):
args = command_string.split()[1:]
for i in range(len(args)):
arg = args[i]
if arg.startswith('--'):
key_value... | true | |
ClassEval_3 | FudanSELab/ClassEval | ClassEval_3 | "import itertools\n\n\nclass ArrangementCalculator:\n def __init__(self, datas):\n self.da(...TRUNCATED) | "import unittest\n\n\nclass ArrangementCalculatorTestCount(unittest.TestCase):\n def test_count_1(...TRUNCATED) | "[{\"method_name\": \"count\", \"method_description\": \"def count(n, m=None):\\n \\\"\\\"\\\(...TRUNCATED) | 5 | 5 | sequential | [] | ArrangementCalculator | 1 | Complete all missing function or method bodies. Return the complete Python file. | "\"\"\"The Arrangement class provides permutation calculations and selection operations for a given (...TRUNCATED) | true |
Derived from FudanSELab/ClassEval (Du et al. 2023, arXiv:2308.01861). License: CC BY-NC 4.0 (upstream data license). Non-commercial use only.
One row per (task_id, variant) with variant in {1,2,3} (100 tasks × 3 = 300 rows; Hub split test).
solution_code, test, and methods_info_json come from upstream.
We add rendered prompts/targets and stratification fields.
Missing bodies use ....
Variants:
........class ClassName: (no pass, no def). target_text is the indented class body.| Field | Meaning |
|---|---|
task_id |
ClassEval task id (e.g. ClassEval_0). |
variant |
1, 2, or 3 (above). |
instruction |
External instruction for this variant. |
prompt_text |
Prompt file. Variants 1–2: full file with ... holes. Variant 3: docstring + imports + class ClassName:. |
target_text |
Empty for Variants 1–2. Variant 3: indented class body; prompt_text + target_text is a full file. |
solution_code |
Gold full-class implementation. |
test |
Class-level unittest source (Pass@1). |
methods_info_json |
JSON list of per-method objects (see below). |
class_name |
Target class name. |
num_functions |
Method count. |
num_cross_deps |
Method/field dependency edge count. |
difficulty_split |
parallel, mixed, or sequential. |
nondeterminism_flags |
Soft flags (e.g. datetime.now); tasks are kept. |
prompt_parse_ok |
prompt_text parsed during build. |
prompt_parse_error |
Error string if not prompt_parse_ok; else empty. |
source |
Always FudanSELab/ClassEval. |
source_id |
Upstream id (same as task_id). |
methods_info_json elements:
| Subfield | Meaning |
|---|---|
method_name |
Short name (e.g. filter). |
method_description |
def name(...): plus docstring. |
test_class |
Per-method unittest class name. |
test_code |
Per-method unittest source. |
solution_code |
Gold body for this method. |
dependencies |
Standalone, lib_dependencies, field_dependencies, method_dependencies. |