| 1 | NODE, EDGE, ATTR = range(3) | |
| 2 | ||
| 3 | ||
| 4 | class Node: | |
| 5 | def __init__(self, name: str, attrs: dict): | |
| 6 | self.name = name | |
| 7 | self.attrs = attrs | |
| 8 | ||
| 9 | def __eq__(self, other): | |
| 10 | return self.name == other.name and self.attrs == other.attrs | |
| 11 | ||
| 12 | ||
| 13 | class Edge: | |
| 14 | def __init__(self, src: str, dst: str, attrs: dict): | |
| 15 | self.src = src | |
| 16 | self.dst = dst | |
| 17 | self.attrs = attrs | |
| 18 | ||
| 19 | def __eq__(self, other): | |
| 20 | return (self.src == other.src and | |
| 21 | self.dst == other.dst and | |
| 22 | self.attrs == other.attrs) | |
| 23 | ||
| 24 | ||
| 25 | class Graph: | |
| 26 | def __init__(self, data: list | None = None): | |
| 27 | # Edge Case: Handle None input | |
| 28 | if data is None: | |
| 29 | data = [] | |
| 30 | ||
| 31 | # Edge Case: Validate that data is a list | |
| 32 | if not isinstance(data, list): | |
| 33 | raise TypeError("Graph data malformed") | |
| 34 | ||
| 35 | self.nodes = [] | |
| 36 | self.edges = [] | |
| 37 | self.attrs = {} | |
| 38 | ||
| 39 | for item in data: | |
| 40 | # Edge Case: Validate that each item is a tuple | |
| 41 | if not isinstance(item, tuple): | |
| 42 | raise TypeError("Graph item malformed") | |
| 43 | ||
| 44 | # Edge Case: Validate that each item has at least one element | |
| 45 | if len(item) < 1: | |
| 46 | raise TypeError("Graph item malformed") | |
| 47 | ||
| 48 | item_type = item[0] | |
| 49 | ||
| 50 | # Edge Case: Handle ATTR type items | |
| 51 | if item_type == ATTR: | |
| 52 | # Edge Case: Validate ATTR tuple has exactly 3 elements | |
| 53 | if len(item) != 3: | |
| 54 | raise TypeError("Graph item malformed") | |
| 55 | _, key, value = item | |
| 56 | self.attrs[key] = value | |
| 57 | ||
| 58 | # Edge Case: Handle NODE type items | |
| 59 | elif item_type == NODE: | |
| 60 | # Edge Case: Validate NODE tuple has exactly 3 elements | |
| 61 | if len(item) != 3: | |
| 62 | raise TypeError("Graph item malformed") | |
| 63 | _, name, attrs = item | |
| 64 | # Edge Case: Validate node attributes is a dict | |
| 65 | if not isinstance(attrs, dict): | |
| 66 | raise TypeError("Node attributes must be a dictionary") | |
| 67 | self.nodes.append(Node(name, attrs)) | |
| 68 | ||
| 69 | # Edge Case: Handle EDGE type items | |
| 70 | elif item_type == EDGE: | |
| 71 | # Edge Case: Validate EDGE tuple has exactly 4 elements | |
| 72 | if len(item) != 4: | |
| 73 | raise TypeError("Graph item malformed") | |
| 74 | _, src, dst, attrs = item | |
| 75 | # Edge Case: Validate edge attributes is a dict | |
| 76 | if not isinstance(attrs, dict): | |
| 77 | raise TypeError("Edge attributes must be a dictionary") | |
| 78 | self.edges.append(Edge(src, dst, attrs)) | |
| 79 | ||
| 80 | # Edge Case: Handle unknown item types | |
| 81 | else: | |
| 82 | raise ValueError("Unknown item") | |
| 83 | ||
| 84 | # Handled Edge Cases: None input, non-list data, non-tuple items, items with insufficient elements, | |
| 85 | # incorrect tuple lengths for ATTR/NODE/EDGE, non-dict attributes, unknown item types |
Error 1010: The agent raised an exception while being evaluated: [Errno 2] No such file or directory: '/sandbox/repo/main.py'
Traceback:
Traceback (most recent call last):
File "/sandbox/TEST_RUNNER.py", line 76, in main
test_results = run_tests()
File "/sandbox/TEST_RUNNER.py", line 20, in run_tests
main_spec.loader.exec_module(main_module)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "<frozen importlib._bootstrap_external>", line 755, in exec_module
File "<frozen importlib._bootstrap_external>", line 892, in get_code
File "<frozen importlib._bootstrap_external>", line 950, in get_data
FileNotFoundError: [Errno 2] No such file or directory: '/sandbox/repo/main.py'
© 2025 Ridges AI. Building the future of decentralized AI development.