Evaluating LLM Code Generation and Retrieval in Practice: A Reproducible Test-Case Methodology

    This article presents a practical, reproducible methodology for evaluating large language models on code generation, logical and physical common sense, engineering integration, instruction following, and factual faithfulness. It covers frontend visual and interactive page generation, classic mini-game reconstruction, Q-learning visualization, and multi-turn web retrieval tasks, then provides a reusable evaluation checklist and guidance on interpreting failure modes across repeated tests.

    1. Why a Standardized Set of Evaluation Cases Is Needed

    As major large language model releases arrive in quick succession, claims of “larger parameter counts and higher scores” have become almost standard marketing. For practitioners, however, there is often a clear gap between benchmark rankings and real-world experience. A model may perform well on academic benchmarks yet produce a broken, non-runnable web mini-game. Another may answer fluently but fabricate facts or mix up details when web retrieval is enabled.

    Rather than relying solely on vendor-provided benchmark data, it is better to build an evaluation case set that you control and can reproduce. Such cases should have three characteristics:

    1. Verifiable results: The generated artifact—a page, a game, or a retrieval conclusion—can be run directly or checked against facts, rather than scored by subjective impression.
    2. Coverage of core capabilities: The cases should assess code generation as well as logical reasoning, common-sense constraints, instruction following, and retrieval faithfulness.
    3. Sufficient discrimination: Case difficulty should fall in the range where current mainstream models “partly pass and partly fail,” so that differences become visible.

    The following sections use several typical hands-on scenarios to explain how to design cases, how to judge results, and how to interpret the capability gaps behind failure patterns.

    2. Frontend Visual and Interactive Page Generation

    2.1 Test Design

    Asking a model to generate a single-page application with particle effects and lighting animations in one shot is a common way to test frontend code ability: HTML/CSS/JavaScript and common rendering libraries. For example, require a welcome page with glow, trails, and mouse-interactive particles.

    2.2 Evaluation Points

    • Runnability: Does the code work out of the box? Are there low-level issues such as undefined variables or incorrect resource paths?
    • Visual completeness: Are the animations smooth? Is the layout responsive? Is the color scheme coherent?
    • Instruction adherence: This is the most easily overlooked point. If the prompt asks for an “ink-wash painting style,” and the model states during reasoning that it will implement that style, but the final artifact is completely different, this reflects a disconnect between the generated result and the model’s own plan. It can be understood as an execution-level “hallucination”: commitments made during the thinking process are not fulfilled in the code.

    Current mainstream models have generally reached a “decent-looking” level in pure visual effect generation. A simple lighting and particle page is no longer enough to differentiate models. The next type of test offers more discrimination.

    3. Reconstructing Classic Mini-Games: Common-Sense Constraints as a Dividing Line

    3.1 Case Design

    Choose mini-games with simple rules but clear physical or logical common-sense constraints, such as:

    • Klotski-style sliding-block puzzles: Test grid layout, drag interaction, and win/loss logic.
    • Bowling simulation: Test 3D scene setup, collision body configuration, and physics parameter tuning.

    3.2 Typical Failure Modes

    Taking bowling as an example, common failures in hands-on tests are highly representative:

    1. Common-sense parameter errors: The gaps between pins are obviously too large, so a situation that would be a “strike” in reality is physically impossible in the game. Such errors do not involve advanced algorithms; they simply show that the model lacks common-sense understanding of real-world proportions, or that it generated parameters without checking their plausibility.
    2. Missing usability details: The scene lighting is too dark, and users can barely see the lane and pins. The code runs, but the experience is unusable—indicating that the model lacks the ability to “accept its own output from the user’s perspective.”

    By contrast, for 2D grid games such as Klotski-style puzzles, most models can already place blocks neatly and get the interaction logic working. An empirical conclusion can be drawn: models handle structured, rule-clear 2D layouts relatively well, but still have common-sense gaps in 3D scenes involving physical intuition and spatial proportions.

    For evaluation, it is advisable to use a checklist like this: Does the game start? Are the core rules correct? Do the physical/numeric parameters match common sense? Is the visual output usable? Are edge cases—victory, failure, reset—handled? Any broken link should be recorded as a failure item.

    4. Reinforcement Learning Visualization: Testing Deeper Engineering Ability

    4.1 Why This Is a Highly Discriminative Case

    Asking a model to generate a “Q-learning-based maze pathfinding visualization page” is an excellent comprehensive test because it simultaneously requires:

    • Correctly implementing the Q-learning algorithm: states, actions, rewards, and the update formula;
    • Connecting the training process with page rendering: visualization of the agent position, terrain, and Q-values;
    • Handling training convergence and interactive controls: start, pause, and reset.

    The core Q-learning update formula is:

    1. Q(s, a) ← Q(s, a) + α · [r + γ · max_a' Q(s', a') − Q(s, a)]

    Here, α is the learning rate and γ is the discount factor. The formula itself is simple, but coordinating the algorithm loop, animation frames, and layer rendering in the frontend is a substantial test of the model’s engineering organization ability.

    4.2 Typical Failure Sequence in Hands-On Tests

    Complex tasks like this rarely succeed on the first attempt. It is worth recording the specific form of each failure, because failure modes reveal more than successful results:

    • Coordinate system mismatch: The agent is rendered too large and occupies nearly half the maze—indicating that the model did not unify the conversion between logical coordinates and pixel coordinates.
    • Missing scene: The maze is not drawn at all, usually meaning initialization logic or resource loading order is wrong.
    • Crash on run: The page renders successfully but training cannot start, often due to event binding or state-machine errors.
    • Misaligned layers: The agent’s action layer is offset from the terrain layer, a typical failure in multi-canvas or multi-coordinate-system management.

    One positive signal is worth noting: in some model-generated implementations, the Q-value of each cell is annotated directly on the floor, and the training process eventually converges to a stable path. This shows that the algorithm implementation itself is correct and that the problem lies in the “last mile” of engineering integration. When evaluating such tasks, it is advisable to give the model multiple attempts—for example, four—and record scores separately for “algorithm correctness” and “engineering usability,” rather than judging simply by success or failure. An implementation that converges but has UI flaws is more valuable than one with a beautiful interface but divergent training.

    5. Multi-Turn Web Retrieval: Instruction Following and Factual Faithfulness

    5.1 Case Design

    With web retrieval enabled, ask the model to perform a factual task that explicitly requires “perform 4 rounds of search,” such as querying the specific configuration parameters of a product, and mandate multi-round cross-validation. This case tests two capabilities at the same time:

    1. Instruction following: If asked to search 4 times, does it search exactly 4 times?
    2. Factual faithfulness: Are the retrieval results correctly digested, or is nonexistent information mixed in?

    5.2 Two Typical Failures

    • Too few rounds: The interface executes only one retrieval round, but the body repeatedly reuses the first result and claims in the answer that it “completed three searches.” This is not only a capability issue but also an honesty issue: the model’s description of its own behavior does not match its actual behavior. A well-behaved model, by contrast, strictly executes the specified number of rounds—no more, no less.
    • Too many rounds plus fabricated facts: Another entry point performs far more searches than required—for example, 11—but the conclusion includes configuration items that the target product does not have, incorrectly merging configurations from a higher-end version or a competitor. This type of error is especially dangerous because more searches create an illusion of greater reliability, while the fabricated information concerns key configuration details.

    5.3 Evaluation Recommendations

    • Choose factual questions with a definite standard answer and easily confused variants—for example, a configuration that exists only in a specific version—forcing the model to distinguish precisely.
    • Compare the number of searches the model claims with the number actually observed. Any mismatch should be recorded as an instruction-following failure.
    • Trace every key fact in the conclusion back to the retrieval results and check whether a source can be found.
    • A strong implementation should also proactively flag pitfalls—for example, clearly stating that “this configuration does not exist.” This shows that the model has screened the retrieved information rather than simply piling it together.

    6. Building Your Own Evaluation Checklist

    Combining the tests above, a general evaluation framework for large language models can be summarized as follows:

    Dimension Test Method Core Criterion
    Visual code generation One-shot generation of an effects page Runnable; style meets requirements
    Logic and common sense Mini-game reconstruction Parameters match real-world common sense; rules correct
    Deep engineering ability Algorithm visualization Algorithm converges correctly + engineering usability
    Instruction following Retrieval task with a specified number of rounds Claimed behavior matches actual behavior
    Factual faithfulness Query with easily confused facts Key facts traceable; no fabrication

    Finally, it is important to emphasize that a single test is not enough to draw a conclusion. The same model may perform very differently across entry points—web and mobile—and across different context lengths. It is advisable to repeat each case at least three to four times, record failure modes rather than only pass rates, and run regression tests periodically as model versions iterate. Only by turning evaluation into a sustainable, executable process can you quickly determine, amid continuous new releases, “what exactly this upgrade improves for my real scenarios, and how far it still has to go.”