Fix judge output parsing edge cases and migrate to polymorphic solution contract #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🛠️ Summary: Fix Judge Output Parsing and Complete Polymorphic Contract Migration
The changes improve test robustness and documentation clarity while preserving all existing solution algorithms.
Changes
Judge Output Normalization
The test framework parses solution outputs using
ast.literal_eval(), which converts single-value outputs such as "1" intoint. SeveralJUDGE_FUNCimplementations assumed outputs werestrorlistonly, causing failures in edge cases.Fixes applied:
isinstance(actual, int)handling in affectedJUDGE_FUNCimplementations[actual]Affected solutions:
intinput and fix empty line parsingintinput fork=0single-line outputintinput for single-element arraysintinput and fix empty array parsingintinput for single-element arraysintinput for single-node listsintinput for single-element arraysArchitecture and Contract Updates
Complete the transition from the deprecated wrapper-based solution pattern to the polymorphic solution contract.
Key updates:
docs/solution_contract.mdas the canonical specification for:SOLUTIONS + get_solver())SOLUTIONSmetadata schema (required class and method)JUDGE_FUNC,COMPARE_MODEpriority)template_solution.py: Polymorphic single-solution templatetemplate_solution_multi.py: Multiple classes with shared method name--wrapperCLI optionnew_problem.bat / new_problem.sh: Remove--wrapperoptionrun_tests.bat: Fix argument forwarding using%*README.mdandREADME_zh-TW.mdto reflect the new architectureARCHITECTURE_MIGRATION.mdtest_debug.py,test_output.py)Testing
Root Cause
The compare module parses outputs with
ast.literal_eval()before passing them toJUDGE_FUNC.Numeric outputs are converted to
int, which was not handled by several judge implementations.Backward Compatibility
--wrapperoption are removed (breaking change)SOLUTIONS + get_solver()contract