Introduction
Large Language Models (LLMs) have revolutionized software development through tools like GitHub Copilot. However, translating informal natural language (NL) intent into precise code remains a challenge. NL is inherently ambiguous; a simple prompt can lead to multiple valid-looking but logically distinct implementations. Currently, developers must manually audit AI-generated code—a high-effort task that often results in the acceptance of "plausibly correct" but buggy code. To address this, we present TICODER (Test-driven Interactive Code Generation), a framework that formalizes user intent through interactive test validation.
The TICODER Framework
TICODER moves away from one-shot generation toward a test-driven dialogue. Instead of asking users to review complex code, the system generates a suite of potential test cases (input-output pairs) alongside candidate code solutions.
The workflow follows a multi-step cycle:
- Generation: The LLM produces a pool of candidate solutions and discriminative tests.
- Ranking: Tests are ranked based on their ability to partition the code pool (i.e., identifying tests where candidates disagree on the output).
- Interaction: The user validates the top-ranked test.
- Pruning: Code suggestions inconsistent with user feedback are removed.
- Refinement: The process repeats until a high-confidence solution is reached.
User Interaction Modes
The system supports different levels of user engagement to minimize cognitive load. In TICODER-PASSFAIL, users simply confirm if a specific assertion (e.g., func("test_case") == True) is correct. In TICODER-OUTPUT, users provide the expected result for a given input if the model's suggestion is incorrect.
Empirical Evaluation and Results
The researchers evaluated TICODER using the MBPP (Mostly Basic Python Problems) and HumanEval datasets across various models, including GPT-4 and CodeGen.
Accuracy Gains
The results demonstrate a substantial performance boost. Across all benchmarks, TICODER improved pass@1 accuracy by an average of 45.97% within just five interactions. Notably, TICODER allows smaller models (e.g., code-davinci-002) to outperform much larger models like GPT-4 used in a standard one-shot configuration. By pruning the search space, the system ensures that the final suggestions presented to the user are consistent with their verified intent.
Human-Centric Metrics
A user study involving 15 programmers confirmed that TICODER significantly reduces cognitive load. Using NASA TLX scores, participants reported lower mental demand, stress, and effort compared to the baseline of scanning raw code suggestions. While validating tests introduces a new interaction step, the overall task completion time did not increase, as the time saved during code review compensated for the time spent on test validation.
Discussion and Future Work
While TICODER shows great promise, several challenges remain. The current evaluation assumes "perfect" user feedback, whereas real-world users may provide noisy or incorrect responses to edge cases. Additionally, the computational cost of generating large samples of code and tests for ranking is higher than one-shot methods.
Future research will explore scaling this approach to complex, multi-file software projects and incorporating richer formal specifications, such as property-based testing, to further bridge the gap between human intent and machine-generated code.
Summary updated