-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_metadata.py
More file actions
72 lines (56 loc) · 2.32 KB
/
create_metadata.py
File metadata and controls
72 lines (56 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
"""
Script to create metadata.json files for all exercism exercises
by counting TEST_CASE and REQUIRE statements in test files.
"""
import os
import re
import json
def count_test_cases_and_assertions(file_path):
"""Count TEST_CASE and REQUIRE statements in a test file."""
try:
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Count TEST_CASE occurrences
test_cases = len(re.findall(r'TEST_CASE\s*\(', content))
# Count REQUIRE and REQUIRE_THROWS assertions
require_matches = re.findall(r'REQUIRE(?:_THROWS(?:_AS)?)?(?:_FALSE)?\s*\(', content)
assertions = len(require_matches)
return test_cases, assertions
except Exception as e:
print(f"Error processing {file_path}: {e}")
return 0, 0
def create_metadata_for_all_exercises():
"""Process all exercises and create metadata.json files."""
practice_dir = "/Users/marcvanduyn/Projects/Microsoft/llm-cpp-eval/benchmark/practice"
# Get all test files
test_files = []
for root, dirs, files in os.walk(practice_dir):
for file in files:
if file.endswith('_test.cpp'):
test_files.append(os.path.join(root, file))
print(f"Found {len(test_files)} test files")
processed = 0
for test_file in test_files:
# Extract exercise name from path
exercise_dir = os.path.dirname(test_file)
exercise_name = os.path.basename(exercise_dir)
# Check if metadata.json already exists
metadata_path = os.path.join(exercise_dir, "metadata.json")
if os.path.exists(metadata_path):
print(f"Skipping {exercise_name} - metadata.json already exists")
continue
# Count test cases and assertions
test_cases, assertions = count_test_cases_and_assertions(test_file)
# Create metadata.json
metadata = {
"number_of_test_cases": test_cases,
"number_of_assertions": assertions
}
with open(metadata_path, 'w') as f:
json.dump(metadata, f, indent=2)
print(f"Created metadata for {exercise_name}: {test_cases} test cases, {assertions} assertions")
processed += 1
print(f"Processed {processed} exercises")
if __name__ == "__main__":
create_metadata_for_all_exercises()