diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2025-10-14 20:07:32 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2025-10-14 20:07:32 +0800 |
| commit | acb703325d865e1ecf5b7d782410e4eaad37d488 (patch) | |
| tree | 312cad2e9d0dbeb608fdd300061b854e4cfa891b | |
| parent | 9d0613b0cb986280e1fb494b1802900eca013b22 (diff) | |
| download | datalab2026-acb703325d865e1ecf5b7d782410e4eaad37d488.tar.gz datalab2026-acb703325d865e1ecf5b7d782410e4eaad37d488.tar.xz | |
update test.py
| -rw-r--r-- | test.py | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -11,6 +11,7 @@ class FunctionAnalyzer(c_ast.NodeVisitor): self.has_array = False self.function_name = None self.type_conversions = [] + self.ternary_ops = [] def visit_FuncDef(self, node): self.function_name = node.decl.name @@ -19,6 +20,11 @@ class FunctionAnalyzer(c_ast.NodeVisitor): def visit_BinaryOp(self, node): self.operators.append(node.op) self.generic_visit(node) + def visit_TernaryOp(self, node): + + self.ternary_ops.append(node) + + self.generic_visit(node) def visit_UnaryOp(self, node): self.operators.append(node.op) @@ -249,10 +255,11 @@ def test_legality(ast, function): operators.append("+") else: operators.append(i) - illegal = set() if analyzer.has_array: illegal.add("array") + if len(analyzer.ternary_ops) !=0: + operators.append("? :") for i in operators: if i != "==": i = i.replace("=", "") @@ -383,8 +390,7 @@ def main(): else: print(f"{' ' *33}error{i+1}: {msg_body}") - max_points = sum(problem_info["rating"] for problem_info in problem_infos.values()) - print(f"Total points: {total_points}/{max_points}") + print(f"Total points: {total_points}") # AutoGrader with open(".autograder_result", "w") as f: @@ -392,4 +398,4 @@ def main(): if __name__ == "__main__": - main() + main()
\ No newline at end of file |
