Skip to main content

validate_exercise_solution

Function validate_exercise_solution 

Source
pub fn validate_exercise_solution(
    exercise: &Exercise,
    user_code: &str,
) -> ExerciseResult
Expand description

Validate exercise solution.

Truly executing exercise.test_cases against user_code would require compiling and running arbitrary user-submitted code inside a sandboxed Rust toolchain, which this crate does not have. Rather than fabricate a pass/fail verdict from an arbitrary heuristic (the previous implementation scored purely by user_code.len(), independent of exercise.test_cases or correctness), this performs a real, deterministic lexical-similarity comparison against exercise.solution_code: the fraction of the reference solution’s significant tokens (identifiers, method/gate names, numeric literals) that also appear in user_code. This is a genuine, computed measure of structural similarity to a known-correct solution – it is not a substitute for actually executing exercise.test_cases, which the returned feedback makes explicit so callers cannot mistake it for real dynamic grading.