Back to all reviewers

validate algorithmic correctness

cline/cline
Based on 3 comments
TypeScript

Always verify algorithms work correctly across edge cases and boundary conditions through concrete examples and mathematical validation. Pay special attention to preventing infinite recursion and ensuring mathematical formulas produce expected results.

Algorithms TypeScript

Reviewer Prompt

Always verify algorithms work correctly across edge cases and boundary conditions through concrete examples and mathematical validation. Pay special attention to preventing infinite recursion and ensuring mathematical formulas produce expected results.

Key practices:

  • Test algorithms with minimal input sizes and edge cases
  • Use concrete examples to verify mathematical calculations step-by-step
  • Implement cycle detection for recursive operations that traverse potentially circular structures
  • Validate formulas by working through the math with specific values

Example from message truncation logic:

// Incorrect: Can result in zero when it shouldn't
messagesToRemove = Math.floor((messages.length - startOfRest) / 8) * 3 * 2
// With messages.length=5, startOfRest=1: floor(4/8) * 3 * 2 = 0 * 6 = 0

// Correct: Properly calculates 3/4 of remaining pairs  
messagesToRemove = Math.floor(((messages.length - startOfRest) * 3) / 4 / 2) * 2
// With messages.length=5, startOfRest=1: floor((4*3)/4/2) * 2 = floor(1.5) * 2 = 2

For recursive operations, implement safeguards:

// Prevent infinite recursion with cycle detection
const visitedPaths = new Set<string>()
if (visitedPaths.has(resolvedPath)) {
    continue // Skip already processed paths
}
visitedPaths.add(resolvedPath)
3
Comments Analyzed
TypeScript
Primary Language
Algorithms
Category

Source Discussions