Spaces:
Sleeping
Sleeping
File size: 1,621 Bytes
acd8e16 |
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 |
"""
Python Algorithms Dataset Loader
Creates test data for Python algorithm evaluation.
"""
import os
import json
from typing import List, Dict, Any
def create_test_data(data_path: str = "python_algorithms_test_data.json"):
"""Create test data for Python algorithm evaluation."""
test_data = {
"sort_list": {
"input": [64, 34, 25, 12, 22, 11, 90],
"expected_output": [11, 12, 22, 25, 34, 64, 90]
},
"binary_search": {
"input": {"arr": [1, 3, 5, 7, 9, 11, 13, 15], "target": 7},
"expected_output": 3
},
"fibonacci": {
"input": 10,
"expected_output": 55
},
"two_sum": {
"input": {"nums": [2, 7, 11, 15], "target": 9},
"expected_output": [0, 1]
},
"merge_sort": {
"input": [38, 27, 43, 3, 9, 82, 10],
"expected_output": [3, 9, 10, 27, 38, 43, 82]
},
"bank_account": {
"input": {"operations": ["deposit", "withdraw", "deposit"], "amounts": [100, 50, 25]},
"expected_output": 75
}
}
with open(data_path, 'w') as f:
json.dump(test_data, f, indent=2)
print(f"Created test data: {data_path}")
return data_path
def load_test_data(data_path: str = "python_algorithms_test_data.json") -> Dict[str, Any]:
"""Load test data for evaluation."""
if not os.path.exists(data_path):
create_test_data(data_path)
with open(data_path, 'r') as f:
return json.load(f)
if __name__ == "__main__":
create_test_data()
|