Test Overview
This test simulates a code review process to check for common coding errors and adherence to best practices before running the code. It verifies that the code meets quality standards and is free of obvious mistakes.
This test simulates a code review process to check for common coding errors and adherence to best practices before running the code. It verifies that the code meets quality standards and is free of obvious mistakes.
def code_review_check(code_lines): issues = [] for i, line in enumerate(code_lines, 1): if 'print' in line and not line.strip().endswith(')'): issues.append(f"Line {i}: print statement missing closing parenthesis") if '==' in line and 'if' not in line: issues.append(f"Line {i}: '==' used outside if condition") if line.strip().startswith('def') and not line.strip().endswith(':'): issues.append(f"Line {i}: function definition missing colon") return issues # Example code to review sample_code = [ "def greet()", # Missing colon " print('Hello world'", # Missing closing parenthesis "x == 5", # '==' outside if "if x == 5:", " print('x is 5')" ] issues_found = code_review_check(sample_code) assert len(issues_found) == 3, f"Expected 3 issues, found {len(issues_found)}"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test environment ready with sample code lines loaded | - | PASS |
| 2 | code_review_check function is called with sample code | Function processes each line of code | - | PASS |
| 3 | Line 1 checked: 'def greet()' missing colon detected | Issues list updated with line 1 issue | - | PASS |
| 4 | Line 2 checked: print statement missing closing parenthesis detected | Issues list updated with line 2 issue | - | PASS |
| 5 | Line 3 checked: '==' used outside if condition detected | Issues list updated with line 3 issue | - | PASS |
| 6 | Lines 4 and 5 checked: no issues found | Issues list remains unchanged | - | PASS |
| 7 | Assert that 3 issues were found | Issues list contains 3 items | assert len(issues_found) == 3 | PASS |
| 8 | Test ends successfully | All checks passed, issues correctly identified | - | PASS |